import unittest
import manage_sys_paths
import json

from messaging.MessageHandler import MessageHandler

class DummyMongoRepo:
    '''Dummy class to be used for testing the MessageHandler'''
    last_trace = None
    def insert_trace(self, trace):
        self.last_trace = trace

from messaging.DummyMessageManager import DummyMessageManager as DummyMessageSender

class Test_MessageHandler(unittest.TestCase):
    handler = None
    repo = None
    msg_sender = None

    def setUp(self):
        self.repo = DummyMongoRepo()
        self.msg_sender = DummyMessageSender.get_instance()
        self.handler = MessageHandler(self.repo, self.msg_sender)

    def _get_valid_message(self) -> str:
        message_values = \
        { 
          'type': 'blockchain-transaction',
          'content': 
            {
            "ApplicationType": "smart-energy",
            "Customer": 13,
            "Postcode": 2261,
            "Timestamp": "01.07.2012 00:30",
            "Solar_Production_kWh": 0.0,
            "Energy_Consumption_kWh": 0.23399999999999999,
            "Heating_Consumption_kWh": 0.23399999999999999,
            "Price_AUD/MWh": 57.04,
            "Total_Demand_MWh": 8097.93,
            "Latitude": -33.362679,
            "Longitude": 151.447302,
            }
        }
        return json.dumps(message_values)

    def _get_pizza_message(self) -> str:
        message_values = \
        { 
          'type': 'blockchain-transaction',
          'content': 
            {
            "ApplicationType": "debug",
            "name": "Margherita",
            "dough": {
                "type": "wheat",
                "cheese": False,
            },
            "sauces": [
                {
                    "name": "tomato"
                },
                {
                    "name": "caramel"
                }
            ]
            }
        }
        return json.dumps(message_values)


    # def test_handleGeneric_correctTraceContent_NotificationSentCorrectly(self):
    #     msg = self._get_valid_message()
    #     _ = self.handler.handle_blockchain_transaction(msg)
    
    def test_HandlePizzaMessage(self):
        print("STARTING THE TEST...")

        msg = self._get_pizza_message()
        _ = self.handler.handle_blockchain_transaction(msg)

if __name__ == '__main__':
    unittest.main()