| 2 | |
| 3 | |
| 4 | class TestcaseManager: |
| 5 | def __init__(self, database_env): |
| 6 | self.database_env = database_env |
| 7 | |
| 8 | def insert_execution_data(self, execution_query_payload): |
| 9 | """Inserts a test execution row into the database. |
| 10 | Returns the execution guid. |
| 11 | "execution_start_time" is defined by milliseconds since the Epoch. |
| 12 | (See https://currentmillis.com to convert that to a real date.)""" |
| 13 | |
| 14 | query = """INSERT INTO test_execution |
| 15 | (guid, execution_start, total_execution_time, username) |
| 16 | VALUES (%(guid)s,%(execution_start_time)s, |
| 17 | %(total_execution_time)s,%(username)s)""" |
| 18 | DatabaseManager(self.database_env).execute_query( |
| 19 | query, execution_query_payload.get_params() |
| 20 | ) |
| 21 | return execution_query_payload.guid |
| 22 | |
| 23 | def update_execution_data(self, execution_guid, execution_time): |
| 24 | """Updates an existing test execution row in the database.""" |
| 25 | query = """UPDATE test_execution |
| 26 | SET total_execution_time=%(execution_time)s |
| 27 | WHERE guid=%(execution_guid)s """ |
| 28 | DatabaseManager(self.database_env).execute_query( |
| 29 | query, |
| 30 | { |
| 31 | "execution_guid": execution_guid, |
| 32 | "execution_time": execution_time, |
| 33 | }, |
| 34 | ) |
| 35 | |
| 36 | def insert_testcase_data(self, testcase_run_payload): |
| 37 | """Inserts all data for the test in the DB. Returns new row guid.""" |
| 38 | query = """INSERT INTO test_run_data( |
| 39 | guid, browser, state, execution_guid, env, start_time, |
| 40 | test_address, runtime, retry_count, message, stack_trace) |
| 41 | VALUES ( |
| 42 | %(guid)s, |
| 43 | %(browser)s, |
| 44 | %(state)s, |
| 45 | %(execution_guid)s, |
| 46 | %(env)s, |
| 47 | %(start_time)s, |
| 48 | %(test_address)s, |
| 49 | %(runtime)s, |
| 50 | %(retry_count)s, |
| 51 | %(message)s, |
| 52 | %(stack_trace)s) """ |
| 53 | DatabaseManager(self.database_env).execute_query( |
| 54 | query, testcase_run_payload.get_params() |
| 55 | ) |
| 56 | |
| 57 | def update_testcase_data(self, testcase_payload): |
| 58 | """Updates an existing test run in the database.""" |
| 59 | query = """UPDATE test_run_data SET |
| 60 | runtime=%(runtime)s, |
| 61 | state=%(state)s, |