import unittest
import manage_sys_paths

from messaging.DummyMessageManager import DummyMessageManager
# init dummy message manager so no connection to rabbitmq is established
_ = DummyMessageManager.get_instance()

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()