Skip to content

Commit

Permalink
tests: adjusted tests including prices information on the admin Cours…
Browse files Browse the repository at this point in the history
…eRun
  • Loading branch information
Tiago-Salles committed Dec 9, 2024
1 parent 9951f9d commit fbc3e6e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 25 deletions.
38 changes: 30 additions & 8 deletions tests/apps/courses/test_admin_course_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,10 @@ def _prepare_add_view_post(self, course, status_code):
"enrollment_end_0": "2015-01-23",
"enrollment_end_1": "09:07:11",
"catalog_visibility": "course_and_search",
"offer": "free",
"price": 0.0,
"offer": "paid",
"price": 59.98,
"certificate_offer": "paid",
"certificate_price": 59.98,
"sync_mode": "manual",
"display_mode": "detailed",
}
Expand Down Expand Up @@ -436,6 +438,7 @@ def test_admin_course_run_add_view_post_staff_user_page_permission(self):

def _prepare_change_view_post(self, course_run, course, status_code, check_method):
"""Helper method to test the change view."""

url = reverse("admin:courses_courserun_change", args=[course_run.id])
data = {
"direct_course": course.id,
Expand All @@ -452,8 +455,10 @@ def _prepare_change_view_post(self, course_run, course, status_code, check_metho
"enrollment_end_1": "09:07:11",
"enrollment_count": "5",
"catalog_visibility": "course_and_search",
"offer": "free",
"price": 0.0,
"offer": "paid",
"price": "59.98",
"certificate_offer": "paid",
"certificate_price": "29.98",
"sync_mode": "manual",
"display_mode": "detailed",
}
Expand Down Expand Up @@ -483,13 +488,21 @@ def _prepare_change_view_post(self, course_run, course, status_code, check_metho
)
check_method(course_run.enrollment_count, 5)
check_method(course_run.sync_mode, "manual")
check_method(course_run.offer, "paid")
check_method(float(course_run.price), 59.98)
check_method(course_run.certificate_offer, "paid")
check_method(float(course_run.certificate_price), 29.98)

return response

def test_admin_course_run_change_view_post_anonymous(self):
"""
Anonymous users should not be allowed to update course runs via the admin.
"""
course_run = CourseRunFactory()
course_run = CourseRunFactory(
offer="free",
certificate_offer="free",
)
snapshot = CourseFactory(page_parent=course_run.direct_course.extended_object)

response = self._prepare_change_view_post(
Expand All @@ -503,7 +516,10 @@ def test_admin_course_run_change_view_post_superuser_draft(self):
"""
Validate that the draft course run can be updated via the admin.
"""
course_run = CourseRunFactory()
course_run = CourseRunFactory(
offer="paid",
certificate_offer="paid",
)
snapshot = CourseFactory(page_parent=course_run.direct_course.extended_object)

user = UserFactory(is_staff=True, is_superuser=True)
Expand All @@ -515,7 +531,10 @@ def test_admin_course_run_change_view_post_superuser_public(self):
"""
Validate that the public course run can not be updated via the admin.
"""
course_run = CourseRunFactory()
course_run = CourseRunFactory(
offer="free",
certificate_offer="free",
)
snapshot = CourseFactory(page_parent=course_run.direct_course.extended_object)
course_run.direct_course.extended_object.publish("en")
course_run.refresh_from_db()
Expand All @@ -532,7 +551,10 @@ def test_admin_course_run_change_view_post_staff_user_missing_permission(self):
Staff users with missing page permissions can not update a course run via the admin
unless CMS permissions are not activated.
"""
course_run = CourseRunFactory()
course_run = CourseRunFactory(
offer="free",
certificate_offer="free",
)
snapshot = CourseFactory(page_parent=course_run.direct_course.extended_object)

user = UserFactory(is_staff=True)
Expand Down
23 changes: 12 additions & 11 deletions tests/apps/courses/test_admin_form_course_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@ def _get_admin_form(course, user):
"catalog_visibility": "course_and_search",
"offer": "free",
"price": 0.0,
"certificate_offer": "free",
"certificate_price": 0.0,
"sync_mode": "manual",
"display_mode": "detailed",
}

request = RequestFactory().get("/")
request.user = user
CourseRunAdminForm.request = request
Expand Down Expand Up @@ -112,17 +115,15 @@ def test_admin_form_course_run_superuser_empty_form(self):
form = CourseRunAdminForm(data={"resource_link": "https://example.com"})

self.assertFalse(form.is_valid())
self.assertEqual(
form.errors,
{
"direct_course": ["This field is required."],
"display_mode": ["This field is required."],
"languages": ["This field is required."],
"catalog_visibility": ["This field is required."],
"offer": ["This field is required."],
"sync_mode": ["This field is required."],
},
)

for field in [
"direct_course",
"display_mode",
"languages",
"catalog_visibility",
"sync_mode",
]:
self.assertEqual(form.errors[field], ["This field is required."])

# Direct course choices

Expand Down
12 changes: 6 additions & 6 deletions tests/apps/courses/test_api_course_run_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -1467,20 +1467,20 @@ def test_api_course_run_sync_price_info_as_optional(self, mock_signal):
draft_course_run = CourseRun.objects.get(direct_course=course)
draft_serializer = SyncCourseRunSerializer(instance=draft_course_run)

self.assertEqual(draft_serializer.data["price"], None)
self.assertEqual(draft_serializer.data["price_currency"], "EUR")
self.assertEqual(draft_serializer.data["offer"], "free")
self.assertEqual(draft_serializer.data["price"], None)
self.assertEqual(draft_serializer.data["offer"], None)
self.assertEqual(draft_serializer.data["certificate_price"], None)
self.assertEqual(draft_serializer.data["certificate_offer"], "free")
self.assertEqual(draft_serializer.data["certificate_offer"], None)

public_course_run = CourseRun.objects.get(direct_course=course.public_extension)
public_serializer = SyncCourseRunSerializer(instance=public_course_run)

self.assertEqual(public_serializer.data["price"], None)
self.assertEqual(public_serializer.data["price_currency"], "EUR")
self.assertEqual(public_serializer.data["offer"], "free")
self.assertEqual(public_serializer.data["price"], None)
self.assertEqual(public_serializer.data["offer"], None)
self.assertEqual(public_serializer.data["certificate_price"], None)
self.assertEqual(public_serializer.data["certificate_offer"], "free")
self.assertEqual(public_serializer.data["certificate_offer"], None)

self.assertEqual(
course.extended_object.title_set.first().publisher_state,
Expand Down

0 comments on commit fbc3e6e

Please sign in to comment.