예제 #1
0
    def test_off_and_on(self):
        # setup
        airily_dao = AirlyDao('url', 'key', 28)
        airily_dao.caqi = MagicMock(return_value=10)
        calendar_dao = CalendarDao('url')
        air_purifier = AirPurifier(ConfigMock())
        air_purifier.turn_off = MagicMock()
        air_purifier.turn_on = MagicMock()
        air_purifier.get_state = MagicMock(return_value=AirPurifierState.ON)
        cleaning_pause = self.get_cleaning_pause(['Monday', 'Tuesday', 'Wednesday'], '8:00', '16:00')
        clean_airtomation_service = CleanAirtomationService(70, cleaning_pause, airily_dao, calendar_dao,
                                                            air_purifier)

        # test
        clean_airtomation_service.clean_polluted_air()
        air_purifier.get_state = MagicMock(return_value=AirPurifierState.OFF)
        airily_dao.caqi = MagicMock(return_value=100)
        clean_airtomation_service.clean_polluted_air()

        # verify
        air_purifier.turn_on.assert_called_once()
        air_purifier.turn_off.assert_called_once()
예제 #2
0
    def test_pause_edge_right(self):
        # setup
        airily_dao = AirlyDao('url', 'key', 28)
        airily_dao.caqi = MagicMock(return_value=10)
        calendar_dao = CalendarDao('url')
        air_purifier = AirPurifier(ConfigMock())
        air_purifier.turn_off = MagicMock()
        air_purifier.turn_on = MagicMock()
        air_purifier.get_state = MagicMock(return_value=AirPurifierState.ON)
        cleaning_pause = self.get_cleaning_pause(['Monday', 'Tuesday', 'Wednesday'], '8:00', '16:00')
        clean_airtomation_service = CleanAirtomationService(70, cleaning_pause, airily_dao, calendar_dao,
                                                            air_purifier)
        # test
        result = clean_airtomation_service._is_not_in_pause_time()

        # verify
        self.assertFalse(result)
예제 #3
0
    def test_turn_on_purifier_when_holiday(self):
        # setup
        airily_dao = AirlyDao('url', 'key', 28)
        airily_dao.caqi = MagicMock(return_value=100)
        calendar_dao = CalendarDao('url')
        calendar_dao.is_holiday = MagicMock(return_value=True)
        air_purifier = AirPurifier(ConfigMock())
        air_purifier.turn_off = MagicMock()
        air_purifier.turn_on = MagicMock()
        cleaning_pause = self.get_cleaning_pause(['Monday', 'Tuesday', 'Wednesday'], '8:00', '16:00')
        clean_airtomation_service = CleanAirtomationService(70, cleaning_pause, airily_dao, calendar_dao,
                                                            air_purifier)
        clean_airtomation_service._pause_time_not_in_holiday = MagicMock()
        # test
        clean_airtomation_service.clean_polluted_air()

        # verify
        airily_dao.caqi.assert_called_once()
        air_purifier.turn_off.assert_not_called()
        air_purifier.turn_on.assert_called_once()
        clean_airtomation_service._pause_time_not_in_holiday.assert_not_called()
예제 #4
0
 def test_request_with_timeout(self):
     airlyDao = AirlyDao('https://airapi.airly.eu', 'API_KEY', 888)
     self.assertIsNone(airlyDao.caqi())
예제 #5
0
 def test_request_with_invalid_installationId(self):
     airlyDao = AirlyDao('https://airapi.airly.eu', 'API_KEY', 666)
     self.assertIsNone(airlyDao.caqi())
예제 #6
0
 def test_request_with_proper_installationId(self):
     airlyDao = AirlyDao('https://airapi.airly.eu', 'API_KEY', 4444)
     self.assertEqual(airlyDao.caqi(), 44.44)