Commit 25546930 authored by Manuel's avatar Manuel

extended unittest and fixed UniqueID issue

bugifx: an exception was thrown when an int is passed as a UniqueID field -> now converted to string
parent b4d3f717
...@@ -90,6 +90,10 @@ class MessageHandler: ...@@ -90,6 +90,10 @@ class MessageHandler:
transaction - Required: dictionary, that is arbitrarily deep nested transaction - Required: dictionary, that is arbitrarily deep nested
mappings - Required: contains string->path mappings, describing how the flattened object is built mappings - Required: contains string->path mappings, describing how the flattened object is built
''' '''
print("TRANSACTION: "+str(transaction))
print("MAPPINGS: "+str(mappings))
flattened = {} flattened = {}
# iterate over schema mappings and resolve paths # iterate over schema mappings and resolve paths
...@@ -111,7 +115,7 @@ class MessageHandler: ...@@ -111,7 +115,7 @@ class MessageHandler:
flattened[mapping] = final_value flattened[mapping] = final_value
flattened["UniqueID"] = hashlib.sha256(flattened["UniqueID"].encode("utf-8")).hexdigest() flattened["UniqueID"] = hashlib.sha256(str(flattened["UniqueID"]).encode("utf-8")).hexdigest()
return flattened return flattened
......
...@@ -48,6 +48,22 @@ class Test_MessageHandler(unittest.TestCase): ...@@ -48,6 +48,22 @@ class Test_MessageHandler(unittest.TestCase):
} }
return json.dumps(message_values) return json.dumps(message_values)
def _get_order_message(self) -> str:
message_values = \
{
'type': 'blockchain-transaction',
'content':
{
"ApplicationType": "debug",
"docType": "order",
"orderId": 1,
"pizza": 1,
"price": 12.0,
"restaurant": 1,
}
}
return json.dumps(message_values)
def _get_pizza_message(self) -> str: def _get_pizza_message(self) -> str:
message_values = \ message_values = \
{ {
...@@ -56,21 +72,27 @@ class Test_MessageHandler(unittest.TestCase): ...@@ -56,21 +72,27 @@ class Test_MessageHandler(unittest.TestCase):
{ {
"ApplicationType": "debug", "ApplicationType": "debug",
"docType": "pizza", "docType": "pizza",
"name": "Margherita", "id": 1,
"name": "Diavolo",
"dough": { "dough": {
"type": "wheat", "type": "wheat",
"cheese": False, "spinach": False
}, },
"sauces": [ "toppings": [
{ {
"name": "tomato", "name": "cheese",
"sugarcontent": 0.0, "price": 0.50,
}, },
{ {
"name": "caramel", "name": "peppers",
"sugarcontent": 1.0, "price": 1.00,
},
{
"name": "chilli-oil",
"price": 0.1,
} }
] ],
} }
} }
return json.dumps(message_values) return json.dumps(message_values)
......
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