def test_data_json_field(self): TestCaseDatabase.__construct_basic_db() event4_data = {"a": 4, "b": [1, 2, 3], "c": "Some_String"} event1 = case_database.Event(type='SYSTEM', message='message1') case_database.case_db.add_event(event=event1, cases=['case1', 'case3']) event2 = case_database.Event(type='WORKFLOW', message='message2', data='some_string') case_database.case_db.add_event(event=event2, cases=['case2', 'case4']) event3 = case_database.Event(type='ACTION', message='message3', data=6) case_database.case_db.add_event(event=event3, cases=['case2', 'case3', 'case4']) event4 = case_database.Event(type='BRANCH', message='message4', data=json.dumps(event4_data)) 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': '', 'message2': 'some_string', 'message3': 6, 'message4': 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']])
def test_edit_note_invalid_id(self): TestCaseDatabase.__construct_basic_db() event1 = case_database.Event(type='SYSTEM', message='message1') case_database.case_db.add_event(event=event1, cases=['case1', 'case3']) event2 = case_database.Event(type='WORKFLOW', message='message2') case_database.case_db.add_event(event=event2, cases=['case2', 'case4']) event3 = case_database.Event(type='ACTION', message='message3') case_database.case_db.add_event(event=event3, cases=['case2', 'case3', 'case4']) event4 = case_database.Event(type='BRANCH', message='message4') case_database.case_db.add_event(event=event4, cases=['case1']) events = case_database.case_db.session.query(case_database.Event).all() expected_json_list = [event.as_json() for event in events] case_database.case_db.edit_event_note(None, '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)) invalid_id = max([event.id for event in events]) + 1 case_database.case_db.edit_event_note(invalid_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))
def test_edit_note(self): TestCaseDatabase.__construct_basic_db() event1 = case_database.Event(type='SYSTEM', message='message1') case_database.case_db.add_event(event=event1, cases=['case1', 'case3']) event2 = case_database.Event(type='WORKFLOW', message='message2') case_database.case_db.add_event(event=event2, cases=['case2', 'case4']) event3 = case_database.Event(type='STEP', message='message3') case_database.case_db.add_event(event=event3, cases=['case2', 'case3', 'case4']) event4 = case_database.Event(type='NEXT', message='message4') 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'] == 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))
def test_add_event(self): TestCaseDatabase.__construct_basic_db() event1 = case_database.Event(type='SYSTEM', message='message1') case_database.case_db.add_event(event=event1, cases=['case1', 'case3']) event2 = case_database.Event(type='WORKFLOW', message='message2') case_database.case_db.add_event(event=event2, cases=['case2', 'case4']) event3 = case_database.Event(type='ACTION', message='message3') case_database.case_db.add_event(event=event3, cases=['case2', 'case3', 'case4']) event4 = case_database.Event(type='BRANCH', message='message4') case_database.case_db.add_event(event=event4, cases=['case1']) expected_event_messages = { 'case1': [('SYSTEM', 'message1'), ('BRANCH', 'message4')], 'case2': [('WORKFLOW', 'message2'), ('ACTION', 'message3')], 'case3': [('SYSTEM', 'message1'), ('ACTION', 'message3')], 'case4': [('WORKFLOW', 'message2'), ('ACTION', '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))