Exemplo n.º 1
0
    def test_data_json_field(self):
        TestCaseDatabase.__construct_basic_db()

        elem1 = ExecutionElement(name='b', parent_name='a')
        elem2 = ExecutionElement(name='c', parent_name='b', ancestry=['a', 'b', 'c'])
        elem3 = ExecutionElement(name='d', parent_name='c')
        elem4 = ExecutionElement()

        event4_data = {"a": 4, "b": [1, 2, 3], "c": "Some_String"}
        event1 = _EventEntry(elem1, 'SYSTEM', 'message1')
        event2 = _EventEntry(elem2, 'WORKFLOW', 'message2', data='some_string')
        event3 = _EventEntry(elem3, 'STEP', 'message3', data=6)
        event4 = _EventEntry(elem4, 'NEXT', 'message4', data=json.dumps(event4_data))

        case_database.case_db.add_event(event=event1, cases=['case1', 'case3'])
        case_database.case_db.add_event(event=event2, cases=['case2', 'case4'])
        case_database.case_db.add_event(event=event3, cases=['case2', 'case3', 'case4'])
        case_database.case_db.add_event(event=event4, cases=['case1'])

        events = case_database.case_db.session.query(case_database.Event).all()
        event_json_list = [event.as_json() for event in events]

        input_output = {'message1': None,
                        'message2': 'some_string',
                        'message3': 6,
                        'message4': json.dumps(event4_data)}

        self.assertEqual(len(event_json_list), len(list(input_output.keys())))
        for event in event_json_list:
            self.assertIn(event['message'], input_output)
            self.assertEqual(event['data'], input_output[event['message']])
Exemplo n.º 2
0
    def test_edit_note(self):
        TestCaseDatabase.__construct_basic_db()

        elem1 = ExecutionElement(name='b', parent_name='a')
        elem2 = ExecutionElement(name='c',
                                 parent_name='b',
                                 ancestry=['a', 'b', 'c'])
        elem3 = ExecutionElement(name='d', parent_name='c')
        elem4 = ExecutionElement()

        event1 = _EventEntry(elem1, 'SYSTEM', 'message1')
        event2 = _EventEntry(elem2, 'WORKFLOW', 'message2')
        event3 = _EventEntry(elem3, 'STEP', 'message3')
        event4 = _EventEntry(elem4, 'NEXT', 'message4')

        case_database.case_db.add_event(event=event1, cases=['case1', 'case3'])
        case_database.case_db.add_event(event=event2, cases=['case2', 'case4'])
        case_database.case_db.add_event(event=event3,
                                        cases=['case2', 'case3', 'case4'])
        case_database.case_db.add_event(event=event4, cases=['case1'])

        events = case_database.case_db.session.query(case_database.Event).all()
        smallest_id = min([event.id for event in events])
        expected_json_list = [event.as_json() for event in events]
        for event in expected_json_list:
            if event['id'] == str(smallest_id):
                event['note'] = 'Note1'

        case_database.case_db.edit_event_note(smallest_id, 'Note1')
        events = case_database.case_db.session.query(case_database.Event).all()
        result_json_list = [event.as_json() for event in events]
        self.assertEqual(len(result_json_list), len(expected_json_list))
        self.assertTrue(
            all(expected_event in result_json_list
                for expected_event in expected_json_list))
Exemplo n.º 3
0
    def test_add_event(self):
        TestCaseDatabase.__construct_basic_db()

        elem1 = ExecutionElement(name='b', parent_name='a')
        elem2 = ExecutionElement(name='c', parent_name='b', ancestry=['a', 'b', 'c'])
        elem3 = ExecutionElement(name='d', parent_name='c')
        elem4 = ExecutionElement()

        event1 = _EventEntry(elem1, 'SYSTEM', 'message1')
        event2 = _EventEntry(elem2, 'WORKFLOW', 'message2')
        event3 = _EventEntry(elem3, 'STEP', 'message3')
        event4 = _EventEntry(elem4, 'NEXT', 'message4')

        case_database.case_db.add_event(event=event1, cases=['case1', 'case3'])
        case_database.case_db.add_event(event=event2, cases=['case2', 'case4'])
        case_database.case_db.add_event(event=event3, cases=['case2', 'case3', 'case4'])
        case_database.case_db.add_event(event=event4, cases=['case1'])

        expected_event_messages = {'case1': [('SYSTEM', 'message1'), ('NEXT', 'message4')],
                                   'case2': [('WORKFLOW', 'message2'), ('STEP', 'message3')],
                                   'case3': [('SYSTEM', 'message1'), ('STEP', 'message3')],
                                   'case4': [('WORKFLOW', 'message2'), ('STEP', 'message3')]}

        # check cases to events is as expected
        for case_name, expected_events in expected_event_messages.items():
            case = case_database.case_db.session.query(case_database.Case) \
                .filter(case_database.Case.name == case_name).all()
            self.assertEqual(len(case), 1, 'There are more than one cases sharing a name {0}'.format(case_name))

            case_event_info = [(event.type, event.message) for event in case[0].events.all()]

            self.assertEqual(len(case_event_info), len(expected_events),
                             'Unexpected number of messages encountered for case {0}'.format(case_name))
            self.assertSetEqual(set(case_event_info), set(expected_events),
                                'Expected event info does not equal received event info for case {0}'.format(case_name))