def test_storage_store_state_metadata(): node_storage = CrawlerNodeStorage(storage_filepath=IN_MEMORY_FILEPATH) state = create_specific_mock_state() # Store state data node_storage.store_state_metadata( state=FleetStateTracker.abridged_state_details(state)) result = node_storage.db_conn.execute( f"SELECT * FROM {CrawlerNodeStorage.STATE_DB_NAME}").fetchall() assert len(result) == 1 for row in result: verify_mock_state_matches_row(state, row) # update state new_now = state.updated.add(minutes=5) new_color = 'red' new_color_hex = '4F3D21' symbol = '%' updated_state = create_specific_mock_state(updated=new_now, color=new_color, color_hex=new_color_hex, symbol=symbol) node_storage.store_state_metadata( state=FleetStateTracker.abridged_state_details(updated_state)) # ensure same item gets updated result = node_storage.db_conn.execute( f"SELECT * FROM {CrawlerNodeStorage.STATE_DB_NAME}").fetchall() assert len(result) == 1 # state data is updated not added for row in result: verify_mock_state_matches_row(updated_state, row)
def test_storage_store_state_metadata(sqlite_connection): node_storage = CrawlerNodeStorage(storage_filepath=IN_MEMORY_FILEPATH) state = create_specific_mock_state() # Store state data node_storage.store_state_metadata(state=FleetSensor.abridged_state_details(state)) result = sqlite_connection.execute(f"SELECT * FROM {CrawlerNodeStorage.STATE_DB_NAME}").fetchall() assert len(result) == 1 for row in result: verify_mock_state_matches_row(state, row) # update state new_now = state.updated.add(minutes=5) updated_state = create_specific_mock_state(updated=new_now) node_storage.store_state_metadata(state=FleetSensor.abridged_state_details(updated_state)) # ensure same item gets updated result = sqlite_connection.execute(f"SELECT * FROM {CrawlerNodeStorage.STATE_DB_NAME}").fetchall() assert len(result) == 1 # state data is updated not added for row in result: verify_mock_state_matches_row(updated_state, row)
def test_storage_db_clear_not_metadata(): node_storage = CrawlerNodeStorage(storage_filepath=IN_MEMORY_FILEPATH) # store some data node = create_random_mock_node() node_storage.store_node_metadata(node=node) state = create_specific_mock_state() node_storage.store_state_metadata(state=state) teacher_checksum = '0x123456789' node_storage.store_current_teacher(teacher_checksum) verify_all_db_tables(node_storage.db_conn, expect_empty=False) # only clear certificates data node_storage.clear(metadata=False, certificates=True) # db tables should not have been cleared verify_all_db_tables(node_storage.db_conn, expect_empty=False)
def test_storage_db_clear_only_metadata_not_certificates(sqlite_connection): node_storage = CrawlerNodeStorage(storage_filepath=IN_MEMORY_FILEPATH) # store some data node = create_random_mock_node() node_storage.store_node_metadata(node=node) state = create_specific_mock_state() node_storage.store_state_metadata(state=FleetSensor.abridged_state_details(state)) teacher_checksum = '0x123456789' node_storage.store_current_teacher(teacher_checksum) verify_all_db_tables(sqlite_connection, expect_empty=False) # clear metadata tables node_storage.clear(metadata=True, certificates=False) # db tables should have been cleared verify_all_db_tables(sqlite_connection, expect_empty=True)
def test_storage_db_clear(): node_storage = CrawlerNodeStorage(storage_filepath=IN_MEMORY_FILEPATH) verify_all_db_tables_exist(node_storage.db_conn) # store some data node = create_random_mock_node() node_storage.store_node_metadata(node=node) state = create_specific_mock_state() node_storage.store_state_metadata( state=FleetStateTracker.abridged_state_details(state)) teacher_checksum = '0x123456789' node_storage.store_current_teacher(teacher_checksum) verify_all_db_tables(node_storage.db_conn, expect_empty=False) # clear tables node_storage.clear() # db tables should have been cleared verify_all_db_tables(node_storage.db_conn, expect_empty=True)