Exemplo n.º 1
0
def test_journeys_dst_october(set_night_times):
    # Journeys between 0100-0200 repeated as timezone changes from BST to GMT
    date = datetime.date(2019, 10, 27)
    query = _query_journeys(SERVICE, DIRECTION, date).order_by("departure")

    # Test in different time zones, all queries should return the same results
    _set_timezone("Europe/London")
    result_gb = query.all()
    _set_timezone("UTC")
    result_utc = query.all()

    expected = [
        (400012, datetime.datetime(2019, 10, 27, 0, 15, tzinfo=BST)),
        (400013, datetime.datetime(2019, 10, 27, 0, 45, tzinfo=BST)),
        (400014, datetime.datetime(2019, 10, 27, 1, 15, tzinfo=BST)),
        (400015, datetime.datetime(2019, 10, 27, 1, 45, tzinfo=BST)),
        (400014, datetime.datetime(2019, 10, 27, 1, 15, tzinfo=GMT)),
        (400015, datetime.datetime(2019, 10, 27, 1, 45, tzinfo=GMT)),
        (400016, datetime.datetime(2019, 10, 27, 2, 15, tzinfo=GMT)),
        (400017, datetime.datetime(2019, 10, 27, 2, 45, tzinfo=GMT)),
        (400018, datetime.datetime(2019, 10, 27, 3, 15, tzinfo=GMT)),
        (400019, datetime.datetime(2019, 10, 27, 3, 45, tzinfo=GMT)),
        (400020, datetime.datetime(2019, 10, 27, 4, 15, tzinfo=GMT)),
        (400021, datetime.datetime(2019, 10, 27, 4, 45, tzinfo=GMT)),
        (400022, datetime.datetime(2019, 10, 27, 5, 15, tzinfo=GMT)),
        (400023, datetime.datetime(2019, 10, 27, 5, 45, tzinfo=GMT)),
        (400024, datetime.datetime(2019, 10, 27, 6, 15, tzinfo=GMT))
    ]

    assert result_gb == expected
    assert result_utc == expected
Exemplo n.º 2
0
def test_journeys_organisation_overriden_by_bh(load_org):
    date = datetime.date(2019, 4, 22)
    result = _query_journeys(SERVICE, DIRECTION, date).all()

    # Bank holidays and special days override organisation calendars,
    # should run as normal
    assert {r.journey_id for r in result} == _set_journeys()
Exemplo n.º 3
0
def test_journeys_no_dst(set_night_times):
    date = datetime.date(2019, 3, 24)
    query = _query_journeys(SERVICE, DIRECTION, date).order_by("departure")
    result = query.all()

    assert result == _expected_journeys(
        datetime.datetime(2019, 3, 24, 0, 15, tzinfo=GMT)
    )
Exemplo n.º 4
0
def test_journeys_not_in_week_month(load_db):
    # Set first journey to 2nd week of month
    models.Journey.query.filter_by(id=400012).update({"weeks": 1 << 1})
    db.session.commit()

    date = datetime.date(2019, 3, 3)
    result = _query_journeys(SERVICE, DIRECTION, date).all()

    assert {r.journey_id for r in result} == _set_journeys() - {400012}
Exemplo n.º 5
0
def test_journeys_weekday(load_db):
    # Should be Monday 4th March 2019, which this service does not run on
    # except bank holidays
    date = datetime.date(2019, 3, 4)
    assert date.isoweekday() == 1

    result = _query_journeys(SERVICE, DIRECTION, date).all()

    assert not result
Exemplo n.º 6
0
def test_journeys_bank_holiday_week_month(load_db):
    # Set first journey to 2nd week of month
    models.Journey.query.filter_by(id=400012).update({"weeks": 1 << 1})
    db.session.commit()

    # Bank holiday on 3rd week of month, should still run
    date = datetime.date(2019, 4, 22)
    result = _query_journeys(SERVICE, DIRECTION, date).all()

    assert {r.journey_id for r in result} == _set_journeys()
Exemplo n.º 7
0
def test_journeys_bank_holiday_override(load_db):
    # Override Easter Monday, id 4
    journey = models.Journey.query.get(400012)
    journey.exclude_holidays = 1 << 4
    db.session.commit()

    date = datetime.date(2019, 4, 22)
    result = _query_journeys(SERVICE, DIRECTION, date).all()

    assert {r.journey_id for r in result} == _set_journeys() - {400012}
Exemplo n.º 8
0
def test_journeys_bank_holiday(load_db):
    # Should be 22nd April 2019, ie Easter Monday
    date = datetime.date(2019, 4, 22)
    assert date.isoweekday() == 1

    query = _query_journeys(SERVICE, DIRECTION, date).order_by("departure")
    result = query.all()

    assert result == _expected_journeys(
        datetime.datetime(2019, 4, 22, 8, 30, tzinfo=BST)
    )
Exemplo n.º 9
0
def test_journeys_sunday_bst(load_db):
    # Should be Sunday 7th April 2019
    date = datetime.date(2019, 4, 7)
    assert date.isoweekday() == 7

    query = _query_journeys(SERVICE, DIRECTION, date).order_by("departure")
    result = query.all()

    assert result == _expected_journeys(
        datetime.datetime(2019, 4, 7, 8, 30, tzinfo=BST)
    )
Exemplo n.º 10
0
def test_journeys_sunday_gmt(load_db):
    # Should be Sunday 3rd March 2019
    date = datetime.date(2019, 3, 3)
    assert date.isoweekday() == 7

    query = _query_journeys(SERVICE, DIRECTION, date).order_by("departure")
    result = query.all()

    assert result == _expected_journeys(
        datetime.datetime(2019, 3, 3, 8, 30, tzinfo=GMT)
    )
Exemplo n.º 11
0
def test_journeys_special_day_override_bh(load_db):
    # Special period overriding journey on bank holiday
    special_date = datetime.date(2019, 4, 22)
    sp = models.SpecialPeriod(
        id=1,
        journey_ref=400012,
        date_start=special_date,
        date_end=special_date,
        operational=False
    )
    db.session.add(sp)
    db.session.commit()

    result = _query_journeys(SERVICE, DIRECTION, special_date).all()

    assert {r.journey_id for r in result} == _set_journeys() - {400012}
Exemplo n.º 12
0
def test_journeys_special_day(load_db):
    # Special period, this journey should run when it didn't before
    special_date = datetime.date(2019, 3, 4)
    sp = models.SpecialPeriod(
        id=1,
        journey_ref=400012,
        date_start=special_date,
        date_end=special_date,
        operational=True
    )
    db.session.add(sp)
    db.session.commit()

    result = _query_journeys(SERVICE, DIRECTION, special_date).all()

    assert {r.journey_id for r in result} == {400012}
Exemplo n.º 13
0
def test_journeys_organisation_weekday(load_org):
    date = datetime.date(2019, 4, 8)
    result = _query_journeys(SERVICE, DIRECTION, date).all()

    # Services associated with organisations still only run on specified days
    assert not result
Exemplo n.º 14
0
def test_journeys_organisation_working_except(load_org):
    date = datetime.date(2019, 4, 21)
    result = _query_journeys(SERVICE, DIRECTION, date).all()

    assert {r.journey_id for r in result} == _set_journeys()
Exemplo n.º 15
0
def test_journeys_organisation_working(load_org):
    date = datetime.date(2019, 4, 28)
    result = _query_journeys(SERVICE, DIRECTION, date).all()

    # 400014 not operational and 400015 operational during working days
    assert {r.journey_id for r in result} == _set_journeys() - {400014}
Exemplo n.º 16
0
def test_journeys_organisation_holiday(load_org):
    date = datetime.date(2019, 4, 14)
    result = _query_journeys(SERVICE, DIRECTION, date).all()

    # 400012 not operational and 400013 operational during holidays
    assert {r.journey_id for r in result} == _set_journeys() - {400012}