def test_with_existing_connection(self): # arrange agent = FactsService() agent.configure(agent._default_config) agent.historian_setup() # act agent.historian_teardown() # assert assert agent._db_connection is None assert agent._db_is_alive is False
def test_valid_setup(self, caplog): # arrange agent = FactsService() agent.configure(agent._default_config) caplog.clear() # act agent.historian_setup() # assert assert isinstance(agent._db_connection, sqlite3.Connection) assert agent._db_is_alive is True assert caplog.record_tuples == [ ('facts_service.agent', logging.INFO, 'Setting up unmapped topics database connection') ]
def test_error_during_setup(self, caplog): # arrange agent = FactsService() agent.configure(agent._default_config) caplog.clear() mock_db = mock.patch('facts_service.agent.sqlite3.connect', side_effect=sqlite3.DatabaseError) mock_db.start() # act agent.historian_setup() # assert mock_db.stop() assert caplog.record_tuples == [ ('facts_service.agent', logging.INFO, 'Setting up unmapped topics database connection'), ('facts_service.agent', logging.ERROR, 'Failed to create database connection: DatabaseError()') ]