Skip to content

Commit

Permalink
fix: Reverted Views unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rijuma committed Aug 30, 2024
1 parent ecec71e commit 9757705
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions edx_name_affirmation/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
)
Expand All @@ -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)

Expand All @@ -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
)
Expand All @@ -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
)
Expand All @@ -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
)
Expand All @@ -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
)
Expand Down Expand Up @@ -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
)
Expand All @@ -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
)
Expand All @@ -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
)
Expand All @@ -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
)
Expand All @@ -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
)
Expand Down

0 comments on commit 9757705

Please sign in to comment.