-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: change empty string to null and refactor serializers
- Loading branch information
1 parent
d6cd4ec
commit bec8966
Showing
8 changed files
with
83 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -358,6 +358,7 @@ def test_course_staff_write_access(self): | |
CourseStaffRole.objects.create(user=course_staff_user, course_id=self.course_id) | ||
response = self.patch_api(course_staff_user, { | ||
'provider': None, | ||
'escalation_email': None, | ||
}) | ||
self.assertEqual(204, response.status_code) | ||
|
||
|
@@ -370,11 +371,30 @@ def test_patch_invalid_data_no_provider(self): | |
response = self.patch_api(self.user, data) | ||
self.assertEqual(400, response.status_code) | ||
|
||
def test_patch_invalid_data_no_escalation_email(self): | ||
@ddt.data('test_provider', None) | ||
def test_patch_invalid_data_no_escalation_email(self, provider_name): | ||
""" | ||
Assert that endpoint returns 400 if provider is provided but escalation_email is missing | ||
""" | ||
data = {'provider': 'test_provider'} | ||
data = {'provider': provider_name} | ||
|
||
response = self.patch_api(self.user, data) | ||
self.assertEqual(400, response.status_code) | ||
|
||
def test_patch_invalid_data_escalation_email(self): | ||
""" | ||
Assert that endpoint returns 400 if provider is None but escalation_email is not | ||
""" | ||
data = {'provider': None, 'escalation_email': '[email protected]'} | ||
|
||
response = self.patch_api(self.user, data) | ||
self.assertEqual(400, response.status_code) | ||
|
||
def test_patch_invalid_data_invalid_escalation_email(self): | ||
""" | ||
Assert that endpoint returns 400 if the escalation email is not a valid email. | ||
""" | ||
data = {'provider': 'test_provider', 'escalation_email': 'test'} | ||
|
||
response = self.patch_api(self.user, data) | ||
self.assertEqual(400, response.status_code) | ||
|
@@ -529,14 +549,15 @@ def test_patch_null_provider(self): | |
""" | ||
Assert provider can be explicitly set to null | ||
""" | ||
data = {'provider': None} | ||
data = {'provider': None, 'escalation_email': None} | ||
|
||
response = self.patch_api(self.user, data) | ||
self.assertEqual(204, response.status_code) | ||
self.assertEqual(len(CourseExamConfiguration.objects.all()), 1) | ||
|
||
config = CourseExamConfiguration.get_configuration_for_course(self.course_id) | ||
self.assertEqual(config.provider, None) | ||
self.assertEqual(config.escalation_email, None) | ||
|
||
def test_get_config(self): | ||
""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -926,6 +926,7 @@ def test_get_escalation_email_no_configuration(self): | |
self.assertEqual(get_escalation_email(self.exam.id), None) | ||
|
||
|
||
@ddt.ddt | ||
class TestCreateOrUpdateCourseExamConfiguration(ExamsAPITestCase): | ||
""" | ||
Tests for the create_or_update_course_exam_configuration API function. | ||
|
@@ -940,28 +941,11 @@ def setUp(self): | |
provider=self.test_provider, | ||
) | ||
|
||
def test_create_or_update_course_exam_configuration_none_provider(self): | ||
""" | ||
Test that the create_or_update_course_exam_configuration function correctly sets the provider to None. | ||
""" | ||
expected_provider = None | ||
|
||
config = CourseExamConfigurationFactory( | ||
course_id=self.exam.course_id, | ||
provider=self.test_provider, | ||
) | ||
|
||
create_or_update_course_exam_configuration(self.exam.course_id, expected_provider, '') | ||
|
||
config.refresh_from_db() | ||
|
||
self.assertEqual(config.provider, expected_provider) | ||
self.assertEqual(config.escalation_email, '') | ||
|
||
def test_create_or_update_course_exam_configuration_none_provider_escalation_email(self): | ||
@ddt.data('[email protected]', '') | ||
def test_create_or_update_course_exam_configuration_none_provider(self, escalation_email): | ||
""" | ||
Test that the create_or_update_course_exam_configuration function correctly sets the provider to None and | ||
disregards any provided escalation_email, because it must be set to the empty string. | ||
Test that the create_or_update_course_exam_configuration function correctly sets the provider to None and that | ||
the function disregards any provided escalation_email, because it must be set to None. | ||
""" | ||
expected_provider = None | ||
|
||
|
@@ -970,12 +954,12 @@ def test_create_or_update_course_exam_configuration_none_provider_escalation_ema | |
provider=self.test_provider, | ||
) | ||
|
||
create_or_update_course_exam_configuration(self.exam.course_id, expected_provider, '[email protected]') | ||
create_or_update_course_exam_configuration(self.exam.course_id, expected_provider, escalation_email) | ||
|
||
config.refresh_from_db() | ||
|
||
self.assertEqual(config.provider, expected_provider) | ||
self.assertEqual(config.escalation_email, '') | ||
self.assertEqual(config.escalation_email, None) | ||
|
||
def test_create_or_update_course_exam_configuration_provider(self): | ||
""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters