Skip to content

Commit

Permalink
fix: Updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rijuma committed Aug 30, 2024
1 parent 9757705 commit 180fd69
Showing 1 changed file with 14 additions and 21 deletions.
35 changes: 14 additions & 21 deletions edx_name_affirmation/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
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 @@ -38,7 +37,6 @@ 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,9 +114,8 @@ def test_post_200(self):
'profile_name': self.PROFILE_NAME,
'verified_name': self.VERIFIED_NAME,
'verification_attempt_id': self.ATTEMPT_ID,
'verification_attempt_status': None,
}
response = self.json_post(
response = self.client.post(
reverse('edx_name_affirmation:verified_name'),
verified_name_data
)
Expand All @@ -139,13 +136,11 @@ def test_post_200_if_staff(self):
'profile_name': self.PROFILE_NAME,
'verified_name': self.VERIFIED_NAME,
'proctored_exam_attempt_id': self.ATTEMPT_ID,
'verification_attempt_status': None,
'status': VerifiedNameStatus.APPROVED.value,
}
response = self.json_post(
response = self.client.post(
reverse('edx_name_affirmation:verified_name'),
verified_name_data,
content_type='json'
verified_name_data
)
self.assertEqual(response.status_code, 200)

Expand All @@ -161,10 +156,9 @@ def test_post_403_non_staff(self):
'profile_name': self.PROFILE_NAME,
'verified_name': self.VERIFIED_NAME,
'verification_attempt_id': self.ATTEMPT_ID,
'verification_attempt_status': None,
'status': VerifiedNameStatus.APPROVED.value,
}
response = self.json_post(
response = self.client.post(
reverse('edx_name_affirmation:verified_name'),
verified_name_data
)
Expand All @@ -177,10 +171,9 @@ def test_post_400_invalid_name(self, verified_name):
'profile_name': self.PROFILE_NAME,
'verified_name': verified_name,
'verification_attempt_id': self.ATTEMPT_ID,
'verification_attempt_status': None,
'status': VerifiedNameStatus.SUBMITTED.value,
}
response = self.json_post(
response = self.client.post(
reverse('edx_name_affirmation:verified_name'),
verified_name_data
)
Expand All @@ -192,10 +185,9 @@ def test_post_400_invalid_serializer(self):
'profile_name': self.PROFILE_NAME,
'verified_name': self.VERIFIED_NAME,
'verification_attempt_id': 'xxyz',
'verification_attempt_status': None,
'status': VerifiedNameStatus.APPROVED.value,
}
response = self.json_post(
response = self.client.post(
reverse('edx_name_affirmation:verified_name'),
verified_name_data
)
Expand All @@ -209,7 +201,7 @@ def test_post_400_two_attempt_ids(self):
'verification_attempt_id': self.ATTEMPT_ID,
'proctored_exam_attempt_id': self.ATTEMPT_ID
}
response = self.json_post(
response = self.client.post(
reverse('edx_name_affirmation:verified_name'),
verified_name_data
)
Expand Down Expand Up @@ -465,6 +457,7 @@ def _get_expected_response(
'verified_name': verified_name_obj.verified_name,
'profile_name': verified_name_obj.profile_name,
'verification_attempt_id': verified_name_obj.verification_attempt_id,
'verification_attempt_status': None,
'proctored_exam_attempt_id': verified_name_obj.proctored_exam_attempt_id,
'status': verified_name_obj.status
}
Expand All @@ -483,7 +476,7 @@ def test_post_201(self):
'username': self.user.username,
'use_verified_name_for_certs': True
}
response = self.json_post(
response = self.client.post(
reverse('edx_name_affirmation:verified_name_config'),
config_data
)
Expand All @@ -499,11 +492,11 @@ def test_post_201_missing_field(self):
}
config_data_missing_field = {'username': self.user.username}

first_response = self.json_post(
first_response = self.client.post(
reverse('edx_name_affirmation:verified_name_config'),
initial_config_data
)
second_response = self.json_post(
second_response = self.client.post(
reverse('edx_name_affirmation:verified_name_config'),
config_data_missing_field
)
Expand All @@ -523,7 +516,7 @@ def test_post_201_if_staff(self):
'username': self.other_user.username,
'use_verified_name_for_certs': True
}
response = self.json_post(
response = self.client.post(
reverse('edx_name_affirmation:verified_name_config'),
config_data
)
Expand All @@ -537,7 +530,7 @@ def test_post_403_non_staff(self):
'username': self.other_user.username,
'use_verified_name_for_certs': True
}
response = self.json_post(
response = self.client.post(
reverse('edx_name_affirmation:verified_name_config'),
config_data
)
Expand All @@ -548,7 +541,7 @@ def test_post_400_invalid_serializer(self):
'username': self.user.username,
'use_verified_name_for_certs': 'not a boolean'
}
response = self.json_post(
response = self.client.post(
reverse('edx_name_affirmation:verified_name_config'),
config_data
)
Expand Down

0 comments on commit 180fd69

Please sign in to comment.