From 9757705e10659b81ca87a5b4970f4caedcb36ae1 Mon Sep 17 00:00:00 2001 From: Marcos Date: Fri, 30 Aug 2024 11:28:32 -0300 Subject: [PATCH] fix: Reverted Views unit tests --- edx_name_affirmation/tests/test_views.py | 29 +++++++++++++----------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/edx_name_affirmation/tests/test_views.py b/edx_name_affirmation/tests/test_views.py index 5ff7063..af74c2d 100644 --- a/edx_name_affirmation/tests/test_views.py +++ b/edx_name_affirmation/tests/test_views.py @@ -8,6 +8,7 @@ from django.contrib.auth import get_user_model from django.core.cache import cache from django.urls import reverse +from functools import partial from edx_name_affirmation.api import ( create_verified_name, @@ -37,6 +38,7 @@ def setUp(self): # Create fresh configs with default values VerifiedNameConfig.objects.create(user=self.user) VerifiedNameConfig.objects.create(user=self.other_user) + self.json_post = partial(self.client.post, content_type="application/json") def tearDown(self): super().tearDown() @@ -116,7 +118,7 @@ def test_post_200(self): 'verification_attempt_id': self.ATTEMPT_ID, 'verification_attempt_status': None, } - response = self.client.post( + response = self.json_post( reverse('edx_name_affirmation:verified_name'), verified_name_data ) @@ -140,9 +142,10 @@ def test_post_200_if_staff(self): 'verification_attempt_status': None, 'status': VerifiedNameStatus.APPROVED.value, } - response = self.client.post( + response = self.json_post( reverse('edx_name_affirmation:verified_name'), - verified_name_data + verified_name_data, + content_type='json' ) self.assertEqual(response.status_code, 200) @@ -161,7 +164,7 @@ def test_post_403_non_staff(self): 'verification_attempt_status': None, 'status': VerifiedNameStatus.APPROVED.value, } - response = self.client.post( + response = self.json_post( reverse('edx_name_affirmation:verified_name'), verified_name_data ) @@ -177,7 +180,7 @@ def test_post_400_invalid_name(self, verified_name): 'verification_attempt_status': None, 'status': VerifiedNameStatus.SUBMITTED.value, } - response = self.client.post( + response = self.json_post( reverse('edx_name_affirmation:verified_name'), verified_name_data ) @@ -192,7 +195,7 @@ def test_post_400_invalid_serializer(self): 'verification_attempt_status': None, 'status': VerifiedNameStatus.APPROVED.value, } - response = self.client.post( + response = self.json_post( reverse('edx_name_affirmation:verified_name'), verified_name_data ) @@ -206,7 +209,7 @@ def test_post_400_two_attempt_ids(self): 'verification_attempt_id': self.ATTEMPT_ID, 'proctored_exam_attempt_id': self.ATTEMPT_ID } - response = self.client.post( + response = self.json_post( reverse('edx_name_affirmation:verified_name'), verified_name_data ) @@ -480,7 +483,7 @@ def test_post_201(self): 'username': self.user.username, 'use_verified_name_for_certs': True } - response = self.client.post( + response = self.json_post( reverse('edx_name_affirmation:verified_name_config'), config_data ) @@ -496,11 +499,11 @@ def test_post_201_missing_field(self): } config_data_missing_field = {'username': self.user.username} - first_response = self.client.post( + first_response = self.json_post( reverse('edx_name_affirmation:verified_name_config'), initial_config_data ) - second_response = self.client.post( + second_response = self.json_post( reverse('edx_name_affirmation:verified_name_config'), config_data_missing_field ) @@ -520,7 +523,7 @@ def test_post_201_if_staff(self): 'username': self.other_user.username, 'use_verified_name_for_certs': True } - response = self.client.post( + response = self.json_post( reverse('edx_name_affirmation:verified_name_config'), config_data ) @@ -534,7 +537,7 @@ def test_post_403_non_staff(self): 'username': self.other_user.username, 'use_verified_name_for_certs': True } - response = self.client.post( + response = self.json_post( reverse('edx_name_affirmation:verified_name_config'), config_data ) @@ -545,7 +548,7 @@ def test_post_400_invalid_serializer(self): 'username': self.user.username, 'use_verified_name_for_certs': 'not a boolean' } - response = self.client.post( + response = self.json_post( reverse('edx_name_affirmation:verified_name_config'), config_data )