Unverified Commit 532f14f6 authored by Johannes Tomren Røsvik's avatar Johannes Tomren Røsvik
Browse files

Separated tests for each field

parent 241c3f8b
Pipeline #77053 passed with stage
in 1 minute and 16 seconds
......@@ -28,40 +28,146 @@ class AgreelanceSignUp(unittest.TestCase):
else:
self.driver = webdriver.Chrome("./bin/chromedriver")
def test_nominal(self):
driver = self.driver
values = self.getNominalValues()
def test_username(self):
testcases = [
["username", "", False], # min-
["username", self.rString(1), True], # min
["username", self.rString(150), True], # max
["username", self.rString(151), False], # max+
]
formstate = self.fill_form(values)
self.assertTrue(self.case_tester(testcases))
def test_firstname(self):
testcases = [
["firstname", "", False], # min-
["firstname", self.rString(1), True], # min
["firstname", self.rString(30), True], # max
["firstname", self.rString(31), False], # max+
]
self.assertTrue(formstate)
self.assertTrue(self.case_tester(testcases))
def test_empty(self):
driver = self.driver
def test_lastname(self):
testcases = [
["lastname", "", False], # min-
["lastname", self.rString(1), True], # min
["lastname", self.rString(30), True], # max
["lastname", self.rString(31), False], # max+
]
self.assertTrue(self.case_tester(testcases))
def test_categories(self):
testcases = [
["username", "", False],
["firstname", "", False],
["lastname", "", False],
["company", "", True],
["email", "", False],
["email_confirmation", "", False],
["password", "", False],
["password_confirmation", "", False],
["phone_number", "", False],
["country", "", False],
["state", "", False],
["city", "", False],
["postal_code", "", False],
["street_address", "", False],
["categories", None, False], # min-
]
self.assertTrue(self.case_tester(testcases))
def test_company(self):
testcases = [
["company", "", True], # min
["company", "30", True], # max
["company", "30", False], # max+
]
self.assertTrue(self.case_tester(testcases))
def test_email(self):
email_6 = self.rString(1) + "@" + self.rString(1) + ".co"
email_254 = self.rString(248) + "@" + self.rString(1) + ".com"
email_255 = self.rString(248) + "@" + self.rString(2) + ".com"
testcases = [
["email", "", False], # min-
["email", email_6, True], # min
["email", email_254, True], # max
["email", email_255, False], # max+
]
self.assertTrue(self.case_tester(testcases))
def test_phone_number(self):
testcases = [
["phone_number", "", False], # min-
["phone_number", self.rDigits(1), True], # min
["phone_number", self.rDigits(50), True], # max
["phone_number", self.rDigits(51), False], # max+
]
self.assertTrue(self.case_tester(testcases))
def test_country(self):
testcases = [
["country", "", False], # min-
["country", self.rString(1), True], # min
["country", self.rString(50), True], # max
["country", self.rString(51), False], # max+
]
self.assertTrue(self.case_tester(testcases))
def test_state(self):
testcases = [
["state", "", False], # min-
["state", self.rString(1), True], # min
["state", self.rString(50), True], # max
["state", self.rString(51), False], # max+
]
self.assertTrue(self.case_tester(testcases))
def test_city(self):
testcases = [
["city", "", False], # min-
["city", self.rString(1), True], # min
["city", self.rString(50), True], # max
["city", self.rString(51), False], # max+
]
self.assertTrue(self.case_tester(testcases))
def test_postal_code(self):
testcases = [
["postal_code", "", False], # min-
["postal_code", self.rDigits(1), True], # min
["postal_code", self.rDigits(50), True], # max
["postal_code", self.rDigits(51), False], # max+
]
self.assertTrue(self.case_tester(testcases))
def test_street_address(self):
testcases = [
["street_address", "", False], # min-
["street_address", self.rString(1), True], # min
["street_address", self.rString(50), True], # max
["street_address", self.rString(51), False], # max+
]
self.assertTrue(self.case_tester(testcases))
def case_tester(self, testcases):
driver = self.driver
for case in testcases:
values = self.getNominalValues()
values[case[0]] = case[1]
# print(values)
formstate = self.fill_form(values)
self.assertTrue(formstate == case[2])
if formstate != case[2]:
print(values)
return False
return True
def fill_form(self, values):
driver = self.driver
......@@ -89,12 +195,13 @@ class AgreelanceSignUp(unittest.TestCase):
username.send_keys(values["username"])
firstname.send_keys(values["firstname"])
lastname.send_keys(values["lastname"])
categories.select_by_index(values["categories"])
if values["categories"] != None:
categories.select_by_index(values["categories"])
company.send_keys(values["company"])
email.send_keys(values["email"])
email_confirmation.send_keys(values["email_confirmation"])
email_confirmation.send_keys(values["email"])
password.send_keys(values["password"])
password_confirmation.send_keys(values["password_confirmation"])
password_confirmation.send_keys(values["password"])
phone_number.send_keys(values["phone_number"])
country.send_keys(values["country"])
state.send_keys(values["state"])
......@@ -111,30 +218,30 @@ class AgreelanceSignUp(unittest.TestCase):
alert = driver.find_element_by_class_name("alert")
return "Your account has been created" in alert.text
except TimeoutException:
print("Timed out waiting for page to load")
# Timed out
return False
def getNominalValues(self):
email_ = self.rString(10) + "@" + self.rString(10) + ".com"
password_ = self.rString(30)
password_ = self.rString(20)
values = {
"username": self.rString(30),
"firstname": self.rString(30),
"lastname": self.rString(30),
"username": self.rString(20),
"firstname": self.rString(20),
"lastname": self.rString(20),
"categories": 0,
"company": self.rString(30),
"company": self.rString(20),
"email": email_,
"email_confirmation": email_,
"password": password_,
"password_confirmation": password_,
"phone_number": self.rDigits(8),
"country": self.rString(30),
"state": self.rString(30),
"city": self.rString(30),
"country": self.rString(20),
"state": self.rString(20),
"city": self.rString(20),
"postal_code": self.rDigits(4),
"street_address": self.rString(30)
"street_address": self.rString(20)
}
return values
......
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