Skip to content
Snippets Groups Projects
Verified Commit 5e28d25d authored by Ernesto Rico Schmidt's avatar Ernesto Rico Schmidt
Browse files

test: add tests for make_conflicts function

parent 21681782
No related branches found
No related tags found
No related merge requests found
Pipeline #9002 passed
Pipeline: aura-tests

#9003

    from datetime import datetime from datetime import datetime, timedelta
    import pytest import pytest
    from django.utils.timezone import make_aware from django.utils.timezone import make_aware
    from program.models import TimeSlot from program.models import TimeSlot
    from program.services import generate_conflicts, generate_timeslots from program.services import generate_conflicts, generate_timeslots, make_conflicts
    from program.tests.factories import TimeslotFactory from program.tests.factories import TimeslotFactory
    from program.tests.test_schedules import schedule_data
    from program.tests.test_schedules import url as schedule_url
    from program.typing import ScheduleData
    pytestmark = pytest.mark.django_db pytestmark = pytest.mark.django_db
    ...@@ -125,3 +128,63 @@ def test_generate_timeslots_monthly(monthly_schedule): ...@@ -125,3 +128,63 @@ def test_generate_timeslots_monthly(monthly_schedule):
    timeslots = generate_timeslots(monthly_schedule) timeslots = generate_timeslots(monthly_schedule)
    assert len(timeslots) == 1 or 2 # I’m not sure why, but this changes on February assert len(timeslots) == 1 or 2 # I’m not sure why, but this changes on February
    def test_make_conflicts_once_schedule_no_collisions(show, once_schedule):
    data = ScheduleData(
    first_date=once_schedule.first_date.strftime("%Y-%m-%d"),
    end_time=once_schedule.end_time.strftime("%H:%M:%S"),
    rrule_id=once_schedule.rrule_id,
    show_id=show.id,
    start_time=once_schedule.start_time.strftime("%H:%M:%S"),
    )
    conflicts = make_conflicts(data, None, once_schedule.show_id)
    projected = conflicts["projected"][0]
    assert projected["collisions"] == []
    assert projected["error"] is None
    assert projected["solution_choices"] == set()
    def test_make_conflicts_weekly_schedule_collisions(admin_api_client, show, weekly_schedule):
    admin_api_client.post(schedule_url(), data=schedule_data(weekly_schedule, show), format="json")
    data = ScheduleData(
    first_date=weekly_schedule.first_date.strftime("%Y-%m-%d"),
    end_time=weekly_schedule.end_time.strftime("%H:%M:%S"),
    rrule_id=weekly_schedule.rrule_id,
    show_id=show.id,
    start_time=weekly_schedule.start_time.strftime("%H:%M:%S"),
    )
    conflicts = make_conflicts(data, None, weekly_schedule.show_id)
    for projected in conflicts["projected"]:
    assert len(projected["collisions"]) == 1
    assert projected["error"] is None
    assert projected["solution_choices"] == {"ours", "theirs"}
    def test_make_conflicts_extend_weekly_schedule_collisions(admin_api_client, show, weekly_schedule):
    response = admin_api_client.post(
    schedule_url(), data=schedule_data(weekly_schedule, show), format="json"
    )
    schedule_id = response.json().get("id")
    in_one_year = datetime.now() + timedelta(days=365)
    data = ScheduleData(
    first_date=weekly_schedule.first_date.strftime("%Y-%m-%d"),
    end_time=weekly_schedule.end_time.strftime("%H:%M:%S"),
    last_date=in_one_year.strftime("%Y-%m-%d"),
    rrule_id=weekly_schedule.rrule_id,
    show_id=show.id,
    start_time=weekly_schedule.start_time.strftime("%H:%M:%S"),
    )
    conflicts = make_conflicts(data, schedule_id, weekly_schedule.show_id)
    for projected in conflicts["projected"]:
    assert len(projected["collisions"]) == 1
    assert projected["error"] is None
    assert projected["solution_choices"] == {"ours", "theirs"}
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment