Unverified Commit ba48d0e4 authored by KristofferHaakonsen's avatar KristofferHaakonsen
Browse files

add 2-way testing

parent 3f59ba60
Pipeline #115563 passed with stage
in 1 minute and 34 seconds
from django.contrib.auth import get_user_model, password_validation
from django.test import TestCase
from users.serializers import UserSerializer
from rest_framework.test import APIRequestFactory, APITestCase
from rest_framework.test import APIRequestFactory, APITestCase, APIClient
from rest_framework.request import Request
from random import choice
from string import ascii_uppercase
......@@ -678,44 +678,76 @@ class Street_AdressBoundaryTestCase(TestCase):
'''
twoWayDomainData = [
[("", False), ("johnDoe", True), ("johnDoe7653", True), ("23165484", True), ("John!#¤%&/<>|§()=?`^*_:;", False) ],
[("", False), ("kkkk", False), ("johnDoe@webmail.com", True), ("johnDoe@web#%¤&/&.com", False)],
[("", False), ("short", False), ("passwordpassword", True), ("123346)(%y#(%¨>l<][475", True)],
[("", False), ("1234", False), ("1122334455", True), ("phonenumber", False), ("=?`^*_:;,.-'¨\+@£$", False)],
[("", False), ("Chad", True), ("Norway1", False), ("=?`^*_:;,.-'¨\+@£$", False)],
[("", False), ("Oslo", True), ("Oslo1", False), ("Oslo=?`^*_:;,.-'¨\+@£$", False)],
[("", False), ("Strandveien", True), ("Strandveien1", True), ("Kongens gate", True), ("Oslo=?`^*_:;,.-'¨\+@£$", False)]]
[("username", "", False), ("username", "johny", True), ("username", "johnDoe7653", True), ("username", "23165484", True), ("username", "John!#¤%&/<>|§()=?`^*_:;", False) ],
[("email", "", False), ("email", "kkkk", False), ("email", "johnDoe@webmail.com", True), ("email", "johnDoe@web#%¤&/&.com", False)],
[("password", "", False), ("password","short", False), ("password","passwordpassword", True), ("password","123346)(%y#(%¨>l<][475", True)],
[("phone_number","", False), ("phone_number","1234", False), ("phone_number","1122334455", True), ("phone_number","phonenumber", False), ("phone_number","=?`^*_:;,.-'¨\+@£$", False)],
[("country","", False), ("country", "Chad", True), ("country", "Norway1", False), ("country", "=?`^*_:;,.-'¨\+@£$", False)],
[("city","", False), ("city", "Oslo", True), ("city", "Oslo1", False), ("city", "Oslo=?`^*_:;,.-'¨\+@£$", False)],
[("street_adress","", False), ("street_adress", "Strandveien", True), ("street_adress", "Strandveien1", True), ("street_adress", "Kongens gate", True), ("street_adress", "Oslo=?`^*_:;,.-'¨\+@£$", False)]]
class two_way_domain_test(TestCase):
def setUp(self):
# Adds some randomness
self.failedCounter = 0
self.testsRunned = 0
self.failures_400 = []
self.failures_201 = []
self.client = APIClient()
def check(self, value1, value2):
# Iterate
self.testsRunned += 1
global counter
defaultDataRegister["username"]= "johnDoe" + str(counter)
counter += 1
def check(self, value1, value2):
#Todo: This method will check the input
print("todo")
# Set data
self.defaultDataRegister = {
"username": "johnDoe"+str(counter), "email": "johnDoe@webserver.com", "password": "johnsPassword", "password1": "johnsPassword", "phone_number": "11223344", "country": "Norway", "city": "Trondheim", "street_address": "Kongens gate 33"}
self.defaultDataRegister[value1[0]] = value1[1]
self.defaultDataRegister[value2[0]] = value2[1]
# Make sure that password == password1, we do not check for this
if value1[0] == "password":
self.defaultDataRegister["password1"] = value1[1]
elif value2[0] == "password":
self.defaultDataRegister["password1"] = value2[1]
# Get result
response = self.client.post("/api/users/", self.defaultDataRegister)
# If the result should be 201
if value1[2] and value2[2]:
if response.status_code != status.HTTP_201_CREATED:
self.failures_201.append({"type1": value1[0], "value1":value1[1], "type2":value2[0], "value2":value2[1]})
self.failedCounter +=1
# If the result should be 400
else:
if response.status_code != status.HTTP_400_BAD_REQUEST:
self.failures_400.append({"type1": value1[0], "value1":value1[1], "type2":value2[0], "value2":value2[1]})
self.failedCounter +=1
# Delete the created user to prevent errors when we test the same value of username several times
if response.status_code == status.HTTP_201_CREATED:
# Authenticate so we can delete
self.client.force_authenticate(user=User.objects.get(id = response.data['id']))
response2 = self.client.delete('/api/users/'+str(response.data['id'])+'/')
def test_two_way_domain(self):
defaultDataRegister["street_adress"]=""
response = self.client.post("/api/users/", defaultDataRegister)
print("\n")
# For each element, try all other elements once
for y1 in range(0, len(twoWayDomainData)):
for x1 in range(0, len(twoWayDomainData[y1])):
print("y1,x1: {}, {} = {}".format(y1, x1, twoWayDomainData[y1][x1]))
for y2 in range(y1+1, len(twoWayDomainData)):
for x2 in range(0, len(twoWayDomainData[y2])):
print("y2,x2: {}, {} = {}".format(y2, x2, twoWayDomainData[y2][x2]))
# Add check method
# Store result and return when y1 goes to next
# Print/return some data
self.check(twoWayDomainData[y1][x1], twoWayDomainData[y2][x2])
# Print results
print("\n-------------------------------------------------------------------------------------------------------------------------------")
print("2-Way Domain Testing:\nTotal combinations (tests): {}\nTotal failed combinations (tests): {}".format(self.testsRunned, self.failedCounter))
print("{} combinations should work but didn't\n{} combinations should NOT work but did".format(len(self.failures_201), len(self.failures_400)))
print("The combinations that should have worked: {}\nThe combinations that should not have worked: {}".format(self.failures_201, self.failures_400))
print("-------------------------------------------------------------------------------------------------------------------------------")
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