Commit b5df6720 authored by Tobias Ingebrigt Ørstad's avatar Tobias Ingebrigt Ørstad
Browse files

Merge branch 'dev' into 'master'

Dev

See merge request !20
parents fa34cea8 3a8cc217
Pipeline #114263 passed with stages
in 2 minutes and 49 seconds
......@@ -11,6 +11,12 @@ from rest_framework import serializers
from rest_framework.exceptions import ValidationError
from django.contrib.auth import get_user_model, password_validation
from unittest import skip
from users.models import User
from datetime import datetime
# -------------------------------------------------------------------------------------------------
# Boundary value tests
# -------------------------------------------------------------------------------------------------
class RegisterUsernameBoundaryTestCase(TestCase):
......@@ -30,6 +36,7 @@ class RegisterUsernameBoundaryTestCase(TestCase):
self.request["username"] = "bob"
request = self.client.post('http://testserver/api/users/', json.dumps(self.request), content_type='application/json')
self.request["email"] = "bob2@bob.no"
self.request["phone_number"] = "12345677"
request2 = self.client.post('http://testserver/api/users/', json.dumps(self.request), content_type='application/json')
self.assertEquals(request2.status_code,400)
......@@ -438,3 +445,285 @@ class UserSerializerTestCase(TestCase):
def tearDown(self):
return super().tearDown()
# -------------------------------------------------------------------------------------------------
# 2 Way domain tests
# -------------------------------------------------------------------------------------------------
class Register2WayDomainTestCase(TestCase):
#Start by defining datatypes for each value of the inputs we want to test
#All arrays consists of data on the format [value to be tested, should this input be valid]
#If the value to be tested is itself an array it means that input should be tested twice, and the status be collected from the second post
#The exception is the password array, which uses both entries of the array as input to password and password1 in one post
def setUp(self):
self.request = json.loads('{"username": "bob1","password": "Heihei1","password1": "Heihei1","athletes": [],"email": "bob@bob.no","coach_files": [],"athlete_files": [],"workouts":[],"phone_number": "12345678","country": "","city": "","street_address":""}')
self.request1 = json.loads('{"username": "bob2","password": "Heihei1","password1": "Heihei1","athletes": [],"email": "bob1@bob.no","coach_files": [],"athlete_files": [],"workouts":[],"phone_number": "12345679","country": "","city": "","street_address":""}')
self.client = APIClient()
User.objects.create(id="1",username="Bill",password="secret")
self.user_1 = User.objects.get(id="1")
self.client.force_authenticate(user=self.user_1)
self.usernames = [["bob",True],["<<<", False],[["bob","bob"], False], ["", False]]
self.emails = [["bob@bob.no",True], ["bob",False], [["bob2@bob.no","bob2@bob.no"],False], ["",False]]
self.password = [[["Bobobo12", "Bobobo12"],True], [["bob","bob"],False], [["Bobobo12","Bobobo11"],False],[["",""],False]]
self.number = [["123",False],["12345678",True],[["12345678","12345678"],False]]
self.country = [["Norway",True],["Norway10",False],["",True]]
self.city = [["Hei",True],["",True]]
self.street_address = [["hei",True],["",True]]
#Method for cleaning up users by deleting
def delete_user(self, id):
try:
user = User.objects.get(id=id)
self.client.force_authenticate(user=user)
response = self.client.delete('http://testserver/api/users/'+str(id)+'/')
except:
pass
#Method for posting users, takes up to 2 fields and values. optional parameter for deleting the user
def postUser(self,field,value,number,field1=None, value1=None, delete=True):
request = [self.request.copy(),self.request1.copy()][number]
if(field=='password'):
request['password'] = value[0]
request['password1'] = value[1]
else:
request[field] = value
if(field1!=None):
if(field1=='password'):
request['password'] = value1[0]
request['password1'] = value1[1]
else:
request[field1] = value1
request = self.client.post('http://testserver/api/users/', json.dumps(request), content_type='application/json')
if request.status_code == 201 and delete:
self.delete_user(request.data['id'])
return request.status_code, request.data
#Method for making sure the correct amount of posts is sent based on the values
#Checks if values are strings or arrays and calls post accordingly
def get_status_for_posts(self,field1,value1,field2,value2):
status_code = ""
code = 0
postdata = ""
if(isinstance(value1, list) and isinstance(value2,list)):
code, postdata = self.postUser(field1,value1[0],0,field2,value2[0], delete = False)
status_code, data = self.postUser(field1,value1[1],1,field2,value2[1])
elif(isinstance(value1, list) and isinstance(value2, str)):
code, postdata = self.postUser(field1,value1[0],0, delete = False)
status_code, data = self.postUser(field1,value1[1],1,field2,value2)
elif(isinstance(value1, str) and isinstance(value2, list)):
code, postdata = self.postUser(field2,value2[0],0, delete = False)
status_code, data = self.postUser(field1,value1,1,field2,value2[1])
else:
status_code, data = self.postUser(field1,value1,0,field2,value2)
if code == 201:
self.delete_user(postdata['id'])
return status_code
#Special version of method above for passwords, as they work differently, mentioned in setup.
def get_status_for_posts_password(self,passwordlist,field1,value1):
status_code = ""
code = 0
postdata = ""
if(isinstance(value1, list)):
code, postdata = self.postUser(field1,value1[0],0, delete = False)
status_code, data = self.postUser('password',passwordlist,1,field1,value1[1])
else:
status_code, data = self.postUser('password',passwordlist,0,field1,value1)
if code == 201:
self.delete_user(postdata['id'])
return status_code
#testing all usernames, a lot of this should be extracted to its own function, but because of time constrains code had to copied
#We have to catch the asserts because if not the method would not run to completion. Instead we collect all assertionErrors in a
#list which we print at the end. All methods below follow same format.
def test_usernames(self):
failures = []
field1 = 'username'
for username in self.usernames:
value1 = username[0]
for email in self.emails:
field2 = 'email'
value2 = email[0]
expectedstatus = username[1] and email[1]
status = self.get_status_for_posts(field1,value1,field2,value2)
try: self.assertEquals((status == 201),expectedstatus)
except AssertionError: failures.append({field1:value1,field2:value2})
for password in self.password:
field2 = 'password'
value2 = password[0]
expectedstatus = username[1] and password[1]
status = self.get_status_for_posts_password(password[0],field1,username[0])
try: self.assertEquals((status == 201),expectedstatus)
except AssertionError: failures.append({field1:value1,field2:value2})
for number in self.number:
field2 = 'phone_number'
value2 = number[0]
expectedstatus = username[1] and number[1]
status = self.get_status_for_posts(field1,value1,field2,value2)
try: self.assertEquals((status == 201),expectedstatus)
except AssertionError: failures.append({field1:value1,field2:value2})
for country in self.country:
field2 = 'country'
value2 = country[0]
expectedstatus = username[1] and country[1]
status = self.get_status_for_posts(field1,value1,field2,value2)
try: self.assertEquals((status == 201),expectedstatus)
except AssertionError: failures.append({field1:value1,field2:value2})
for city in self.city:
field2 = 'city'
value2 = city[0]
expectedstatus = username[1] and city[1]
status = self.get_status_for_posts(field1,value1,field2,value2)
try: self.assertEquals((status == 201),expectedstatus)
except AssertionError: failures.append({field1:value1,field2:value2})
for street_address in self.street_address:
field2 = 'street_address'
value2 = street_address[0]
expectedstatus = username[1] and street_address[1]
status = self.get_status_for_posts(field1,value1,field2,value2)
try: self.assertEquals((status == 201),expectedstatus)
except AssertionError: failures.append({field1:value1,field2:value2})
print(failures)
def test_emails(self):
failures = []
field1 = 'email'
for email in self.emails:
value1 = email[0]
for password in self.password:
field2 = 'password'
value2 = password[0]
expectedstatus = email[1] and password[1]
status = self.get_status_for_posts_password(password[0],field1,email[0])
try: self.assertEquals((status == 201),expectedstatus)
except AssertionError: failures.append({field1:value1,field2:value2})
for number in self.number:
field2 = 'phone_number'
value2 = number[0]
expectedstatus = email[1] and number[1]
status = self.get_status_for_posts(field1,value1,field2,value2)
try: self.assertEquals((status == 201),expectedstatus)
except AssertionError: failures.append({field1:value1,field2:value2})
for country in self.country:
field2 = 'country'
value2 = country[0]
expectedstatus = email[1] and country[1]
status = self.get_status_for_posts(field1,value1,field2,value2)
try: self.assertEquals((status == 201),expectedstatus)
except AssertionError: failures.append({field1:value1,field2:value2})
for city in self.city:
field2 = 'city'
value2 = city[0]
expectedstatus = email[1] and city[1]
status = self.get_status_for_posts(field1,value1,field2,value2)
try: self.assertEquals((status == 201),expectedstatus)
except AssertionError: failures.append({field1:value1,field2:value2})
for street_address in self.street_address:
field2 = 'street_address'
value2 = street_address[0]
expectedstatus = email[1] and street_address[1]
status = self.get_status_for_posts(field1,value1,field2,value2)
try: self.assertEquals((status == 201),expectedstatus)
except AssertionError: failures.append({field1:value1,field2:value2})
print(failures)
def test_passwords(self):
failures = []
field1 = 'password'
for password in self.password:
value1 = password[0]
for number in self.number:
field2 = 'phone_number'
value2 = number[0]
expectedstatus = password[1] and number[1]
status = self.get_status_for_posts_password(value1,field2,value2)
try: self.assertEquals((status == 201),expectedstatus)
except AssertionError: failures.append({field1:value1,field2:value2})
for country in self.country:
field2 = 'country'
value2 = country[0]
expectedstatus = password[1] and country[1]
status = self.get_status_for_posts_password(value1,field2,value2)
try: self.assertEquals((status == 201),expectedstatus)
except AssertionError: failures.append({field1:value1,field2:value2})
for city in self.city:
field2 = 'city'
value2 = city[0]
expectedstatus = password[1] and city[1]
status = self.get_status_for_posts_password(value1,field2,value2)
try: self.assertEquals((status == 201),expectedstatus)
except AssertionError: failures.append({field1:value1,field2:value2})
for street_address in self.street_address:
field2 = 'street_address'
value2 = street_address[0]
expectedstatus = password[1] and street_address[1]
status = self.get_status_for_posts_password(value1,field2,value2)
try: self.assertEquals((status == 201),expectedstatus)
except AssertionError: failures.append({field1:value1,field2:value2})
print(failures)
def test_numbers(self):
failures = []
field1 = 'phone_number'
for number in self.number:
value1 = number[0]
for country in self.country:
field2 = 'country'
value2 = country[0]
expectedstatus = number[1] and country[1]
status = self.get_status_for_posts(field1,value1,field2,value2)
try: self.assertEquals((status == 201),expectedstatus)
except AssertionError: failures.append({field1:value1,field2:value2})
for city in self.city:
field2 = 'city'
value2 = city[0]
expectedstatus = number[1] and city[1]
status = self.get_status_for_posts(field1,value1,field2,value2)
try: self.assertEquals((status == 201),expectedstatus)
except AssertionError: failures.append({field1:value1,field2:value2})
for street_address in self.street_address:
field2 = 'street_address'
value2 = street_address[0]
expectedstatus = number[1] and street_address[1]
status = self.get_status_for_posts(field1,value1,field2,value2)
try: self.assertEquals((status == 201),expectedstatus)
except AssertionError: failures.append({field1:value1,field2:value2})
print(failures)
def test_countries(self):
failures = []
field1 = 'country'
for country in self.country:
value1 = country[0]
for city in self.city:
field2 = 'city'
value2 = city[0]
expectedstatus = country[1] and city[1]
status = self.get_status_for_posts(field1,value1,field2,value2)
try: self.assertEquals((status == 201),expectedstatus)
except AssertionError: failures.append({field1:value1,field2:value2})
for street_address in self.street_address:
field2 = 'street_address'
value2 = street_address[0]
expectedstatus = country[1] and street_address[1]
status = self.get_status_for_posts(field1,value1,field2,value2)
try: self.assertEquals((status == 201),expectedstatus)
except AssertionError: failures.append({field1:value1,field2:value2})
print(failures)
def test_city(self):
failures = []
field1 = 'city'
for city in self.city:
value1 = city[0]
for street_address in self.street_address:
field2 = 'street_address'
value2 = street_address[0]
expectedstatus = city[1] and street_address[1]
status = self.get_status_for_posts(field1,value1,field2,value2)
try: self.assertEquals((status == 201),expectedstatus)
except AssertionError: failures.append({field1:value1,field2:value2})
print(failures)
......@@ -17,7 +17,7 @@ from datetime import datetime
# Before running this test, remember to host the application on http://localhost:9090 using docker-compose up --build
# in the main project folder
# Test is run by: python seleniumLikeIntegrationTest.py (when in the workouts-folder)
# Test is run by: python seleniumFR5Test.py (when in the workouts-folder)
class AccessWorkoutTestCase(unittest.TestCase):
# Creates two unique usernames to be used in the tests;
......@@ -68,7 +68,7 @@ class AccessWorkoutTestCase(unittest.TestCase):
phoneNumberField.send_keys("12312312")
countryField.send_keys("Norway")
cityField.send_keys("Molde")
streetAddressField.send_keys("Oslo_suger")
streetAddressField.send_keys("Hovedgata")
# Finds and clicks the button that creates the account
createAccountButton = driver.find_element_by_id("btn-create-account")
......@@ -94,7 +94,7 @@ class AccessWorkoutTestCase(unittest.TestCase):
# Inputs values into fields
workoutNameField.send_keys("TestWorkout")
workoutDateField.clear()
workoutDateField.send_keys("2020-01-01 12:00")
workoutDateField.send_keys("1111-01-01 00:01")
workoutNotesField.send_keys("This is an auto-generated workout meant for testing")
workoutVisibilityField.send_keys("PR")
......@@ -163,7 +163,7 @@ class AccessWorkoutTestCase(unittest.TestCase):
phoneNumberField.send_keys("12312312")
countryField.send_keys("Norway")
cityField.send_keys("Molde")
streetAddressField.send_keys("Oslo_suger")
streetAddressField.send_keys("Hovedgata")
# Finds and clicks the button that creates the account
createAccountButton = driver.find_element_by_id("btn-create-account")
......@@ -189,7 +189,7 @@ class AccessWorkoutTestCase(unittest.TestCase):
# Inputs values into fields
workoutNameField.send_keys("TestWorkout")
workoutDateField.clear()
workoutDateField.send_keys("2020-01-01 12:00")
workoutDateField.send_keys("1111-01-01 00:01")
workoutNotesField.send_keys("This is an auto-generated public workout meant for testing")
workoutVisibilityField.send_keys("PU")
......@@ -234,7 +234,7 @@ class AccessWorkoutTestCase(unittest.TestCase):
phoneNumberField.send_keys("12312312")
countryField.send_keys("Norway")
cityField.send_keys("Oslo")
streetAddressField.send_keys("Molde_suger")
streetAddressField.send_keys("Sideveien")
# Finds and clicks the button that creates the account
createAccountButton = driver.find_element_by_id("btn-create-account")
......@@ -264,7 +264,7 @@ class AccessWorkoutTestCase(unittest.TestCase):
# 1. Athlete registers himself
# 2. Athlete logs out
# 3. Coach registers himself
# 4. Coach sendes coaching request to athlete
# 4. Coach sends coaching request to athlete
# 5. Coach logs out
# 6. Athlete logs in
# 7. Athlete accepts the coaching request from the coach
......@@ -304,7 +304,7 @@ class AccessWorkoutTestCase(unittest.TestCase):
phoneNumberField.send_keys("12312312")
countryField.send_keys("Norway")
cityField.send_keys("Molde")
streetAddressField.send_keys("Oslo_suger")
streetAddressField.send_keys("Hovedgata")
# Finds and clicks the button that creates the account
createAccountButton = driver.find_element_by_id("btn-create-account")
......@@ -344,7 +344,7 @@ class AccessWorkoutTestCase(unittest.TestCase):
phoneNumberField.send_keys("12312312")
countryField.send_keys("Norway")
cityField.send_keys("Molde")
streetAddressField.send_keys("Oslo_suger")
streetAddressField.send_keys("Hovedgata")
# Finds and clicks the button that creates the account
createAccountButton = driver.find_element_by_id("btn-create-account")
......@@ -429,7 +429,7 @@ class AccessWorkoutTestCase(unittest.TestCase):
# Inputs values into fields
workoutNameField.send_keys("TestWorkout")
workoutDateField.clear()
workoutDateField.send_keys("2020-01-01 12:00")
workoutDateField.send_keys("1111-01-01 00:01")
workoutNotesField.send_keys("This is an auto-generated coach workout meant for testing")
workoutVisibilityField.send_keys("CO")
......@@ -466,6 +466,8 @@ class AccessWorkoutTestCase(unittest.TestCase):
time.sleep(0.5)
# --- 11 ---
self.scroll_down()
# Finds and clicks the new workout
workoutElement = driver.find_elements_by_css_selector("a.list-group-item")[-1]
workoutElement.click()
......@@ -476,7 +478,7 @@ class AccessWorkoutTestCase(unittest.TestCase):
workoutOwner = workoutOwnerField.get_attribute("value")
#Tests that the owner name of the newly created workout matches the athletes name
self.assertEqual(workoutOwner,athlete_uniqueUsername)
self.assertEqual(workoutOwner, athlete_uniqueUsername)
#Tests if all the page elements (workout details, files, and comments) are available on the page
self.assertTrue(self.check_workout_page_elements_exists())
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment