Commit efa8a837 authored by Håvard Farestveit's avatar Håvard Farestveit
Browse files

Changed test_cases in 2-way tests and added some new boundary tests #22

parent c4076310
Pipeline #122019 passed with stages
in 2 minutes and 54 seconds
......@@ -11,7 +11,6 @@ variables = [
'city',
'street_address'
]
values = ['valid', 'invalid', 'blank']
variable_values = {
'valid':
{
......@@ -46,58 +45,59 @@ variable_values = {
}
}
# Test cases generated by https://pairwise.teremokgames.com
test_cases = [
{
"username": "invalid", "password": "blank", "password1": "valid", "email": "invalid", "phone_number": "valid", "country": "blank", "city": "blank", "street_address": "invalid"},{
"username": "invalid", "password": "valid", "password1": "blank", "email": "valid", "phone_number": "blank", "country": "blank", "city": "invalid", "street_address": "valid"},{
"username": "invalid", "password": "valid", "password1": "blank", "email": "blank", "phone_number": "invalid", "country": "valid", "city": "blank", "street_address": "invalid"},{
"username": "invalid", "password": "blank", "password1": "blank", "email": "invalid", "phone_number": "valid", "country": "blank", "city": "invalid", "street_address": "valid"},{
"username": "invalid", "password": "blank", "password1": "valid", "email": "valid", "phone_number": "blank", "country": "invalid", "city": "valid", "street_address": "blank"},{
"username": "valid", "password": "blank", "password1": "blank", "email": "blank", "phone_number": "invalid", "country": "blank", "city": "valid", "street_address": "blank"},{
"username": "valid", "password": "blank", "password1": "blank", "email": "invalid", "phone_number": "blank", "country": "valid", "city": "blank", "street_address": "valid"},{
"username": "valid", "password": "valid", "password1": "valid", "email": "valid", "phone_number": "blank", "country": "valid", "city": "invalid", "street_address": "blank"},{
"username": "blank", "password": "valid", "password1": "blank", "email": "valid", "phone_number": "valid", "country": "invalid", "city": "invalid", "street_address": "blank"},{
"username": "blank", "password": "blank", "password1": "blank", "email": "blank", "phone_number": "blank", "country": "valid", "city": "valid", "street_address": "invalid"},{
"username": "blank", "password": "blank", "password1": "blank", "email": "valid", "phone_number": "invalid", "country": "invalid", "city": "blank", "street_address": "blank"},{
"username": "blank", "password": "blank", "password1": "valid", "email": "blank", "phone_number": "valid", "country": "valid", "city": "invalid", "street_address": "invalid"},{
"username": "blank", "password": "valid", "password1": "blank", "email": "blank", "phone_number": "blank", "country": "blank", "city": "valid", "street_address": "valid"},{
"username": "blank", "password": "blank", "password1": "valid", "email": "invalid", "phone_number": "invalid", "country": "blank", "city": "blank", "street_address": "blank"},{
"username": "invalid", "password": "blank", "password1": "valid", "email": "blank", "phone_number": "invalid", "country": "invalid", "city": "valid", "street_address": "valid"},{
"username": "invalid", "password": "valid", "password1": "valid", "email": "valid", "phone_number": "blank", "country": "blank", "city": "blank", "street_address": "invalid"},{
"username": "invalid", "password": "blank", "password1": "blank", "email": "blank", "phone_number": "blank", "country": "invalid", "city": "invalid", "street_address": "valid"},{
"username": "invalid", "password": "valid", "password1": "blank", "email": "invalid", "phone_number": "invalid", "country": "valid", "city": "valid", "street_address": "blank"},{
"username": "valid", "password": "valid", "password1": "valid", "email": "invalid", "phone_number": "blank", "country": "invalid", "city": "valid", "street_address": "blank"},{
"username": "valid", "password": "blank", "password1": "blank", "email": "valid", "phone_number": "blank", "country": "valid", "city": "blank", "street_address": "invalid"},{
"username": "valid", "password": "blank", "password1": "valid", "email": "blank", "phone_number": "invalid", "country": "blank", "city": "invalid", "street_address": "valid"},{
"username": "valid", "password": "valid", "password1": "blank", "email": "invalid", "phone_number": "valid", "country": "blank", "city": "valid", "street_address": "blank"},{
"username": "valid", "password": "blank", "password1": "blank", "email": "valid", "phone_number": "blank", "country": "invalid", "city": "blank", "street_address": "invalid"},{
"username": "valid", "password": "valid", "password1": "valid", "email": "blank", "phone_number": "invalid", "country": "valid", "city": "blank", "street_address": "valid"},{
"username": "valid", "password": "blank", "password1": "blank", "email": "blank", "phone_number": "valid", "country": "blank", "city": "invalid", "street_address": "blank"},{
"username": "blank", "password": "blank", "password1": "valid", "email": "invalid", "phone_number": "blank", "country": "valid", "city": "invalid", "street_address": "blank"},{
"username": "blank", "password": "blank", "password1": "blank", "email": "valid", "phone_number": "invalid", "country": "blank", "city": "valid", "street_address": "invalid"},{
"username": "blank", "password": "valid", "password1": "blank", "email": "blank", "phone_number": "valid", "country": "invalid", "city": "blank", "street_address": "valid"},{
"username": "blank", "password": "blank", "password1": "valid", "email": "blank", "phone_number": "blank", "country": "valid", "city": "invalid", "street_address": "blank"},{
"username": "blank", "password": "valid", "password1": "blank", "email": "invalid", "phone_number": "blank", "country": "blank", "city": "valid", "street_address": "invalid"},{
"username": "blank", "password": "blank", "password1": "valid", "email": "valid", "phone_number": "invalid", "country": "blank", "city": "blank", "street_address": "valid"},{
"username": "blank", "password": "valid", "password1": "blank", "email": "blank", "phone_number": "valid", "country": "invalid", "city": "blank", "street_address": "blank"}
]
class UserRegistration2WayTestCase(TestCase):
def setUp(self):
print("Running two way user registration")
self.client = Client()
self.testcases = []
default_testcase = {
'username': 'valid',
'password': 'valid',
'password1': 'valid',
'email': 'valid',
'phone_number': 'valid',
'country': 'valid',
'city': 'valid',
'street_address': 'valid'
}
self.testcases.append(default_testcase)
# Iterate over the different values to create a combination of two variables out of all the variables.
for x in range(len(variables)):
for y in range(len(variables) - x):
y = y + x;
if x != y:
variable1 = variables[x]
variable2 = variables[y]
for value1 in values:
# Removes testcases where ther is no invalid input
if value1 == 'invalid' and variable_values["invalid"][variable1] == None:
break
for value2 in values:
# Removes testcases where ther is no invalid input
if value2 == 'invalid' and variable_values["invalid"][variable2] == None:
break
# This testcase is tested by the default case
if (value1 == 'valid' and value2 == 'valid'):
break
new_testcase = default_testcase.copy()
new_testcase[variable1] = value1
new_testcase[variable2] = value2
self.testcases.append(new_testcase)
def test_two_way(self):
for testcase in self.testcases:
for testcase in test_cases:
request = {}
invalid_request = False
for key, value in testcase.items():
request[key] = variable_values[value][key]
if key == 'username' and value == 'valid':
# Add a uid to username so that there is no "user already exists error"
# Add a uid to username to avoid "user already exists error"
request['username'] = request['username'] + str(uuid.uuid4())
if (
......@@ -107,7 +107,6 @@ class UserRegistration2WayTestCase(TestCase):
or (key == 'password1' and value == 'blank')
):
invalid_request = True
response_code = 400 if invalid_request else 201
response = self.client.post('/api/users/', request)
self.assertEqual(response.status_code, response_code)
describe("Register new user", () => {
it("Register with valid user", () => {
it("Register with valid input", () => {
cy.register();
cy.get("#form-register-user").within(($form) => {
cy.get('input[name="username"]').type("testUser" + Date.now());
......@@ -10,7 +10,17 @@ describe("Register new user", () => {
cy.get('input[name="country"]').type("Testonia");
cy.get('input[name="city"]').type("Testheim");
cy.get('input[name="street_address"]').type("Testing street");
cy.get('input[name="username"]').type("testUser");
});
cy.get("#btn-create-account").click();
cy.url().should("include", "/workouts.html");
});
it("Register with only mandetory valid input", () => {
cy.register();
cy.get("#form-register-user").within(($form) => {
cy.get('input[name="username"]').type("testUser" + Date.now());
cy.get('input[name="password"]').type("123456789");
cy.get('input[name="password1"]').type("123456789");
});
cy.get("#btn-create-account").click();
cy.url().should("include", "/workouts.html");
......@@ -22,7 +32,24 @@ describe("Register new user", () => {
cy.get(".alert").contains("Registration failed!");
});
it("Register new user with max lenth username", () => {
it("Register new user with less than max lenth username", () => {
cy.register();
cy.get("#form-register-user").within(($form) => {
let max_length_username = Date.now() + "x".repeat(136);
cy.get('input[name="username"]').type(max_length_username);
cy.get('input[name="email"]').type("test@mail.it");
cy.get('input[name="password"]').type("123456789");
cy.get('input[name="password1"]').type("123456789");
cy.get('input[name="phone_number"]').type("12345678");
cy.get('input[name="country"]').type("Testonia");
cy.get('input[name="city"]').type("Testheim");
cy.get('input[name="street_address"]').type("Testing street");
});
cy.get("#btn-create-account").click();
cy.url().should("include", "/workouts.html");
});
it("Register new user with max length username", () => {
cy.register();
cy.get("#form-register-user").within(($form) => {
let max_length_username = Date.now() + "x".repeat(137);
......@@ -50,7 +77,6 @@ describe("Register new user", () => {
cy.get('input[name="country"]').type("Testonia");
cy.get('input[name="city"]').type("Testheim");
cy.get('input[name="street_address"]').type("Testing street");
cy.get('input[name="username"]').type("testUser");
});
cy.get("#btn-create-account").click();
cy.contains("Registration failed!");
......@@ -74,13 +100,13 @@ describe("Register new user", () => {
it("Testing for no password", () => {
cy.register();
cy.get("#form-register-user").within(($form) => {
cy.get('input[name="username"]').type("testUser");
cy.get('input[name="email"]').type("test@mail.it");
cy.get('input[name="password1"]').type("123456789");
cy.get('input[name="phone_number"]').type("12345678");
cy.get('input[name="country"]').type("Testonia");
cy.get('input[name="city"]').type("Testheim");
cy.get('input[name="street_address"]').type("Testing street");
cy.get('input[name="username"]').type("testUser");
});
cy.get("#btn-create-account").click();
cy.contains("Registration failed!");
......@@ -89,13 +115,13 @@ describe("Register new user", () => {
it("Testing for no password1", () => {
cy.register();
cy.get("#form-register-user").within(($form) => {
cy.get('input[name="username"]').type("testUser");
cy.get('input[name="email"]').type("test@mail.it");
cy.get('input[name="password"]').type("123456789");
cy.get('input[name="phone_number"]').type("12345678");
cy.get('input[name="country"]').type("Testonia");
cy.get('input[name="city"]').type("Testheim");
cy.get('input[name="street_address"]').type("Testing street");
cy.get('input[name="username"]').type("testUser");
});
cy.get("#btn-create-account").click();
cy.contains("Registration failed!");
......@@ -112,12 +138,41 @@ describe("Register new user", () => {
cy.get('input[name="country"]').type("Testonia");
cy.get('input[name="city"]').type("Testheim");
cy.get('input[name="street_address"]').type("Testing street");
cy.get('input[name="username"]').type("testUser");
});
cy.get("#btn-create-account").click();
cy.get(".alert").contains("Registration failed!");
});
it("Valid with one more than min length country", () => {
cy.register();
cy.get("#form-register-user").within(($form) => {
cy.get('input[name="username"]').type("testUser" + Date.now());
cy.get('input[name="email"]').type("test@mail.it");
cy.get('input[name="password"]').type("123456789");
cy.get('input[name="password1"]').type("123456789");
cy.get('input[name="country"]').type("x");
cy.get('input[name="city"]').type("Testheim");
cy.get('input[name="street_address"]').type("Testing street");
});
cy.get("#btn-create-account").click();
cy.url().should("include", "/workouts.html");
});
it("Valid less than max length country", () => {
cy.register();
cy.get("#form-register-user").within(($form) => {
cy.get('input[name="username"]').type("testUser" + Date.now());
cy.get('input[name="email"]').type("test@mail.it");
cy.get('input[name="password"]').type("123456789");
cy.get('input[name="password1"]').type("123456789");
cy.get('input[name="country"]').type("x".repeat(49));
cy.get('input[name="city"]').type("Testheim");
cy.get('input[name="street_address"]').type("Testing street");
});
cy.get("#btn-create-account").click();
cy.url().should("include", "/workouts.html");
});
it("Valid max length country", () => {
cy.register();
cy.get("#form-register-user").within(($form) => {
......@@ -148,7 +203,34 @@ describe("Register new user", () => {
cy.contains("Registration failed!");
});
it("Valid Max lenth street", () => {
it("Valid more than min length of street", () => {
cy.register();
cy.get("#form-register-user").within(($form) => {
cy.get('input[name="username"]').type("testUser" + Date.now());
cy.get('input[name="email"]').type("test@mail.it");
cy.get('input[name="password"]').type("123456789");
cy.get('input[name="password1"]').type("123456789");
cy.get('input[name="street_address"]').type("x");
});
cy.get("#btn-create-account").click();
cy.url().should("include", "/workouts.html");
});
it("Valid less than max length of street", () => {
cy.register();
cy.get("#form-register-user").within(($form) => {
cy.get('input[name="username"]').type("testUser" + Date.now());
cy.get('input[name="email"]').type("test@mail.it");
cy.get('input[name="password"]').type("123456789");
cy.get('input[name="password1"]').type("123456789");
cy.get('input[name="street_address"]').type("x".repeat(49));
});
cy.get("#btn-create-account").click();
cy.url().should("include", "/workouts.html");
});
it("Valid Max length street", () => {
cy.register();
cy.get("#form-register-user").within(($form) => {
cy.get('input[name="username"]').type("testUser" + Date.now());
......@@ -174,17 +256,30 @@ describe("Register new user", () => {
cy.contains("Registration failed!");
});
it("Too long phone number", () => {
it("Valid more than min phone number", () => {
cy.register();
cy.get("#form-register-user").within(($form) => {
cy.get('input[name="username"]').type("testUser" + Date.now());
cy.get('input[name="email"]').type("test@mail.it");
cy.get('input[name="password"]').type("123456789");
cy.get('input[name="password1"]').type("123456789");
cy.get('input[name="street_address"]').type("x".repeat(51));
cy.get('input[name="street_address"]').type("x");
});
cy.get("#btn-create-account").click();
cy.contains("Registration failed!");
cy.url().should("include", "/workouts.html");
});
it("Valid less than max phone number", () => {
cy.register();
cy.get("#form-register-user").within(($form) => {
cy.get('input[name="username"]').type("testUser" + Date.now());
cy.get('input[name="email"]').type("test@mail.it");
cy.get('input[name="password"]').type("123456789");
cy.get('input[name="password1"]').type("123456789");
cy.get('input[name="street_address"]').type("x".repeat(49));
});
cy.get("#btn-create-account").click();
cy.url().should("include", "/workouts.html");
});
it("Valid max length phone number", () => {
......@@ -199,4 +294,17 @@ describe("Register new user", () => {
cy.get("#btn-create-account").click();
cy.url().should("include", "/workouts.html");
});
it("Too long phone number", () => {
cy.register();
cy.get("#form-register-user").within(($form) => {
cy.get('input[name="username"]').type("testUser" + Date.now());
cy.get('input[name="email"]').type("test@mail.it");
cy.get('input[name="password"]').type("123456789");
cy.get('input[name="password1"]').type("123456789");
cy.get('input[name="street_address"]').type("x".repeat(51));
});
cy.get("#btn-create-account").click();
cy.contains("Registration failed!");
});
});
......@@ -38,6 +38,36 @@ describe("Boundary testing for new workouts", () => {
cy.url().should("include", "/workouts.html");
});
it("Valid workout creation with two exercises ", () => {
cy.get("#btn-create-workout").click();
cy.get("#inputName").type("Test Workout");
cy.get("#inputVisibility").select("PU");
cy.get("#inputDateTime").type("2021-03-30T13:00");
cy.get("#inputNotes").type('Test')
const filePath = "./TestFile.txt";
cy.get("#customFile").attachFile(filePath);
cy.scrollTo("bottom");
cy.get("#div-exercises").within(($form) => {
cy.get('select[name="type"]').select("1", { force: true });
cy.get('input[name="sets"]').type("1", { force: true });
cy.get('input[name="number"]').type("1", { force: true });
});
cy.get('#btn-add-exercise').click({force:true})
cy.get(".div-exercise-container").eq(1).within(($form) => {
cy.get('select[name="type"]').select("1", { force: true });
cy.get('input[name="sets"]').type("10", { force: true });
cy.get('input[name="number"]').type("10", { force: true });
});
cy.get("#btn-ok-workout").click();
cy.url().should('include', '/workouts.html');
});
it("Log workout with blank fields", () => {
cy.get("#btn-create-workout").click();
......@@ -65,10 +95,10 @@ describe("Boundary testing for new workouts", () => {
cy.contains('This field may not be blank');
});
it("Log workout with too long name", () => {
it("Log workout with min name", () => {
cy.get("#btn-create-workout").click();
cy.get("#inputName").type("x");
cy.get("#inputName").type("x".repeat(101));
cy.get("#inputDateTime").type("2021-03-30T13:00");
cy.get("#inputVisibility").select("PU");
cy.get("#inputNotes").type("Notes");
......@@ -77,6 +107,23 @@ describe("Boundary testing for new workouts", () => {
cy.get("#customFile").attachFile(filePath);
cy.scrollTo("bottom");
cy.get("#div-exercises").within(($form) => {
cy.get('select[name="type"]').select("1", { force: true });
cy.get('input[name="sets"]').type("1", { force: true });
cy.get('input[name="number"]').type("1", { force: true });
});
cy.get("#btn-ok-workout").click();
cy.url().should("include", "/workouts.html");
});
it("Log workout with too long name", () => {
cy.get("#btn-create-workout").click();
cy.get("#inputName").type("x".repeat(101));
cy.get("#inputDateTime").type("2021-03-30T13:00");
cy.get("#inputVisibility").select("PU");
cy.get("#inputNotes").type("Notes");
cy.scrollTo("bottom");
cy.get("#div-exercises").within(($form) => {
cy.get('select[name="type"]').select("1", { force: true });
cy.get('input[name="sets"]').type("1", { force: true });
......@@ -109,6 +156,112 @@ describe("Boundary testing for new workouts", () => {
cy.url().should("include", "/workouts.html");
});
it("Log workout with less than max length name", () => {
cy.get("#btn-create-workout").click();
cy.get("#inputName").type("x".repeat(99));
cy.get("#inputDateTime").type("2021-03-30T13:00");
cy.get("#inputVisibility").select("PU");
cy.get("#inputNotes").type("Notes");
const filePath = "./TestFile.txt";
cy.get("#customFile").attachFile(filePath);
cy.scrollTo("bottom");
cy.get("#div-exercises").within(($form) => {
cy.get('select[name="type"]').select("1", { force: true });
cy.get('input[name="sets"]').type("1", { force: true });
cy.get('input[name="number"]').type("1", { force: true });
});
cy.get("#btn-ok-workout").click();
cy.url().should("include", "/workouts.html");
});
it("Log workout max date", () => {
cy.get("#btn-create-workout").click();
cy.get("#inputName").type("Test Workout");
cy.get("#inputDateTime").type("9999-12-31T23:59");
cy.get("#inputVisibility").select("PU");
cy.get("#inputNotes").type("Notes");
const filePath = "./TestFile.txt";
cy.get("#customFile").attachFile(filePath);
cy.scrollTo("bottom");
cy.get("#div-exercises").within(($form) => {
cy.get('select[name="type"]').select("1", { force: true });
cy.get('input[name="sets"]').type("1", { force: true });
cy.get('input[name="number"]').type("1", { force: true });
});
cy.get("#btn-ok-workout").click();
cy.url().should("include", "/workouts.html");
});
it("Log workout with less than max date", () => {
cy.get("#btn-create-workout").click();
cy.get("#inputName").type("Test Workout");
cy.get("#inputDateTime").type("9998-11-30T22:59");
cy.get("#inputVisibility").select("PU");
cy.get("#inputNotes").type("Notes");
const filePath = "./TestFile.txt";
cy.get("#customFile").attachFile(filePath);
cy.scrollTo("bottom");
cy.get("#div-exercises").within(($form) => {
cy.get('select[name="type"]').select("1", { force: true });
cy.get('input[name="sets"]').type("1", { force: true });
cy.get('input[name="number"]').type("1", { force: true });
});
cy.get("#btn-ok-workout").click();
cy.url().should("include", "/workouts.html");
});
it("Log workout min date", () => {
cy.get("#btn-create-workout").click();
cy.get("#inputName").type("Test Workout");
cy.get("#inputDateTime").type("0002-01-01T00:00");
cy.get("#inputVisibility").select("PU");
cy.get("#inputNotes").type("Notes");
const filePath = "./TestFile.txt";
cy.get("#customFile").attachFile(filePath);
cy.scrollTo("bottom");
cy.get("#div-exercises").within(($form) => {
cy.get('select[name="type"]').select("1", { force: true });
cy.get('input[name="sets"]').type("1", { force: true });
cy.get('input[name="number"]').type("1", { force: true });
});
cy.get("#btn-ok-workout").click();
cy.url().should("include", "/workouts.html");
});
it("Log workout less than min date", () => {
cy.get("#btn-create-workout").click();
cy.get("#inputName").type("Test Workout");
cy.get("#inputDateTime").type("0001-01-01T00:00");
cy.get("#inputVisibility").select("PU");
cy.get("#inputNotes").type("Notes");
const filePath = "./TestFile.txt";
cy.get("#customFile").attachFile(filePath);
cy.scrollTo("bottom");
cy.get("#div-exercises").within(($form) => {
cy.get('select[name="type"]').select("1", { force: true });
cy.get('input[name="sets"]').type("1", { force: true });
cy.get('input[name="number"]').type("1", { force: true });
});
cy.get("#btn-ok-workout").click();
cy.contains('Datetime has wrong format');
});
it("Log workout with no note", () => {
cy.get("#btn-create-workout").click();
......@@ -131,13 +284,13 @@ describe("Boundary testing for new workouts", () => {
cy.contains('This field may not be blank')
});
it("Valid workout creation with two exercises ", () => {
it("Log workout with min length of note", () => {
cy.get("#btn-create-workout").click();
cy.get("#inputName").type("Test Workout");
cy.get("#inputVisibility").select("PU");
cy.get("#inputDateTime").type("2021-03-30T13:00");
cy.get("#inputNotes").type('Test')
cy.get("#inputVisibility").select("PU");
cy.get("#inputNotes").type(".");
const filePath = "./TestFile.txt";
cy.get("#customFile").attachFile(filePath);
......@@ -149,15 +302,7 @@ describe("Boundary testing for new workouts", () => {
cy.get('input[name="number"]').type("1", { force: true });
});
cy.get('#btn-add-exercise').click({force:true})
cy.get(".div-exercise-container").eq(1).within(($form) => {
cy.get('select[name="type"]').select("1", { force: true });
cy.get('input[name="sets"]').type("10", { force: true });
cy.get('input[name="number"]').type("10", { force: true });
});