Skip to content
Snippets Groups Projects
Select Git revision
  • 31db5ab4c0ff8e0a4fb7d8f16bc9484699c9c1e2
  • master default
  • v5.2.2
  • v5.2.1
  • v5.2.0
  • v5.1.2
  • v5.1.1
  • v5.1.0
  • 5.0.2
9 results

PieChartGenerator$1.class

Blame
    • Robert Goldmann's avatar
      31db5ab4
      v.5.0.3 - (29) · 31db5ab4
      Robert Goldmann authored
      -Fixed issue where user have to press enter button in projectWindow (otherwise dropDown values would have been null)
      31db5ab4
      History
      v.5.0.3 - (29)
      Robert Goldmann authored
      -Fixed issue where user have to press enter button in projectWindow (otherwise dropDown values would have been null)
    TestGarbageContainerScheduleTile.py 4.42 KiB
    from datetime import datetime
    from unittest import mock
    
    from logic import Helpers
    from logic.tile.tiles.GarbageContainerScheduleTile import GarbageContainerScheduleTile
    
    
    def example_settings(enableNotifications):
        return {
            "path": None,
            "garbageType": "Papier" or "Gelbe Säcke" or "Bioabfall" or "Restabfall",
            "notificationViaPushbullet": {
                "enable": enableNotifications,
                "daysBeforeEvent": 1,
                "hour": 10,
                "pushbulletToken": "myToken"
            }
        }
    
    
    class TestIsAlreadyNotified:
        def test_not_notified_should_return_false(self):
            tile = GarbageContainerScheduleTile('myGarbageScheduleTile', example_settings(False), 10)
            assert tile._is_already_notified(datetime.now()) is False
    
        def test_already_notified_but_not_today_should_return_false(self):
            tile = GarbageContainerScheduleTile('myGarbageScheduleTile', example_settings(False), 10)
    
            tile.__lastNotificationDate = datetime(year=2021, month=3, day=18).date()
            currentDateTime = datetime(year=2021, month=3, day=21, hour=11, minute=35, second=0)
    
            assert tile._is_already_notified(currentDateTime) is False
    
        def test_already_notified_should_return_true(self):
            tile = GarbageContainerScheduleTile('myGarbageScheduleTile', example_settings(False), 10)
    
            tile._lastNotificationDate = datetime(year=2021, month=3, day=21).date()
            currentDateTime = datetime(year=2021, month=3, day=21, hour=11, minute=35, second=0)
    
            assert tile._is_already_notified(currentDateTime) is True
    
    
    class TestSendNotification:
        @mock.patch('logic.tile.tiles.GarbageContainerScheduleTile.Helpers')
        def test_notification_disabled_should_do_nothing(self, helpersMock):
            tile = GarbageContainerScheduleTile('myGarbageScheduleTile', example_settings(False), 10)
    
            tile._send_notification(1, '')
            helpersMock.send_notification_via_pushbullet.assert_not_called()
    
        @mock.patch('logic.tile.tiles.GarbageContainerScheduleTile.Helpers')
        def test_notification_enabled_reaming_days_greater_than_settings_should_do_nothing(self, helpersMock):
            tile = GarbageContainerScheduleTile('myGarbageScheduleTile', example_settings(True), 10)
    
            tile._send_notification(3, '')
            helpersMock.send_notification_via_pushbullet.assert_not_called()
    
        @mock.patch('logic.Helpers.requests')
        def test_send_notification_after_settings_hour_should_call_pushbullet_api(self, requestsMock):
            tile = GarbageContainerScheduleTile('myGarbageScheduleTile', example_settings(True), 10)
    
            requestsMock.post.return_value.status_code = 200
            with mock.patch.object(tile, '_get_current_date_time', wraps=tile._get_current_date_time) as currentDateTimeMock:
                currentDateTimeMock.return_value = datetime(year=2021, month=3, day=21, hour=11, minute=35, second=0)
                tile._send_notification(1, '')
    
            requestsMock.post.assert_called_once_with(Helpers.PUSHBULLET_PUSH_URL, data=mock.ANY, headers=mock.ANY)
    
        @mock.patch('logic.tile.tiles.GarbageContainerScheduleTile.Helpers')
        def test_send_notification_before_settings_hour_should_do_nothing(self, helpersMock):
            tile = GarbageContainerScheduleTile('myGarbageScheduleTile', example_settings(True), 10)
    
            with mock.patch.object(tile, '_get_current_date_time', wraps=tile._get_current_date_time) as currentDateTimeMock:
                currentDateTimeMock.return_value = datetime(year=2021, month=3, day=21, hour=9, minute=35, second=0)
                tile._send_notification(1, '')
    
            helpersMock.send_notification_via_pushbullet.assert_not_called()
    
        @mock.patch('logic.Helpers.requests')
        def test_already_notified_should_skip_sending(self, requestsMock):
            tile = GarbageContainerScheduleTile('myGarbageScheduleTile', example_settings(True), 10)
    
            requestsMock.post.return_value.status_code = 200
            tile._send_notification(1, '')
            tile._send_notification(1, '')
    
            requestsMock.post.assert_called_once()
    
        @mock.patch('logic.Helpers.requests')
        def test_already_notified_should_skip_sending_even_if_already_skipped_before(self, requestsMock):
            tile = GarbageContainerScheduleTile('myGarbageScheduleTile', example_settings(True), 10)
    
            requestsMock.post.return_value.status_code = 200
            tile._send_notification(1, '')
            tile._send_notification(1, '')
            tile._send_notification(1, '')
    
            requestsMock.post.assert_called_once()