Commit 9ac8ef4c authored by Alexander Lercher's avatar Alexander Lercher

Rest Gateway: first tests

parent 21605a3e
# add modules folder to interpreter path
import sys
import os
modules_paths = ['../app/', '../../modules/']
for path in modules_paths:
if os.path.exists(path):
sys.path.insert(1, path)
import unittest
import manage_sys_paths
import rest.blockchain_trace as blockchain_trace
class Test_BlockchainTrace(unittest.TestCase):
def _get_valid_input(self):
return {
"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):
input = self._get_valid_input()
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):
input = {}
self.assertFalse(blockchain_trace.isBlockchainTraceValid(input), "Empty input should not be accepted")
def test_isBlockchainTraceValid_missingKeys(self):
input = {
"ApplicationType": "string",
"Metadata": {},
"ResourceIds": "string",
"ResourceMd5": "string",
"ResourceState": "string",
"TransactionFrom": "string",
"TransactionFromLatLng": "string",
"TransactionId": "string",
"TransactionTo": "string",
"TransactionToLatLng": "string",
"TransferredAsset": "string"
}
self.assertFalse(blockchain_trace.isBlockchainTraceValid(input), "Input should not be accepted because timestamp is missing")
if __name__ == '__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