Commit 4e2e062c authored by Bogdan's avatar Bogdan

Semantic Linking unit test update

parent 978d11f9
...@@ -96,7 +96,7 @@ class MessageHandler: ...@@ -96,7 +96,7 @@ class MessageHandler:
node["table"] = layer.table node["table"] = layer.table
node["use_case"] = layer.use_case node["use_case"] = layer.use_case
nodes.append(node) nodes.append(node)
unique_id_list.append(node["UniqueId"]) unique_id_list.append(node["UniqueID"])
#check for duplicates #check for duplicates
#TODO EDIT NODES_IN_DB RETURN #TODO EDIT NODES_IN_DB RETURN
...@@ -104,7 +104,7 @@ class MessageHandler: ...@@ -104,7 +104,7 @@ class MessageHandler:
# if len(nodes_in_db) > 0: #found duplicates # if len(nodes_in_db) > 0: #found duplicates
# #remove duplicates from nodes: # #remove duplicates from nodes:
# for node in nodes: # for node in nodes:
# if node["UniqueId"] in nodes_in_db: # if node["UniqueID"] in nodes_in_db:
# nodes.remove(node) # nodes.remove(node)
#no duplicates anymore #no duplicates anymore
......
...@@ -8,9 +8,76 @@ from messaging.DummyMessageManager import DummyMessageManager as DummyMessageSen ...@@ -8,9 +8,76 @@ from messaging.DummyMessageManager import DummyMessageManager as DummyMessageSen
class DummyMongoRepo: class DummyMongoRepo:
'''Dummy class to be used for testing the MessageHandler''' '''Dummy class to be used for testing the MessageHandler'''
last_trace = None last_trace = None
DBnodes = []
def insert_trace(self, trace): def insert_trace(self, trace):
self.last_trace = trace self.last_trace = trace
def get_layers_for_use_case_and_table(use_case, table):
testLayers = [
{
"layer_name": "layer1",
"properties": [
"UniqueID",
"doughType"
],
"table": "pizza",
"total_properties": [
"UniqueID",
"doughType",
"firstTopping",
"firstToppingPrice",
"hasSpinach",
"name",
"toppingInfo"
],
"use_case": "debug"
},
{
"layer_name": "layer2",
"properties": [
"firstTopping"
],
"table": "pizza",
"total_properties": [
"UniqueID",
"doughType",
"firstTopping",
"firstToppingPrice",
"hasSpinach",
"name",
"toppingInfo"
],
"use_case": "debug"
}
]
returnLayers = []
for layer in testLayers:
if (layer["use_case"] == use_case) and (layer["table"] == table):
returnLayers.append(layer)
return returnLayers
# layers = self._repository.get_layers_for_use_case_and_table(use_case, table)
## if no local layers are found, fetch information from server
# if len(layers) == 0:
# layers = self._fetch_layer_information(use_case, table)
# self._repository.delete_layer(layer)
# self._repository.add_layer(layer)
#TODO
# nodes_in_db = self._repository.get_nodes_from_ids(unique_id_list)
#TODO first
# self._repository.add_layer_nodes(nodes)
def add_layer_nodessss(nodes):
DBnodes.extend(nodes)
return
class Test_Pipeline(unittest.TestCase): class Test_Pipeline(unittest.TestCase):
handler = None handler = None
repo = None repo = None
...@@ -44,6 +111,13 @@ class Test_Pipeline(unittest.TestCase): ...@@ -44,6 +111,13 @@ class Test_Pipeline(unittest.TestCase):
msg = self._buildTraceMessage() msg = self._buildTraceMessage()
self.handler.handle_new_trace(msg["content"]) self.handler.handle_new_trace(msg["content"])
def testDuplicateTrace(self):
msg = self._buildTraceMessage()
msg2 = self._buildTraceMessage()
self.handler.handle_new_trace(msg["content"])
self.handler.handle_new_trace(msg2["content"])
self.assertEqual(len(self.repo.DBnodes),1)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment