Skip to content
Snippets Groups Projects
Commit 35c06624 authored by Mohamed Anis Koubaa's avatar Mohamed Anis Koubaa :v_tone2:
Browse files

database_connectivity_tests

parent 997a156f
Branches 2-write-tests
No related tags found
1 merge request!8Draft: Resolve "Write tests" - "Connection to MongoDB"
Pipeline #249308 failed
......@@ -3,18 +3,18 @@ print("In module database_test __package__ : ", __package__)
from .database import connection
def test_connection():
def test_authentication():
assert True
#Do some initialisations
result = ""
log = None
error_occured = False
#Test core
#Test core #tbd
result = connection()
print(result)
#Assert, implement test plan
#Assert, implement test plan #tbd
# assert log != None, "Build log should not be empty"
assert error_occured == False, "Connection server, error occured"
assert len(result) > 0, "response should not be empty"
......
......@@ -13,8 +13,6 @@ def known_search(known='nix'):
database = HandleDatabase()
#Do some initialisations
#context = str(Path().absolute()) + "/../" #Assuming that Docker is one level higher
#dockerfile = "./Docker/Dockerfile_Test" #Using Dockerfile_test for building
query_output = [] #is it a list?
#Give it a try
......
......@@ -15,6 +15,7 @@ def test_schema_db_add():
#Test core
result = schema_db_add(ex_schema_path)
print("resulting records after adding schema: ")
for record in result:
print("Id: %s, title: %s, description: %s" % (record["$id"], record["title"], record["description"]))
......
......@@ -2,10 +2,11 @@ import pathlib as Path
print("In module database __package__ : ", __package__)
import json
from ...GitLabSyncer.fetchSchemaFromGitLab import SchemaFetcher
from ...Database.schemaDatabase import SchemaDatabase
from collections import defaultdict
def schema_fetch():
"""
......@@ -27,25 +28,36 @@ def schema_fetch():
finally:
return schema_repo
def schema_db_add(path_schema):
def schema_db_add(ex_schema_path):
"""
add schema to data-base
"""
#Instantiate a schema database
sdb = SchemaDatabase()
response = {}
response['before'] = sdb.getAllSchema()
#Do some initialisations
with open(path_schema) as file:
exSchema = json.load(file)
with open(ex_schema_path) as file:
ex_schema = json.load(file)
response['schema_added'] = ex_schema
id_dict = defaultdict(list)
for item in response['before']:
id_dict[item['$id']].append(item)
print("ex_schema is: ", ex_schema)
print("id dict for $id is: ", id_dict[ex_schema['$id']])
#Give it a try
try:
sdb.addSchema(exSchema)
response = sdb.getAllSchema()
sdb.addSchema(ex_schema)
response['after'] = sdb.getAllSchema()
except:
print("adding schema to schema db: error occured.")
finally:
return response
if __name__ == '__main__':
schema_fetch()
\ No newline at end of file
schema_fetch()
schema_db_add('metadata_standard.json')
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment