Example #1
0
    def test_get_message_time_invalid_date_string(self):
        start_date = '${PH01}'
        start_time = '${PH02}'
        schedule = '-2h'
        placeholders = {'PH01': 'Invalid date string', 'PH02': '4:30pm'}

        m = Message(content='',
                    schedule=schedule,
                    start_date=start_date,
                    start_time=start_time,
                    title='')
        m.set_placeholders(placeholders=placeholders)

        # Verify ValueError exception is raised when input date string is invalid.
        with pytest.raises(ValueError):
            m.get_message_time()
Example #2
0
    def test_get_message_time_missing_schedule(self):
        start_date = '${PH01}'
        start_time = '${PH02}'
        schedule = ''
        placeholders = {'PH01': '07-25-2020', 'PH02': '4:30pm'}

        m = Message(content='',
                    schedule=schedule,
                    start_date=start_date,
                    start_time=start_time,
                    title='')
        m.set_placeholders(placeholders=placeholders)

        # Verify that message_time is essentially now.
        expected = datetime.now(tz=tz.gettz('America/Los_Angeles'))
        assert (m.get_message_time() - expected).microseconds < 1000
Example #3
0
    def test_get_message_time_relative_time_days(self):
        start_date = '${PH01}'
        start_time = '${PH02}'
        schedule = '-1d'
        placeholders = {'PH01': '07-25-2020', 'PH02': '4:30pm'}

        m = Message(content='',
                    schedule=schedule,
                    start_date=start_date,
                    start_time=start_time,
                    title='')
        m.set_placeholders(placeholders=placeholders)

        # Expected time is one day before start_time, because of the relative offset from schedule
        temp = get_expected_date(placeholders['PH01'])
        expected = datetime(year=temp.year,
                            month=temp.month,
                            day=temp.day - 1,
                            hour=16,
                            minute=30,
                            tzinfo=tz.gettz('America/Los_Angeles'))

        assert m.get_message_time() == expected
Example #4
0
    def test_get_message_time(self, start_date_str):
        start_date = '${PH01}'
        start_time = '${PH02}'
        schedule = '-2h'
        placeholders = {'PH01': start_date_str, 'PH02': '1pm'}

        m = Message(content='',
                    schedule=schedule,
                    start_date=start_date,
                    start_time=start_time,
                    title='')
        m.set_placeholders(placeholders=placeholders)

        # Expected time is two hours before start_time, because of the relative offset from schedule
        temp = get_expected_date(placeholders['PH01'])
        expected = datetime(year=temp.year,
                            month=temp.month,
                            day=temp.day,
                            hour=11,
                            minute=0,
                            tzinfo=tz.gettz('America/Los_Angeles'))

        assert m.get_message_time() == expected