Skip to content

Commit 95d0dbe

Browse files
test: Add some tests.
1 parent 545d646 commit 95d0dbe

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

promo_code/user/tests/auth/test_validation.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -301,23 +301,33 @@ def test_empty_surname_field(self):
301301
class AuthenticationTestCase(rest_framework.test.APITestCase):
302302
def setUp(self):
303303
self.client = rest_framework.test.APIClient()
304+
self.signin_url = django.urls.reverse('api-user:sign-in')
304305
super().setUp()
305306

306307
def tearDown(self):
307308
user.models.User.objects.all().delete()
308309
super().tearDown()
309310

310-
def test_signin_missing_fields(self):
311-
response = self.client.post(
312-
django.urls.reverse('api-user:sign-in'),
313-
{},
314-
format='json',
315-
)
311+
@parameterized.parameterized.expand(
312+
[
313+
('missing_password', {'email': '[email protected]'}, 'password'),
314+
('missing_email', {'password': 'any'}, 'email'),
315+
('empty_data', {}, ['email', 'password']),
316+
],
317+
)
318+
def test_missing_required_fields(self, case_name, data, expected_fields):
319+
response = self.client.post(self.signin_url, data, format='json')
316320
self.assertEqual(
317321
response.status_code,
318322
rest_framework.status.HTTP_400_BAD_REQUEST,
319323
)
320324

325+
if isinstance(expected_fields, list):
326+
for field in expected_fields:
327+
self.assertIn(field, response.data)
328+
else:
329+
self.assertIn(expected_fields, response.data)
330+
321331
def test_signin_invalid_password(self):
322332
user.models.User.objects.create_user(
323333

0 commit comments

Comments
 (0)