Ejemplo n.º 1
0
 def test_process_event(self, init_rpc):
     dct = {
         'type': 'ProductCreated',
         'timestamp': 123,
         'id': 1,
         'parent_id': None,
         'stock': 10,
     }
     input_event = JsonInputEvent.from_dict(dct)
     process_event(input_event)
Ejemplo n.º 2
0
 def test_process_event_incorrect_timestamp(self, init_rpc):
     dct = {
         'type': 'ProductCreated',
         'timestamp': -1,
         'id': 1,
         'parent_id': None,
         'stock': 10,
     }
     input_event = JsonInputEvent.from_dict(dct)
     with pytest.raises(Exception):
         process_event(input_event)
Ejemplo n.º 3
0
 def test_process_event_incorrect_method(self, init_rpc):
     dct = {
         'type': 'UnknownMethod',
         'timestamp': 123,
         'id': 1,
         'parent_id': None,
         'stock': 10,
     }
     input_event = JsonInputEvent.from_dict(dct)
     with pytest.raises(Exception):
         process_event(input_event)
Ejemplo n.º 4
0
    def process_message(self, message):
        logger.info('Received event: {}'.format(message))

        try:
            event = JsonInputEvent.from_json(message)
        except Exception as exc:
            logger.error(traceback.format_exc())
            return

        try:
            process_event(event)
        except Exception as exc:
            logger.error(traceback.format_exc())
Ejemplo n.º 5
0
 def test_from_json_incorrect_event(self, input_event_json):
     incorrect_json_message = input_event_json.replace('\"', '\'')
     with pytest.raises(Exception):
         JsonInputEvent.from_json(incorrect_json_message)
Ejemplo n.º 6
0
 def test_from_json_correct_event(self, input_event_dct, input_event_json):
     inst = JsonInputEvent.from_json(input_event_json)
     assert inst.method == input_event_dct['type']
     assert inst.timestamp == input_event_dct['timestamp']
     assert isinstance(inst.params, dict)
Ejemplo n.º 7
0
 def test_from_dict_incorrect_event_structure(self, input_event_dct):
     del input_event_dct['timestamp']
     with pytest.raises(Exception):
         JsonInputEvent.from_dict(input_event_dct)