Пример #1
0
 def test_invalid_configuration(self, caplog):
     # arrange
     facts_service_parameters = {
         "base_api_url": "https://facts.prod.ecorithm.com/api/v1",
         "username": "******",
         "password": "******",
         "unmapped_topics_database": "unmapped_topics.db"
     }
     building_parameters = {
         "building_id": None,
         "topic_building_mapping": {}
     }
     object = FactsService(facts_service_parameters, building_parameters)
     caplog.clear()
     # act
     object.configure(object._default_config)
     # assert
     assert len(caplog.records) == 1
     assert (
         'facts_service.agent', logging.WARNING,
         'Topic to building ID mapping is empty. Nothing will be published.'
         ' Check your configuration!') in caplog.record_tuples
     assert object._facts_service_base_api_url\
         == 'https://facts.prod.ecorithm.com/api/v1'
     assert object._facts_service_username == 'foo'
     assert object._facts_service_password == 'bar'
     assert object._db_path == 'unmapped_topics.db'
     assert object._building_id is None
     assert object._topic_building_mapping == dict()
Пример #2
0
 def test_ignored_topic_building_mapping(self, caplog):
     # arrange
     facts_service_parameters = {
         "base_api_url": "https://facts.prod.ecorithm.com/api/v1",
         "username": "******",
         "password": "******",
         "unmapped_topics_database": "unmapped_topics.db"
     }
     building_parameters = {
         "building_id": 42,
         "topic_building_mapping": {
             "campus/fake_device_#1/fake_point": 42,
             "campus/fake_device_#2/fake_point": 1337
         }
     }
     object = FactsService(facts_service_parameters, building_parameters)
     # act
     caplog.clear()
     object.configure(object._default_config)
     # assert
     assert len(caplog.records) == 1
     assert ('facts_service.agent', logging.WARNING,
             'Building ID is 42, topic to building_id mapping is ignored'
             ) in caplog.record_tuples
     assert object._facts_service_base_api_url\
         == 'https://facts.prod.ecorithm.com/api/v1'
     assert object._facts_service_username == 'foo'
     assert object._facts_service_password == 'bar'
     assert object._db_path == 'unmapped_topics.db'
     assert object._building_id is 42
     assert object._topic_building_mapping == dict()
Пример #3
0
 def test_no_connection(self):
     # arrange
     agent = FactsService()
     agent.configure(agent._default_config)
     # act
     agent.historian_teardown()
     # assert
     assert agent._db_connection is None
     assert agent._db_is_alive is False
Пример #4
0
 def agent_bldg(self):
     facts_service_parameters = {
         "base_api_url": "https://facts.prod.ecorithm.com/api/v1",
         "username": "******",
         "password": "******",
         "unmapped_topics_database": "unmapped_topics.db"
     }
     building_parameters = {"building_id": 42, "topic_building_mapping": {}}
     agent = FactsService(facts_service_parameters, building_parameters)
     agent.configure(agent._default_config)
     return agent
Пример #5
0
 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')
     ]
Пример #6
0
 def agent_campus_with_missing_topics(self):
     facts_service_parameters = {
         "base_api_url": "https://facts.prod.ecorithm.com/api/v1",
         "username": "******",
         "password": "******",
         "unmapped_topics_database": "unmapped_topics.db"
     }
     building_parameters = {
         "building_id": None,
         "topic_building_mapping": {
             "campus/building_A/fake_device/point_1": 42,
             "campus/building_A/fake_device/point_2": 42
         }
     }
     agent = FactsService(facts_service_parameters, building_parameters)
     agent.configure(agent._default_config)
     return agent
Пример #7
0
 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()')
     ]
Пример #8
0
 def test_facts_service_parameters_not_dict(self, caplog):
     # arrange
     facts_service_parameters = None
     building_parameters = {"building_id": 42, "topic_building_mapping": {}}
     object = FactsService(facts_service_parameters, building_parameters)
     caplog.clear()
     # act
     object.configure(object._default_config)
     # assert
     assert len(caplog.records) == 1
     assert ('facts_service.agent', logging.WARNING,
             'Supplied facts_service_parameters is not a dict, ignored'
             ) in caplog.record_tuples
     assert object._facts_service_base_api_url is None
     assert object._facts_service_username is None
     assert object._facts_service_password is None
     assert object._db_path == "unmapped_topics.db"
     assert object._building_id is 42
     assert object._topic_building_mapping == dict()
Пример #9
0
 def test_valid_configuration(self, caplog):
     # arrange
     facts_service_parameters = {
         "base_api_url": "https://facts.prod.ecorithm.com/api/v1",
         "username": "******",
         "password": "******",
         "unmapped_topics_database": "unmapped_topics.db"
     }
     building_parameters = {"building_id": 42, "topic_building_mapping": {}}
     object = FactsService(facts_service_parameters, building_parameters)
     caplog.clear()
     # act
     object.configure(object._default_config)
     # assert
     assert len(caplog.records) == 0
     assert object._facts_service_base_api_url\
         == 'https://facts.prod.ecorithm.com/api/v1'
     assert object._facts_service_username == 'foo'
     assert object._facts_service_password == 'bar'
     assert object._db_path == 'unmapped_topics.db'
     assert object._building_id is 42
     assert object._topic_building_mapping == dict()