Commit 28641988 authored by Alexander Lercher's avatar Alexander Lercher

Changed communication from API Gateway

API Gateway -> trace retrievel for every trace containing ApplicationType information
parent 1f7eeae6
...@@ -16,15 +16,5 @@ def receive(): ...@@ -16,15 +16,5 @@ def receive():
return Response(status=400) return Response(status=400)
def isBlockchainTraceValid(trace) -> bool: def isBlockchainTraceValid(trace) -> bool:
return 'TransactionId' in trace \ # different for every use case, no global schema
and 'Timestamp' in trace \ return 'ApplicationType' in trace
and 'ApplicationType' in trace \
and 'TransactionFrom' in trace \
and 'TransactionFromLatLng' in trace \
and 'TransactionTo' in trace \
and 'TransactionToLatLng' in trace \
and 'TransferredAsset' in trace \
and 'ResourceIds' in trace \
and 'ResourceMd5' in trace \
and 'ResourceState' in trace \
and 'Metadata' in trace
...@@ -9,41 +9,20 @@ import routes.blockchain_trace as blockchain_trace ...@@ -9,41 +9,20 @@ import routes.blockchain_trace as blockchain_trace
class Test_BlockchainTrace(unittest.TestCase): class Test_BlockchainTrace(unittest.TestCase):
def _get_valid_input(self): def _get_min_valid_input(self):
return { return {
"ApplicationType": "string", "ApplicationType": "string"
"Metadata": {},
"ResourceIds": "string",
"ResourceMd5": "string",
"ResourceState": "string",
"Timestamp": "2019-08-27T14:00:48.587Z",
"TransactionFrom": "string",
"TransactionFromLatLng": "string",
"TransactionId": "string",
"TransactionTo": "string",
"TransactionToLatLng": "string",
"TransferredAsset": "string"
} }
def test_isBlockchainTraceValid_validInputAndTypes(self): def test_isBlockchainTraceValid_validInputAndTypes(self):
input = self._get_valid_input() input = self._get_min_valid_input()
self.assertTrue(blockchain_trace.isBlockchainTraceValid(input), "Trace should be valid") self.assertTrue(blockchain_trace.isBlockchainTraceValid(input), "Trace should be valid")
# def test_isBlockchainTraceValid_invalidMetadataInputType(self):
# input = self._get_valid_input()
# input["Metadata"] = "string"
# self.assertFalse(blockchain_trace.isBlockchainTraceValid(input), "Metadata type should be invalid")
# def test_isBlockchainTraceValid_invalidTransactionFromLatLngInputType(self):
# input = self._get_valid_input()
# input["TransactionFromLatLng"] = ["55.1", "44.1"]
# self.assertFalse(blockchain_trace.isBlockchainTraceValid(input), "TransactionFromLatLng type should be invalid")
def test_isBlockchainTraceValid_emptyInput(self): def test_isBlockchainTraceValid_emptyInput(self):
input = {} input = {}
self.assertFalse(blockchain_trace.isBlockchainTraceValid(input), "Empty input should not be accepted") self.assertFalse(blockchain_trace.isBlockchainTraceValid(input), "Empty input should not be accepted")
def test_isBlockchainTraceValid_missingKeys(self): def test_isBlockchainTraceValid_additionalKeys(self):
input = { input = {
"ApplicationType": "string", "ApplicationType": "string",
"Metadata": {}, "Metadata": {},
...@@ -57,7 +36,7 @@ class Test_BlockchainTrace(unittest.TestCase): ...@@ -57,7 +36,7 @@ class Test_BlockchainTrace(unittest.TestCase):
"TransactionToLatLng": "string", "TransactionToLatLng": "string",
"TransferredAsset": "string" "TransferredAsset": "string"
} }
self.assertFalse(blockchain_trace.isBlockchainTraceValid(input), "Input should not be accepted because timestamp is missing") self.assertTrue(blockchain_trace.isBlockchainTraceValid(input), "Input should be accepted")
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