Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Feb 27, 2025
1 parent 39bf49d commit 8fb508b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
9 changes: 6 additions & 3 deletions cms/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1514,15 +1514,18 @@ def clean(self):
and ExternalCoursePage.objects.filter(course=self.course).exists()
):
raise ValidationError(
{"course": "There is already an external course page associated with this course."}

{
"course": "There is already an external course page associated with this course."
}
)
elif (
isinstance(self, ExternalCoursePage)
and CoursePage.objects.filter(course=self.course).exists()
):
raise ValidationError(
{"course": "There is already an internal course page associated with this course."}
{
"course": "There is already an internal course page associated with this course."
}
)

super().clean()
Expand Down
22 changes: 15 additions & 7 deletions cms/models_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2427,13 +2427,21 @@ def test_child_page_with_static_pages_with_platform(superuser_client):
@pytest.mark.parametrize(
"existing_course_factory, new_course_factory, expected_error",
[
(CoursePageFactory, ExternalCoursePageFactory,
"{'course': ['There is already an internal course page associated with this course.']}"),
(ExternalCoursePageFactory, CoursePageFactory,
"{'course': ['There is already an external course page associated with this course.']}"),
]
(
CoursePageFactory,
ExternalCoursePageFactory,
"{'course': ['There is already an internal course page associated with this course.']}",
),
(
ExternalCoursePageFactory,
CoursePageFactory,
"{'course': ['There is already an external course page associated with this course.']}",
),
],
)
def test_prevent_duplicate_pages_with_same_course(existing_course_factory, new_course_factory, expected_error):
def test_prevent_duplicate_pages_with_same_course(
existing_course_factory, new_course_factory, expected_error
):
"""
Tests that an error is raised when trying to create a duplicate course page.
"""
Expand All @@ -2442,4 +2450,4 @@ def test_prevent_duplicate_pages_with_same_course(existing_course_factory, new_c
with pytest.raises(ValidationError) as context:
new_course_factory.create(course=course_page.course)

assert (str(context.value) == expected_error)
assert str(context.value) == expected_error

0 comments on commit 8fb508b

Please sign in to comment.