Unverified Commit 973475f9 authored by Johannes Tomren Røsvik's avatar Johannes Tomren Røsvik
Browse files

Add basic signup test

parent 51e82323
Pipeline #76859 canceled with stage
# This test will only pass if the site and secret keys are set to
# RECAPTCHA_SITE_KEY = 6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI
# RECAPTCHA_SECRET_KEY = 6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe
# in agreelance/settings.py. See recaptcha docs for more information:
# https://developers.google.com/recaptcha/docs/faq
import unittest
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import time
import os
import random
import string
from time import sleep
url = "http://127.0.0.1:8000/user/signup"
class AgreelanceSignUp(unittest.TestCase):
def setUp(self):
if os.name == "nt":
self.driver = webdriver.Chrome("./bin/chromedriver.exe")
else:
self.driver = webdriver.Chrome("./bin/chromedriver")
# Input random valid info in form
def test_fill_form_valid(self):
driver = self.driver
driver.get(url)
username = driver.find_element_by_id("id_username")
firstname = driver.find_element_by_id("id_first_name")
lastname = driver.find_element_by_id("id_last_name")
categories = Select(driver.find_element_by_id("id_categories"))
company = driver.find_element_by_id("id_company")
email = driver.find_element_by_id("id_email")
email_confirmation = driver.find_element_by_id("id_email_confirmation")
password = driver.find_element_by_id("id_password1")
password_confirmation = driver.find_element_by_id("id_password2")
phone_number = driver.find_element_by_id("id_phone_number")
country = driver.find_element_by_id("id_country")
state = driver.find_element_by_id("id_state")
city = driver.find_element_by_id("id_city")
postal_code = driver.find_element_by_id("id_postal_code")
street_address = driver.find_element_by_id("id_street_address")
recaptcha = driver.find_element_by_class_name("g-recaptcha")
submit = driver.find_element_by_xpath("/html/body/div[1]/form/button")
username.send_keys(self.rString(30))
firstname.send_keys(self.rString(30))
lastname.send_keys(self.rString(30))
categories.select_by_index(0)
company.send_keys(self.rString(30))
email_ = self.rString(10) + "@" + self.rString(10) + ".com"
email.send_keys(email_)
email_confirmation.send_keys(email_)
password_ = self.rString(30)
password.send_keys(password_)
password_confirmation.send_keys(password_)
phone_number.send_keys(self.rDigits(8))
country.send_keys(self.rString(30))
state.send_keys(self.rString(30))
city.send_keys(self.rString(30))
postal_code.send_keys(self.rDigits(4))
street_address.send_keys(self.rString(30))
recaptcha.click()
submit.click()
timeout = 5
try:
element_present = EC.presence_of_element_located((By.CLASS_NAME, 'alert'))
WebDriverWait(driver, timeout).until(element_present)
except TimeoutException:
print("Timed out waiting for page to load")
alert = driver.find_element_by_class_name("alert")
self.assertTrue("Your account has been created and is awaiting verification" in alert.text)
def tearDown(self):
self.driver.close()
@staticmethod
def rString(length):
return ''.join(random.choices(string.ascii_lowercase, k=length))
@staticmethod
def rDigits(length):
return ''.join(random.choices(string.digits, k=length))
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