Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
steering
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AURA
steering
Commits
cde7192e
Verified
Commit
cde7192e
authored
2 months ago
by
Ernesto Rico Schmidt
Browse files
Options
Downloads
Patches
Plain Diff
test: add tests for resolve_conflicts function
parent
5e28d25d
No related branches found
No related tags found
No related merge requests found
Pipeline
#9004
passed
2 months ago
Stage: check
Stage: test
Stage: build
Stage: deploy
Stage: release
Pipeline: aura-tests
#9005
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
program/tests/test_services.py
+113
-3
113 additions, 3 deletions
program/tests/test_services.py
with
113 additions
and
3 deletions
program/tests/test_services.py
+
113
−
3
View file @
cde7192e
from
datetime
import
datetime
,
timedelta
import
pytest
from
rest_framework.exceptions
import
ValidationError
from
django.utils.timezone
import
make_aware
from
program.models
import
TimeSlot
from
program.services
import
generate_conflicts
,
generate_timeslots
,
make_conflicts
from
program.models
import
ScheduleConflictError
,
TimeSlot
from
program.services
import
(
generate_conflicts
,
generate_timeslots
,
make_conflicts
,
resolve_conflicts
,
)
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
from
program.typing
import
ScheduleCreateUpdateData
,
ScheduleData
pytestmark
=
pytest
.
mark
.
django_db
...
...
@@ -188,3 +194,107 @@ def test_make_conflicts_extend_weekly_schedule_collisions(admin_api_client, show
assert
len
(
projected
[
"
collisions
"
])
==
1
assert
projected
[
"
error
"
]
is
None
assert
projected
[
"
solution_choices
"
]
==
{
"
ours
"
,
"
theirs
"
}
def
test_resolve_conflicts_no_same_day_start_and_end
(
show
,
weekly_schedule
):
data
=
ScheduleCreateUpdateData
(
schedule
=
ScheduleData
(
end_time
=
weekly_schedule
.
end_time
.
strftime
(
"
%H:%M:%S
"
),
first_date
=
weekly_schedule
.
first_date
.
strftime
(
"
%Y-%m-%d
"
),
last_date
=
weekly_schedule
.
first_date
.
strftime
(
"
%Y-%m-%d
"
),
rrule_id
=
weekly_schedule
.
rrule_id
,
show_id
=
show
.
id
,
start_time
=
weekly_schedule
.
start_time
.
strftime
(
"
%H:%M:%S
"
),
)
)
with
pytest
.
raises
(
ValidationError
,
match
=
"
Start and end dates must not be the same.
"
):
resolve_conflicts
(
data
,
None
,
show
.
pk
)
def
test_resolve_conflicts_no_start_after_end
(
show
,
weekly_schedule
):
data
=
ScheduleCreateUpdateData
(
schedule
=
ScheduleData
(
end_time
=
weekly_schedule
.
start_time
.
strftime
(
"
%H:%M:%S
"
),
first_date
=
weekly_schedule
.
first_date
.
strftime
(
"
%Y-%m-%d
"
),
last_date
=
(
weekly_schedule
.
first_date
-
timedelta
(
days
=
1
)).
strftime
(
"
%Y-%m-%d
"
),
rrule_id
=
weekly_schedule
.
rrule_id
,
show_id
=
show
.
id
,
start_time
=
weekly_schedule
.
end_time
.
strftime
(
"
%H:%M:%S
"
),
)
)
with
pytest
.
raises
(
ValidationError
,
match
=
"
End date mustn
'
t be before start.
"
):
resolve_conflicts
(
data
,
None
,
show
.
pk
)
def
test_resolve_conflicts_one_solution_per_conflict
(
admin_api_client
,
show
,
weekly_schedule
):
admin_api_client
.
post
(
schedule_url
(),
data
=
schedule_data
(
weekly_schedule
,
show
),
format
=
"
json
"
)
data
=
ScheduleCreateUpdateData
(
schedule
=
ScheduleData
(
end_time
=
weekly_schedule
.
end_time
.
strftime
(
"
%H:%M:%S
"
),
first_date
=
weekly_schedule
.
first_date
.
strftime
(
"
%Y-%m-%d
"
),
rrule_id
=
weekly_schedule
.
rrule_id
,
show_id
=
show
.
id
,
start_time
=
weekly_schedule
.
start_time
.
strftime
(
"
%H:%M:%S
"
),
)
)
with
pytest
.
raises
(
ScheduleConflictError
,
match
=
"
Numbers of conflicts and solutions don
'
t match.
"
):
resolve_conflicts
(
data
,
None
,
show
.
pk
)
def
test_resolve_conflicts_unresolved_conflicts
(
admin_api_client
,
show
,
once_schedule
):
admin_api_client
.
post
(
schedule_url
(),
data
=
schedule_data
(
once_schedule
,
show
),
format
=
"
json
"
)
data
=
ScheduleCreateUpdateData
(
schedule
=
ScheduleData
(
end_time
=
once_schedule
.
end_time
.
strftime
(
"
%H:%M:%S
"
),
first_date
=
once_schedule
.
first_date
.
strftime
(
"
%Y-%m-%d
"
),
rrule_id
=
once_schedule
.
rrule_id
,
show_id
=
show
.
id
,
start_time
=
once_schedule
.
start_time
.
strftime
(
"
%H:%M:%S
"
),
),
solutions
=
{
""
:
"
ours
"
},
)
with
pytest
.
raises
(
ScheduleConflictError
,
match
=
"
Not all conflicts have been resolved.
"
):
resolve_conflicts
(
data
,
None
,
show
.
pk
)
def
test_resolve_conflicts_dry_run
(
admin_api_client
,
show
,
weekly_schedule
):
data
=
ScheduleCreateUpdateData
(
schedule
=
ScheduleData
(
dryrun
=
True
,
end_time
=
weekly_schedule
.
end_time
.
strftime
(
"
%H:%M:%S
"
),
first_date
=
weekly_schedule
.
first_date
.
strftime
(
"
%Y-%m-%d
"
),
rrule_id
=
weekly_schedule
.
rrule_id
,
show_id
=
show
.
id
,
start_time
=
weekly_schedule
.
start_time
.
strftime
(
"
%H:%M:%S
"
),
)
)
schedule
=
resolve_conflicts
(
data
,
None
,
show
.
pk
)
assert
len
(
schedule
[
"
create
"
])
==
52
or
53
assert
schedule
[
"
update
"
]
==
[]
assert
schedule
[
"
delete
"
]
==
[]
def
test_resolve_conflicts_no_errors
(
show
,
weekly_schedule
):
data
=
ScheduleCreateUpdateData
(
schedule
=
ScheduleData
(
end_time
=
weekly_schedule
.
end_time
.
strftime
(
"
%H:%M:%S
"
),
first_date
=
weekly_schedule
.
first_date
.
strftime
(
"
%Y-%m-%d
"
),
rrule_id
=
weekly_schedule
.
rrule_id
,
show_id
=
show
.
id
,
start_time
=
weekly_schedule
.
start_time
.
strftime
(
"
%H:%M:%S
"
),
)
)
schedule
=
resolve_conflicts
(
data
,
None
,
show
.
pk
)
assert
"
errors
"
not
in
schedule
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment