Example #1
0
class TestDay:
    @pytest.mark.parametrize('when,weekday,holiday,hours', [
        (date(2015, 3, 15), 'Sunday', None, [Hour(time(12), time(17))]),
        (datetime(2015, 3, 15), 'Sunday', None, [Hour(time(12), time(17))]),
        (datetime(2015, 3,
                  18), 'Wednesday', None, [Hour(time(9, 10), time(18))]),
        (datetime(2015, 3, 14), 'Saturday', 'Pi Day', []),
        (date(2015, 3,
              22), 'Sunday', 'Random 3 Days', [Hour(time(1), time(2))]),
        (None, 'Saturday', None, [Hour(time(11), time(18))]),
    ])
    def test_creation(self, mock_hours, mock_today, when, weekday, holiday,
                      hours):
        day_hours = Day.from_date(when)
        if when:
            if isinstance(when, datetime):
                day = when.date()
            else:
                day = when
        else:
            day = date.today()

        assert day_hours.date == day
        assert day_hours.weekday == weekday
        assert day_hours.hours == hours
        assert day_hours.holiday == holiday
Example #2
0
def test_generate_regular_hours(mock_hours_response):
    hours = _generate_regular_hours()

    # hours[0] because FAKE_WEB_HOURS mocks Monday at index 0
    assert hours[0][0] == Hour(open=time(9, 30),
                               close=time(14, 00),
                               staffer='test1')
    assert hours[0][1] == Hour(open=time(15, 00),
                               close=time(15, 30),
                               staffer='test2')
Example #3
0
@pytest.fixture
def mock_hours_yaml(fs):
    fs.create_file('/etc/ocf/hours.yaml', contents=FAKE_HOURS_YAML)


@pytest.fixture
def mock_now():
    with freeze_time(FAKE_NOW):
        yield


@pytest.mark.parametrize(
    'now,expected_hours',
    [
        # regular hours
        (date(2015, 3, 13), [Hour(open=time(9), close=time(18))]),
        (None, [Hour(open=time(11), close=time(18))]),

        # holidays
        (date(2015, 3, 14), []),
        (date(2015, 3, 19), [
            Hour(open=time(9), close=time(12)),
            Hour(open=time(14), close=time(18)),
        ]),
        (date(2015, 3, 20), [Hour(open=time(1), close=time(2))]),
        (date(2015, 3, 21), [Hour(open=time(1), close=time(2))]),
        (date(2015, 3, 22), [Hour(open=time(1), close=time(2))]),
        (date(2015, 3, 23), [Hour(open=time(9), close=time(18))]),
    ])
def test_hours_on_date(now, expected_hours, mock_hours_yaml, mock_now):
    assert read_hours_listing().hours_on_date(now) == expected_hours
Example #4
0
from datetime import date
from datetime import datetime
from datetime import time

import mock
import pytest
from freezegun import freeze_time

from ocflib.lab.hours import Day
from ocflib.lab.hours import Hour
from ocflib.lab.hours import REGULAR_HOURS

FAKE_HOLIDAYS = [
    (date(2015, 3, 14), date(2015, 3, 14), 'Pi Day', []),
    (date(2015, 3, 20), date(2015, 3,
                             22), 'Random 3 Days', [Hour(time(1), time(2))]),
]
FAKE_REGULAR_HOURS = {
    Day.MONDAY: [Hour(time(9), time(18))],
    Day.TUESDAY: [Hour(time(9), time(18))],
    Day.WEDNESDAY: [Hour(time(9, 10), time(18))],
    Day.THURSDAY: [Hour(time(9), time(18))],
    Day.FRIDAY: [Hour(time(9), time(18))],
    Day.SATURDAY: [Hour(time(11), time(18))],
    Day.SUNDAY: [Hour(time(12), time(17))],
}


@pytest.yield_fixture
def mock_hours():
    with mock.patch('ocflib.lab.hours.HOLIDAYS', FAKE_HOLIDAYS), \