Commit c459efad authored by Ian Evangelista's avatar Ian Evangelista
Browse files

black box tests complete

parent 08942564
Pipeline #167089 passed with stages
This source diff could not be displayed because it is too large. You can view the blob instead.
# Python program to demonstrate
# selenium
import time
import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import string
import random
import requests
import itertools
test_data = [
["ian@norge.no", "Norge", "Klæbuveien", "Oslo", "12345678"],
["ian@norge.no", "Sverige", "Klæbuveien", "Oslo", "12345678"],
["niko@norge.no", "Norge", "Klæbuveien", "Oslo", "12345678"],
["niko@norge.no", "Sverige", "Klæbuveien", "Oslo", "12345678"],
["ian@norge.no", "Norge", "Prinsens Gate", "Oslo", "12345678"],
["niko@norge.no", "Norge", "Prinsens Gate", "Oslo", "12345678"],
["ian@norge.no", "Norge", "Prinsens Gate", "Trondheim", "12345678"],
["niko@norge.no", "Norge", "Prinsens Gate", "Trondheim", "12345678"],
["ian@norge.no", "Norge", "Prinsens Gate", "Trondheim", "98765432"],
["niko@norge.no", "Norge", "Prinsens Gate", "Trondheim", "98765432"],
["ian@norge.no", "Sverige", "Prinsens Gate", "Oslo", "98765432"],
["ian@norge.no", "Sverige", "Klæbuveien", "Trondheim", "98765432"]
]
inputs = ["username", "email", "password", "password1", "phone_number", "country", "city", "street_address"]
def create_username():
return ''.join(random.choice(string.ascii_letters) for i in range(10))
def create_input(length):
return ''.join(random.choice(string.ascii_letters) for i in range(length))
password = create_input(8)
class RegisterTwoWayUnitTesting(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.url = "http://localhost:5500/frontend/www/register.html"
self.driver.get(self.url)
self.driver.maximize_window()
def test_two_way_domain(self):
for data in test_data:
password = create_input(7)
self.driver.find_element_by_name("username").clear()
self.driver.find_element_by_name("username").send_keys(create_username())
self.driver.find_element_by_name("email").clear()
self.driver.find_element_by_name("email").send_keys(data[0])
self.driver.find_element_by_name("password").clear()
self.driver.find_element_by_name("password").send_keys(password)
self.driver.find_element_by_name("password1").clear()
self.driver.find_element_by_name("password1").send_keys(password)
data =[
[password, ""],
["Norge", ""],
["Klæbuveien", ""],
["Oslo", ""],
["12345678", ""],
]
self.driver.find_element_by_name("country").clear()
self.driver.find_element_by_name("country").send_keys(data[1])
domain =[
[create_username(), create_input(151), ""],
["ian@ian.no", create_input(8), ""],
]
self.driver.find_element_by_name("street_address").clear()
self.driver.find_element_by_name("street_address").send_keys(data[2])
test_data = list(itertools.product(*data))
self.driver.find_element_by_name("city").clear()
self.driver.find_element_by_name("city").send_keys(data[3])
domain_data = list(itertools.product(*domain))
self.driver.find_element_by_name("phone_number").clear()
self.driver.find_element_by_name("phone_number").send_keys(data[4])
class RegisterTwoWayUnitTesting(unittest.TestCase):
def setUp(self):
self.counter = 0
self.driver.find_element_by_id("btn-create-account").click()
time.sleep(5)
if self.driver.current_url != self.url:
assert self.driver.current_url != self.url
break
def test_two_way_domain(self):
for d_data in domain_data:
for t_data in test_data:
response = requests.post("http://127.0.0.1:8000/api/users/", {'username': d_data[0].join(random.choice(string.ascii_letters) for i in range(5)), 'email': d_data[1], 'password': t_data[0], 'password1': t_data[0], 'country': t_data[1], 'street_address': t_data[2], 'city': t_data[3], 'phone_number': t_data[4]})
if response.status_code == 201:
self.counter += 1
print('Combination number', self.counter, ':', 'username:', d_data[0], 'email:', d_data[1], 'password:', t_data[0], 'country:', t_data[1], 'street address:', t_data[2], 'city:', t_data[3], 'phone number:', t_data[4])
assert(self.counter > 0)
# cleanup method called after every test performed
def tearDown(self):
self.driver.close()
print("Test completed")
if __name__ == "__main__":
unittest.main()
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