예제 #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 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
예제 #4
0
 def test_with_args(self):
     # arrange
     facts_service_parameters = {
         "base_api_url": "https://facts.prod.ecorithm.com/api/v1",
         "username": "",
         "password": "",
         "unmapped_topics_database": "trends.db"
     }
     building_parameters = {
         "building_id": None,
         "topic_building_mapping": {}
     }
     kwargs = {"submit_size_limit": 500}
     # act
     object = FactsService(facts_service_parameters, building_parameters,
                           **kwargs)
     # assert
     assert hasattr(object, '_facts_service_base_api_url')
     assert hasattr(object, '_facts_service_username')
     assert hasattr(object, '_facts_service_password')
     assert hasattr(object, '_building_id')
     assert hasattr(object, '_topic_building_mapping')
     assert hasattr(object, '_db_path')
     assert hasattr(object, '_db_connection')
     assert hasattr(object, '_db_is_alive')
     assert object._default_config.get('facts_service_parameters')\
         == facts_service_parameters
     assert object._default_config.get('building_parameters')\
         == building_parameters
     assert object._default_config.get('submit_size_limit') == 500
     assert object._process_loop_in_greenlet is False
예제 #5
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
예제 #6
0
 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
예제 #7
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()
예제 #8
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()
예제 #9
0
 def test_with_defaults(self):
     # arrange
     # act
     object = FactsService()
     # assert
     assert hasattr(object, '_facts_service_base_api_url')
     assert hasattr(object, '_facts_service_username')
     assert hasattr(object, '_facts_service_password')
     assert hasattr(object, '_building_id')
     assert hasattr(object, '_topic_building_mapping')
     assert hasattr(object, '_db_path')
     assert hasattr(object, '_db_connection')
     assert hasattr(object, '_db_is_alive')
     assert object._default_config.get('facts_service_parameters') == dict()
     assert object._default_config.get('building_parameters') == dict()
     assert object._default_config.get('submit_size_limit') == 1000
     assert object._process_loop_in_greenlet is False
예제 #10
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')
     ]
예제 #11
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()')
     ]
예제 #12
0
 def test_version(self):
     # arrange
     # act
     version = FactsService().version()
     # assert
     assert version == __version__
예제 #13
0
 def test_query_topics_by_pattern(self):
     # arrange
     agent = FactsService()
     # act
     with pytest.raises(NotImplementedError):
         agent.query_topics_by_pattern('campus/building/fake_device.*')
예제 #14
0
 def test_query_aggregate_topics(self):
     # arrange
     agent = FactsService()
     # act
     with pytest.raises(NotImplementedError):
         agent.query_aggregate_topics()
예제 #15
0
 def test_query_historian(self):
     # arrange
     agent = FactsService()
     # act
     with pytest.raises(NotImplementedError):
         agent.query_historian('campus/building/fake_device/point')
예제 #16
0
 def test_query_topic_list(self):
     # arrange
     agent = FactsService()
     # act
     with pytest.raises(NotImplementedError):
         agent.query_topic_list()
예제 #17
0
 def test_pass(self):
     # arrange
     # act
     FactsService().manage_db_size(None, None)