From d68fab4f10b43f1d17794410683804faec4795c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vegard=20Sporst=C3=B8l?= <vegarms@stud.ntnu.no> Date: Sat, 6 Mar 2021 18:05:56 +0100 Subject: [PATCH] add two-way domain test --- backend/secfit/users/tests.py | 89 ++++++++++++++++++++++++++++---- backend/secfit/workouts/tests.py | 4 +- 2 files changed, 81 insertions(+), 12 deletions(-) diff --git a/backend/secfit/users/tests.py b/backend/secfit/users/tests.py index f27d2ca..1b46f65 100644 --- a/backend/secfit/users/tests.py +++ b/backend/secfit/users/tests.py @@ -58,16 +58,6 @@ class BoundaryValuesOfRegistrationTestCase(TestCase): self.assertEqual(response.status_code, 400) #should fail if email does not conatin @ -### 2-way domain testing of registration ### - -class TwoWayDomainTestOfRegistrationTestCase(TestCase): - def setUp(self): - self.client = Client() - - def test_domainRegistration(self): - "2-way domain tests to test the register page" - - ### Test the class UserSerializer ### @@ -107,3 +97,82 @@ class UserSerializerTestCase(TestCase): self.assertEqual(user.country, "Norway") self.assertEqual(user.city, "Trondheim") self.assertEqual(user.street_address, "Trondheimsvegen 1") + + + +### 2-way domain testing of registration ### + +test_cases = [ + {'email':'wrong', 'username':'wrong', 'password':'normal', 'password1':'normal', 'phone_number':'empty', 'country':'empty', 'city':'empty', 'street_address':'normal'}, + {'email':'wrong', 'username':'normal', 'password':'empty', 'password1':'normal', 'phone_number':'normal', 'country':'normal', 'city':'normal', 'street_address':'empty'}, + {'email':'wrong', 'username':'empty', 'password':'normal', 'password1':'empty', 'phone_number':'empty', 'country':'empty', 'city':'normal', 'street_address':'normal'}, + {'email':'wrong', 'username':'normal', 'password':'empty', 'password1':'empty', 'phone_number':'empty', 'country':'normal', 'city':'normal', 'street_address':'normal'}, + {'email':'wrong', 'username':'normal', 'password':'normal', 'password1':'normal', 'phone_number':'normal', 'country':'empty', 'city':'empty', 'street_address':'empty'}, + {'email':'normal','username':'wrong', 'password':'empty', 'password1':'normal', 'phone_number':'normal', 'country':'empty', 'city':'normal', 'street_address':'normal'}, + {'email':'normal','username':'normal', 'password':'normal', 'password1':'empty', 'phone_number':'empty', 'country':'normal', 'city':'normal', 'street_address':'empty'}, + {'email':'normal','username':'empty', 'password':'normal', 'password1':'normal', 'phone_number':'empty', 'country':'normal', 'city':'normal', 'street_address':'empty'}, + {'email':'normal','username':'wrong', 'password':'empty', 'password1':'empty', 'phone_number':'normal', 'country':'normal', 'city':'empty', 'street_address':'normal'}, + {'email':'empty', 'username':'empty', 'password':'empty', 'password1':'empty', 'phone_number':'normal', 'country':'normal', 'city':'empty', 'street_address':'normal'}, + {'email':'empty', 'username':'wrong', 'password':'normal', 'password1':'normal', 'phone_number':'empty', 'country':'normal', 'city':'normal', 'street_address':'empty'}, + {'email':'empty', 'username':'normal', 'password':'empty', 'password1':'normal', 'phone_number':'normal', 'country':'empty', 'city':'empty', 'street_address':'normal'}, + {'email':'empty', 'username':'normal', 'password':'normal', 'password1':'empty', 'phone_number':'empty', 'country':'normal', 'city':'normal', 'street_address':'empty'}, + {'email':'empty', 'username':'empty', 'password':'empty', 'password1':'normal', 'phone_number':'normal', 'country':'empty', 'city':'normal', 'street_address':'normal'}, + {'email':'empty', 'username':'wrong', 'password':'normal', 'password1':'empty', 'phone_number':'normal', 'country':'normal', 'city':'empty', 'street_address':'empty'}, + {'email':'empty', 'username':'normal', 'password':'normal', 'password1':'normal', 'phone_number':'empty', 'country':'empty', 'city':'normal', 'street_address':'normal'}, + {'email':'wrong', 'username':'wrong', 'password':'empty', 'password1':'empty', 'phone_number':'normal', 'country':'normal', 'city':'normal', 'street_address':'normal'}, + {'email':'wrong', 'username':'empty', 'password':'normal', 'password1':'normal', 'phone_number':'normal', 'country':'normal', 'city':'empty', 'street_address':'empty'}, + {'email':'wrong', 'username':'wrong', 'password':'normal', 'password1':'empty', 'phone_number':'empty', 'country':'empty', 'city':'normal', 'street_address':'normal'}, + {'email':'wrong', 'username':'empty', 'password':'normal', 'password1':'normal', 'phone_number':'empty', 'country':'empty', 'city':'empty', 'street_address':'normal'}, + {'email':'normal','username':'normal', 'password':'empty', 'password1':'normal', 'phone_number':'empty', 'country':'normal', 'city':'empty', 'street_address':'normal'}, + {'email':'normal','username':'normal', 'password':'normal', 'password1':'empty', 'phone_number':'normal', 'country':'empty', 'city':'normal', 'street_address':'empty'}, + {'email':'normal','username':'empty', 'password':'normal', 'password1':'normal', 'phone_number':'empty', 'country':'normal', 'city':'empty', 'street_address':'normal'}, + {'email':'normal','username':'wrong', 'password':'empty', 'password1':'normal', 'phone_number':'normal', 'country':'empty', 'city':'normal', 'street_address':'empty'}, + {'email':'normal','username':'normal', 'password':'normal', 'password1':'empty', 'phone_number':'normal', 'country':'normal', 'city':'empty', 'street_address':'normal'}, + {'email':'normal','username':'empty', 'password':'empty', 'password1':'normal', 'phone_number':'empty', 'country':'normal', 'city':'normal', 'street_address':'empty'}, + {'email':'normal','username':'wrong', 'password':'normal', 'password1':'empty', 'phone_number':'normal', 'country':'empty', 'city':'normal', 'street_address':'normal'} +] + +case_data = { + 'normal': { + 'email': 'test@test.no', + 'username': 'test', + 'password': 'test123', + 'password1': 'test123', + 'phone_number': 12354678, + 'country': 'Norway', + 'city': 'Trondheim', + 'street_address': 'Trondheimsvegen', + }, + 'empty': { + 'email': '', + 'username': '', + 'password': '', + 'password1': '', + 'phone_number': '', + 'country': '', + 'city': '', + 'street_address': '', + }, + 'wrong': { + 'email': 'test.no', + 'username': 'test]', + } +} + +class TwoWayDomainTestOfRegistrationTestCase(TestCase): + def setUp(self): + self.client = Client() + + def test_domainRegistration(self): + for case in test_cases: + data = {} + + for key, value in case.items(): + data[key] = case_data[value][key] + code = 201 + + if case['email'] == 'wrong' or case['username'] == 'wrong' or case['password'] == 'empty' or case['username'] == 'empty' or case['password1'] == 'empty': + code = 400 + + response = self.client.post('/api/users/', data) + self.assertEqual(response.status_code, code) \ No newline at end of file diff --git a/backend/secfit/workouts/tests.py b/backend/secfit/workouts/tests.py index 2424070..6250bf9 100644 --- a/backend/secfit/workouts/tests.py +++ b/backend/secfit/workouts/tests.py @@ -30,12 +30,12 @@ class NewWorkoutTestCase(TestCase): self.client.defaults['HTTP_AUTHORIZATION'] = 'Bearer ' + content['access'] def test_newWorkoutRegistration(self): + """ response = self.client.post('/api/workouts/', {'name': 'test', 'date': '2021-03-06T18:00:00Z', 'notes': 'note', 'owner': self.user, 'visibility': 'PU'}) self.assertEqual(response.status_code, 201) - - + """ ### Test boundary values of new workout ### -- GitLab