Commit 2bab2467 authored by Ola Hermann Opheim's avatar Ola Hermann Opheim
Browse files

Merge branch 'test/register_tests' into 'master'

Test/register tests

See merge request olahop/agreelance123!10
parents 6adb7372 0010bbbf
...@@ -234,7 +234,7 @@ class GiveTaskOfferBoundaryTest(unittest.TestCase): ...@@ -234,7 +234,7 @@ class GiveTaskOfferBoundaryTest(unittest.TestCase):
# title 199 chars # title 199 chars
nr_of_offers = TaskOffer.objects.count() nr_of_offers = TaskOffer.objects.count()
self.client.post(f'/projects/{self.testBoundaryProject.pk}/', { self.client.post(f'/projects/{self.testBoundaryProject.pk}/', {
'title': title_200char, 'title': title_200char[:-1],
'description': 'max 500', 'description': 'max 500',
'price': 123, 'price': 123,
'taskvalue': self.testBoundaryTask.id, 'taskvalue': self.testBoundaryTask.id,
...@@ -245,7 +245,7 @@ class GiveTaskOfferBoundaryTest(unittest.TestCase): ...@@ -245,7 +245,7 @@ class GiveTaskOfferBoundaryTest(unittest.TestCase):
# title 200 chars # title 200 chars
nr_of_offers = TaskOffer.objects.count() nr_of_offers = TaskOffer.objects.count()
self.client.post(f'/projects/{self.testBoundaryProject.pk}/', { self.client.post(f'/projects/{self.testBoundaryProject.pk}/', {
'title': title_200char[:-1], 'title': title_200char,
'description': 'max 500', 'description': 'max 500',
'price': 123, 'price': 123,
'taskvalue': self.testBoundaryTask.id, 'taskvalue': self.testBoundaryTask.id,
...@@ -332,7 +332,7 @@ class GiveTaskOfferBoundaryTest(unittest.TestCase): ...@@ -332,7 +332,7 @@ class GiveTaskOfferBoundaryTest(unittest.TestCase):
'taskvalue': self.testBoundaryTask.id, 'taskvalue': self.testBoundaryTask.id,
'offer_submit': True 'offer_submit': True
}) })
# TODO: self.assertEqual(TaskOffer.objects.count(), nr_of_offers) # self.assertEqual(TaskOffer.objects.count(), nr_of_offers)
# price 0 # price 0
nr_of_offers = TaskOffer.objects.count() nr_of_offers = TaskOffer.objects.count()
...@@ -416,14 +416,8 @@ class AcceptingOfferOutputTest(unittest.TestCase): ...@@ -416,14 +416,8 @@ class AcceptingOfferOutputTest(unittest.TestCase):
project = response.context['project'] project = response.context['project']
self.assertEqual(project, self.testAcceptProject) self.assertEqual(project, self.testAcceptProject)
self.assertTrue(self.userOfferer.profile in project.participants.all()) self.assertTrue(self.userOfferer.profile in project.participants.all())
# TODO: fix in code if this is the error
# self.assertEqual(project.status, 'i') # self.assertEqual(project.status, 'i')
# Checks output task relevant data # Checks output task relevant data
task = Task.objects.get(id=self.testAcceptTask.id) task = Task.objects.get(id=self.testAcceptTask.id)
self.assertEqual(response.context['tasks'][0], self.testAcceptTask) self.assertEqual(response.context['tasks'][0], self.testAcceptTask)
......
...@@ -7,80 +7,668 @@ from projects.models import Project, ProjectCategory, Task ...@@ -7,80 +7,668 @@ from projects.models import Project, ProjectCategory, Task
from projects.views import get_user_task_permissions from projects.views import get_user_task_permissions
# Task 3 - I
class SignUpPageTest(unittest.TestCase): class SignUpPageBoundaryTest(unittest.TestCase):
def setUp(self): def setUp(self):
self.client = Client() self.client = Client()
self.testCategory = ProjectCategory.objects.create(name='test1') self.testCategory = ProjectCategory.objects.create(name='test1')
self.testCategory2 = ProjectCategory.objects.create(name='test2') self.testCategory2 = ProjectCategory.objects.create(name='test2')
self.testCategory3 = ProjectCategory.objects.create(name='test3')
def test_sign_up_page(self): def test_sign_up_page(self):
validUsernameLength = "NFRLRGi2KoOtEcOLJyGWwOaXChNueq2bq12qrlS6S0YPkku3JsfYo2BPWOhkNFRLRGi2KoOtEcOLJyGWwOaXChNueq2bq12qrlS6S0YPkku3JsfYo2BPWOhkNFRLRGi2KoOtEcOLJyGWwOaXChNue" test_data = {
validUsernameExactLength = "kNFRLRGi2KoOtEcOLJyGWwOaXChNueq2bq12qrlS6S0YPkku3JsfYo2BPWOhkNFRLRGi2KoOtEcOLJyGWwOaXChNueq2bq12qrlS6S0YPkku3JsfYo2BPWOhkNFRLRGi2KoOtEcOLJyGWwOaXChNue" 'username': 'max 150',
unvalidUsernameLength = "AkNFRLRGi2KoOtEcOLJyGWwOaXChNueq2bq12qrlS6S0YPkku3JsfYo2BPWOhkNFRLRGi2KoOtEcOLJyGWwOaXChNueq2bq12qrlS6S0YPkku3JsfYo2BPWOhkNFRLRGi2KoOtEcOLJyGWwOaXChNue"
# Test username boundary values
response1 = self.client.post('/user/signup/', {
'username': validUsernameLength,
'first_name': 'max 30', 'first_name': 'max 30',
'last_name': 'max 30', 'last_name': 'max 30',
'categories': '1', 'categories': '1',
'categories': '2',
'company': 'max 30', 'company': 'max 30',
'email': 'max254@gmail.com', 'email': 'max254@gmail.com',
'email_confirmation': 'max254@gmail.com', 'email_confirmation': 'max254@gmail.com',
'password1': 'rules123', 'password1': 'veryDifficult123',
'password2': 'rules123', 'password2': 'veryDifficult123',
'phone_number': '501234567', 'phone_number': 'max 50',
'country': 'Norge', 'country': 'max 50',
'state': 'Tadasd', 'state': 'max 50',
'city': 'max', 'city': 'max 50',
'postal_code': '1234', 'postal_code': 'max 50',
'street_address': 'max 30' 'street_address': 'max 50'
}) }
self.assertEqual(response1.status_code, 302)
chars_30 = "NNEcOLJyGWwOaXChNueq2sfYo2BPWO"
chars_50 = "NNEcOLJyGWwOaXueq2sfYo2BPWOyGWwOaXChNueq2sfYo2BPWO"
chars_150 = "kNFRLRGi2KoOtEcOLJyGWwOaXChNueq2bq12qrlS6S0YPkku3JsfYo2BPWOhkNFRLRGi2KoOtEcOLJyGWwOaXChNueq2bq12qrlS6S0YPkku3JsfYo2BPWOhkNFRLRGi2KoOtEcOLJyGWwOaXChNue"
email_254chars = "kNFkjhRLRGi2KoOtEcOLJyGWwOaXChNueq2bq12qrlS6S0YPkku3JsfYo2BPWOhkNFRLRGi2KoOtEcOLJyGWwOaXChNueq2bq12kNFRLRGi2KoOtEcOLJyGWwOaXChNueq2bq12qrlS6S0YPkku3JsfYo2BPWOhkNFRLRGi2KoOtEcOLJyGWwOaXChNueq2bq12qrlS6qrlS6S0YPkku3JsfYo2BPWOhkNFRLRGi2KoOtEcOLJyG@gmail.com"
counter = 0 # ensures valid usernames
# Test username boundary values by check if list of users extends
# username 0 chars
users = User.objects.count()
test_data['username'] = ''
self.client.post('/user/signup/', test_data)
self.assertEqual(User.objects.count(), users)
# username 1 chars
users = User.objects.count()
test_data['username'] = "A"
self.client.post('/user/signup/', test_data)
self.assertEqual(User.objects.count(), users+1)
# username 150 chars
users = User.objects.count()
test_data['username'] = chars_150
self.client.post('/user/signup/', test_data)
self.assertEqual(User.objects.count(), users+1)
# username 151 chars
users = User.objects.count()
test_data['username'] = chars_150 + "A"
self.client.post('/user/signup/', test_data)
self.assertEqual(User.objects.count(), users)
# Test first name boundary values by check if list of users extends
# first name 0 chars
users = User.objects.count()
test_data['username'] = "A" + str(counter)
counter += 1
test_data['first_name'] = ''
self.client.post('/user/signup/', test_data)
self.assertEqual(User.objects.count(), users)
# first name 1 chars
users = User.objects.count()
test_data['username'] = "A" + str(counter)
counter += 1
test_data['first_name'] = "A"
self.client.post('/user/signup/', test_data)
self.assertEqual(User.objects.count(), users+1)
# first name 30 chars
users = User.objects.count()
test_data['username'] = "A" + str(counter)
counter += 1
test_data['first_name'] = chars_30
self.client.post('/user/signup/', test_data)
self.assertEqual(User.objects.count(), users+1)
response2 = self.client.post('/user/signup/', { # first name 31 chars
'username': validUsernameExactLength, users = User.objects.count()
test_data['username'] = "A" + str(counter)
counter += 1
test_data['first_name'] = chars_30 + "A"
self.client.post('/user/signup/', test_data)
self.assertEqual(User.objects.count(), users)
test_data['first_name'] = "valid first name"
# Test last name boundary values by check if list of users extends
# last_name 0 chars
users = User.objects.count()
test_data['username'] = "A" + str(counter)
counter += 1
test_data['last_name'] = ''
self.client.post('/user/signup/', test_data)
self.assertEqual(User.objects.count(), users)
# last_name 1 chars
users = User.objects.count()
test_data['username'] = "A" + str(counter)
counter += 1
test_data['last_name'] = "A"
self.client.post('/user/signup/', test_data)
self.assertEqual(User.objects.count(), users+1)
# last_name 30 chars
users = User.objects.count()
test_data['username'] = "A" + str(counter)
counter += 1
test_data['last_name'] = chars_30
self.client.post('/user/signup/', test_data)
self.assertEqual(User.objects.count(), users+1)
# last_name 31 chars
users = User.objects.count()
test_data['username'] = "A" + str(counter)
counter += 1
test_data['last_name'] = chars_30 + "A"
self.client.post('/user/signup/', test_data)
self.assertEqual(User.objects.count(), users)
test_data['last_name'] = "valid last name"
# Test categories boundary values by check if list of users extends
# no categories chars
users = User.objects.count()
test_data['username'] = "A" + str(counter)
counter += 1
test_data['categories'] = ''
self.client.post('/user/signup/', test_data)
self.assertEqual(User.objects.count(), users)
# 1 category
users = User.objects.count()
test_data['username'] = "A" + str(counter)
counter += 1
test_data['categories'] = '1'
self.client.post('/user/signup/', test_data)
self.assertEqual(User.objects.count(), users+1)
# multiple categories
users = User.objects.count()
test_data = {
'username': "A" + str(counter),
'first_name': 'max 30', 'first_name': 'max 30',
'last_name': 'max 30', 'last_name': 'max 30',
'categories': '1', 'categories': '1',
'categories': '2', 'categories': '2',
'company': 'max 30', 'company': 'max 30',
'email': 'max254@gmail.com', 'email': 'max254@gmail.com',
'email_confirmation': 'max254@gmail.com', 'email_confirmation': 'max254@gmail.com',
'password1': 'rules123', 'password1': 'veryDifficult123',
'password2': 'rules123', 'password2': 'veryDifficult123',
'phone_number': '501234567', 'phone_number': 'max 50',
'country': 'Norge', 'country': 'max 50',
'state': 'Tadasd', 'state': 'max 50',
'city': 'max', 'city': 'max 50',
'postal_code': '1234', 'postal_code': 'max 50',
'street_address': 'max 30' 'street_address': 'max 50'
}
counter += 1
self.client.post('/user/signup/', test_data)
self.assertEqual(User.objects.count(), users+1)
# Test company boundary values by check if list of users extends
# company 30 chars
users = User.objects.count()
test_data['username'] = "A" + str(counter)
counter += 1
test_data['company'] = chars_30
self.client.post('/user/signup/', test_data)
self.assertEqual(User.objects.count(), users+1)
# company 31 chars
users = User.objects.count()
test_data['username'] = "A" + str(counter)
counter += 1
test_data['company'] = chars_30 + "A"
self.client.post('/user/signup/', test_data)
self.assertEqual(User.objects.count(), users)
test_data['company'] = "valid company"
# Test email boundary values by check if list of users extends
# email 254 chars
users = User.objects.count()
test_data['username'] = "A" + str(counter)
counter += 1
test_data['email'] = email_254chars
self.client.post('/user/signup/', test_data)
self.assertEqual(User.objects.count(), users+1)
# email 255 chars
users = User.objects.count()
test_data['username'] = "A" + str(counter)
counter += 1
test_data['email'] = "A" + email_254chars
self.client.post('/user/signup/', test_data)
self.assertEqual(User.objects.count(), users)
test_data['email'] = "valid@example.com"
# Test password boundary values by check if list of users extends
# password 7 chars
users = User.objects.count()
test_data['username'] = "A" + str(counter)
counter += 1
test_data['password'] = 'invalid'
self.client.post('/user/signup/', test_data)
#self.assertEqual(User.objects.count(), users)
# password 8 chars
users = User.objects.count()
test_data['username'] = "A" + str(counter)
counter += 1
test_data['password'] = "!invalid"
self.client.post('/user/signup/', test_data)
self.assertEqual(User.objects.count(), users+1)
test_data['password'] = "veryDifficult123"
# Test phone_number boundary values by check if list of users extends
# phone_number 0 chars
users = User.objects.count()
test_data['username'] = "A" + str(counter)
counter += 1
test_data['phone_number'] = ''
self.client.post('/user/signup/', test_data)
self.assertEqual(User.objects.count(), users)
# phone_number 1 chars
users = User.objects.count()
test_data['username'] = "A" + str(counter)
counter += 1
test_data['phone_number'] = "A"
self.client.post('/user/signup/', test_data)
self.assertEqual(User.objects.count(), users+1)
# phone_number 30 chars
users = User.objects.count()
test_data['username'] = "A" + str(counter)
counter += 1
test_data['phone_number'] = chars_50
self.client.post('/user/signup/', test_data)
self.assertEqual(User.objects.count(), users+1)
# phone_number 31 chars
users = User.objects.count()
test_data['username'] = "A" + str(counter)
counter += 1
test_data['phone_number'] = chars_50 + "A"
self.client.post('/user/signup/', test_data)
self.assertEqual(User.objects.count(), users)
test_data['phone_number'] = "valid phone nr"
# Test country boundary values by check if list of users extends
# country 0 chars
users = User.objects.count()
test_data['username'] = "A" + str(counter)
counter += 1
test_data['country'] = ''
self.client.post('/user/signup/', test_data)
self.assertEqual(User.objects.count(), users)
# country 1 chars
users = User.objects.count()
test_data['username'] = "A" + str(counter)
counter += 1
test_data['country'] = "A"
self.client.post('/user/signup/', test_data)
self.assertEqual(User.objects.count(), users+1)
# country 30 chars
users = User.objects.count()
test_data['username'] = "A" + str(counter)
counter += 1
test_data['country'] = chars_50
self.client.post('/user/signup/', test_data)
self.assertEqual(User.objects.count(), users+1)
# country 31 chars
users = User.objects.count()
test_data['username'] = "A" + str(counter)
counter += 1
test_data['country'] = chars_50 + "A"
self.client.post('/user/signup/', test_data)
self.assertEqual(User.objects.count(), users)
test_data['country'] = "valid country"
# Test state boundary values by check if list of users extends
# state 0 chars
users = User.objects.count()
test_data['username'] = "A" + str(counter)
counter += 1
test_data['state'] = ''
self.client.post('/user/signup/', test_data)
self.assertEqual(User.objects.count(), users)
# state 1 chars
users = User.objects.count()
test_data['username'] = "A" + str(counter)
counter += 1
test_data['state'] = "A"
self.client.post('/user/signup/', test_data)
self.assertEqual(User.objects.count(), users+1)
# state 30 chars
users = User.objects.count()
test_data['username'] = "A" + str(counter)
counter += 1
test_data['state'] = chars_50
self.client.post('/user/signup/', test_data)
self.assertEqual(User.objects.count(), users+1)
# state 31 chars
users = User.objects.count()
test_data['username'] = "A" + str(counter)
counter += 1
test_data['state'] = chars_50 + "A"
self.client.post('/user/signup/', test_data)
self.assertEqual(User.objects.count(), users)
test_data['state'] = "valid state"
# Test city boundary values by check if list of users extends
# city 0 chars
users = User.objects.count()
test_data['username'] = "A" + str(counter)
counter += 1
test_data['city'] = ''
self.client.post('/user/signup/', test_data)
self.assertEqual(User.objects.count(), users)
# city 1 chars
users = User.objects.count()
test_data['username'] = "A" + str(counter)
counter += 1
test_data['city'] = "A"
self.client.post('/user/signup/', test_data)
self.assertEqual(User.objects.count(), users+1)
# city 30 chars
users = User.objects.count()
test_data['username'] = "A" + str(counter)
counter += 1
test_data['city'] = chars_50
self.client.post('/user/signup/', test_data)
self.assertEqual(User.objects.count(), users+1)
# city 31 chars
users = User.objects.count()
test_data['username'] = "A" + str(counter)
counter += 1
test_data['city'] = chars_50 + "A"
self.client.post('/user/signup/', test_data)
self.assertEqual(User.objects.count(), users)
test_data['city'] = "valid city"
# Test postal_code boundary values by check if list of users extends
# postal_code 0 chars
users = User.objects.count()
test_data['username'] = "A" + str(counter)
counter += 1
test_data['postal_code'] = ''
self.client.post('/user/signup/', test_data)
self.assertEqual(User.objects.count(), users)
# postal_code 1 chars
users = User.objects.count()
test_data['username'] = "A" + str(counter)
counter += 1
test_data['postal_code'] = "A"
self.client.post('/user/signup/', test_data)
self.assertEqual(User.objects.count(), users+1)
# postal_code 30 chars
users = User.objects.count()
test_data['username'] = "A" + str(counter)
counter += 1
test_data['postal_code'] = chars_50
self.client.post('/user/signup/', test_data)
self.assertEqual(User.objects.count(), users+1)
# postal_code 31 chars
users = User.objects.count()
test_data['username'] = "A" + str(counter)
counter += 1
test_data['postal_code'] = chars_50 + "A"
self.client.post('/user/signup/', test_data)
self.assertEqual(User.objects.count(), users)
test_data['postal_code'] = "valid postal code"
# Test street_address boundary values by check if list of users extends
# street_address 0 chars
users = User.objects.count()
test_data['username'] = "A" + str(counter)
counter += 1
test_data['street_address'] = ''
self.client.post('/user/signup/', test_data)
self.assertEqual(User.objects.count(), users)
# street_address 1 chars
users = User.objects.count()
test_data['username'] = "A" + str(counter)
counter += 1
test_data['street_address'] = "A"
self.client.post('/user/signup/', test_data)
self.assertEqual(User.objects.count(), users+1)
# street_address 30 chars
users = User.objects.count()
test_data['username'] = "A" + str(counter)
counter += 1
test_data['street_address'] = chars_50
self.client.post('/user/signup/', test_data)
self.assertEqual(User.objects.count(), users+1)
# street_address 31 chars
users = User.objects.count()
test_data['username'] = "A" + str(counter)
counter += 1
test_data['street_address'] = chars_50 + "A"
self.client.post('/user/signup/', test_data)
self.assertEqual(User.objects.count(), users)
test_data['street_address'] = "valid steet"
# Task 3 - III
class SignUpDomainTest(unittest.TestCase):
def setUp(self):
self.client = Client()
User.objects.all().delete()
self.testCategory = ProjectCategory.objects.create(name='test1')
self.testCategory2 = ProjectCategory.objects.create(name='test2')
self.testCategory3 = ProjectCategory.objects.create(name='test3')
def test_sign_up_page(self):
chars_30 = "NNEcOLJyGWwOaXChNueq2sfYo2BPWO"
chars_50 = "NNEcOLJyGWwOaXueq2sfYo2BPWOyGWwOaXChNueq2sfYo2BPWO"
chars_150 = "kNFRLRGi2KoOtEcOLJyGWwOaXChNueq2bq12qrlS6S0YPkku3JsfYo2BPWOhkNFRLRGi2KoOtEcOLJyGWwOaXChNueq2bq12qrlS6S0YPkku3JsfYo2BPWOhkNFRLRGi2KoOtEcOLJyGWwOaXChNue"
email_254chars = "kNFkjhRLRGi2KoOtEcOLJyGWwOaXChNueq2bq12qrlS6S0YPkku3JsfYo2BPWOhkNFRLRGi2KoOtEcOLJyGWwOaXChNueq2bq12kNFRLRGi2KoOtEcOLJyGWwOaXChNueq2bq12qrlS6S0YPkku3JsfYo2BPWOhkNFRLRGi2KoOtEcOLJyGWwOaXChNueq2bq12qrlS6qrlS6S0YPkku3JsfYo2BPWOhkNFRLRGi2KoOtEcOLJyG@gmail.com"
# Test case 1
users = User.objects.count()
self.client.post('/user/signup/', {
'username': '123',
'first_name': '123',
'last_name': '123',
'categories': '1',
'company': chars_30,
'email': email_254chars,
'email_confirmation': email_254chars,
'password1': 'Valid123',
'password2': 'Valid123',
'phone_number': '123',
'country': '123',
'state': '123',
'city': '123',
'postal_code': '123',
'street_address': '123'
}) })
self.assertEqual(response1.status_code, 302) self.assertEqual(User.objects.count(), 1)
User.objects.all().delete()
response3 = self.client.post('/user/signup/', { # Test case 2
'username': unvalidUsernameLength, users = User.objects.count()
'first_name': 'max 30', self.client.post('/user/signup/', {
'last_name': 'max 30', 'username': chars_150,
'first_name': chars_30,
'last_name': chars_30,
'categories': '2',
'company': '',
'email': email_254chars,
'email_confirmation': email_254chars,
'password1': 'Valid123',
'password2': 'Valid123',
'phone_number': chars_50,
'country': chars_50,
'state': chars_50,