mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-02-07 23:49:42 +00:00
Fix PEP8 fails
This commit is contained in:
@@ -6,7 +6,9 @@ from RIGS import models
|
|||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
class UserRegistrationTest(LiveServerTestCase):
|
class UserRegistrationTest(LiveServerTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.browser = webdriver.Firefox()
|
self.browser = webdriver.Firefox()
|
||||||
os.environ['RECAPTCHA_TESTING'] = 'True'
|
os.environ['RECAPTCHA_TESTING'] = 'True'
|
||||||
@@ -18,7 +20,7 @@ class UserRegistrationTest(LiveServerTestCase):
|
|||||||
def test_registration(self):
|
def test_registration(self):
|
||||||
# Navigate to the registration page
|
# Navigate to the registration page
|
||||||
self.browser.get(self.live_server_url + '/user/register/')
|
self.browser.get(self.live_server_url + '/user/register/')
|
||||||
#self.browser.implicitly_wait(3)
|
# self.browser.implicitly_wait(3)
|
||||||
title_text = self.browser.find_element_by_tag_name('h3').text
|
title_text = self.browser.find_element_by_tag_name('h3').text
|
||||||
self.assertIn("User Registration", title_text)
|
self.assertIn("User Registration", title_text)
|
||||||
|
|
||||||
@@ -27,12 +29,14 @@ class UserRegistrationTest(LiveServerTestCase):
|
|||||||
self.assertEqual(username.get_attribute('placeholder'), 'Username')
|
self.assertEqual(username.get_attribute('placeholder'), 'Username')
|
||||||
email = self.browser.find_element_by_id('id_email')
|
email = self.browser.find_element_by_id('id_email')
|
||||||
self.assertEqual(email.get_attribute('placeholder'), 'E-mail')
|
self.assertEqual(email.get_attribute('placeholder'), 'E-mail')
|
||||||
self.assertEqual(email.get_attribute('type'), 'email') # If this is correct we don't need to test it later
|
# If this is correct we don't need to test it later
|
||||||
|
self.assertEqual(email.get_attribute('type'), 'email')
|
||||||
password1 = self.browser.find_element_by_id('id_password1')
|
password1 = self.browser.find_element_by_id('id_password1')
|
||||||
self.assertEqual(password1.get_attribute('placeholder'), 'Password')
|
self.assertEqual(password1.get_attribute('placeholder'), 'Password')
|
||||||
self.assertEqual(password1.get_attribute('type'), 'password')
|
self.assertEqual(password1.get_attribute('type'), 'password')
|
||||||
password2 = self.browser.find_element_by_id('id_password2')
|
password2 = self.browser.find_element_by_id('id_password2')
|
||||||
self.assertEqual(password2.get_attribute('placeholder'), 'Password confirmation')
|
self.assertEqual(
|
||||||
|
password2.get_attribute('placeholder'), 'Password confirmation')
|
||||||
self.assertEqual(password2.get_attribute('type'), 'password')
|
self.assertEqual(password2.get_attribute('type'), 'password')
|
||||||
first_name = self.browser.find_element_by_id('id_first_name')
|
first_name = self.browser.find_element_by_id('id_first_name')
|
||||||
self.assertEqual(first_name.get_attribute('placeholder'), 'First name')
|
self.assertEqual(first_name.get_attribute('placeholder'), 'First name')
|
||||||
@@ -47,12 +51,14 @@ class UserRegistrationTest(LiveServerTestCase):
|
|||||||
username.send_keys('TestUsername')
|
username.send_keys('TestUsername')
|
||||||
email.send_keys('test@example.com')
|
email.send_keys('test@example.com')
|
||||||
password1.send_keys('correcthorsebatterystaple')
|
password1.send_keys('correcthorsebatterystaple')
|
||||||
password2.send_keys('correcthorsebatterystapleerror') # deliberate mistake
|
# deliberate mistake
|
||||||
|
password2.send_keys('correcthorsebatterystapleerror')
|
||||||
first_name.send_keys('John')
|
first_name.send_keys('John')
|
||||||
last_name.send_keys('Smith')
|
last_name.send_keys('Smith')
|
||||||
initials.send_keys('JS')
|
initials.send_keys('JS')
|
||||||
phone.send_keys('0123456789')
|
phone.send_keys('0123456789')
|
||||||
self.browser.execute_script("return jQuery('#g-recaptcha-response').val('PASSED')")
|
self.browser.execute_script(
|
||||||
|
"return jQuery('#g-recaptcha-response').val('PASSED')")
|
||||||
|
|
||||||
# Submit incorrect form
|
# Submit incorrect form
|
||||||
submit = self.browser.find_element_by_xpath("//input[@type='submit']")
|
submit = self.browser.find_element_by_xpath("//input[@type='submit']")
|
||||||
@@ -62,7 +68,8 @@ class UserRegistrationTest(LiveServerTestCase):
|
|||||||
password2 = self.browser.find_element_by_id('id_password2')
|
password2 = self.browser.find_element_by_id('id_password2')
|
||||||
|
|
||||||
# Read what the error is
|
# Read what the error is
|
||||||
alert = self.browser.find_element_by_css_selector('div.alert-danger').text
|
alert = self.browser.find_element_by_css_selector(
|
||||||
|
'div.alert-danger').text
|
||||||
self.assertIn("password fields didn't match", alert)
|
self.assertIn("password fields didn't match", alert)
|
||||||
|
|
||||||
# Passwords should be empty
|
# Passwords should be empty
|
||||||
@@ -72,13 +79,15 @@ class UserRegistrationTest(LiveServerTestCase):
|
|||||||
# Correct error
|
# Correct error
|
||||||
password1.send_keys('correcthorsebatterystaple')
|
password1.send_keys('correcthorsebatterystaple')
|
||||||
password2.send_keys('correcthorsebatterystaple')
|
password2.send_keys('correcthorsebatterystaple')
|
||||||
self.browser.execute_script("return jQuery('#g-recaptcha-response').val('PASSED')")
|
self.browser.execute_script(
|
||||||
|
"return jQuery('#g-recaptcha-response').val('PASSED')")
|
||||||
|
|
||||||
# Submit again
|
# Submit again
|
||||||
password2.send_keys(Keys.ENTER)
|
password2.send_keys(Keys.ENTER)
|
||||||
|
|
||||||
# Check we have a success message
|
# Check we have a success message
|
||||||
alert = self.browser.find_element_by_css_selector('div.alert-success').text
|
alert = self.browser.find_element_by_css_selector(
|
||||||
|
'div.alert-success').text
|
||||||
self.assertIn('register', alert)
|
self.assertIn('register', alert)
|
||||||
self.assertIn('email', alert)
|
self.assertIn('email', alert)
|
||||||
|
|
||||||
@@ -86,7 +95,8 @@ class UserRegistrationTest(LiveServerTestCase):
|
|||||||
self.assertEqual(len(mail.outbox), 1)
|
self.assertEqual(len(mail.outbox), 1)
|
||||||
email = mail.outbox[0]
|
email = mail.outbox[0]
|
||||||
self.assertIn('activation required', email.subject)
|
self.assertIn('activation required', email.subject)
|
||||||
urls = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', email.message)
|
urls = re.findall(
|
||||||
|
'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', email.message)
|
||||||
self.assertEqual(len(urls), 2)
|
self.assertEqual(len(urls), 2)
|
||||||
|
|
||||||
mail.outbox = [] # empty this for later
|
mail.outbox = [] # empty this for later
|
||||||
@@ -109,7 +119,8 @@ class UserRegistrationTest(LiveServerTestCase):
|
|||||||
username.send_keys('TestUsername')
|
username.send_keys('TestUsername')
|
||||||
password.send_keys('correcthorsebatterystaple')
|
password.send_keys('correcthorsebatterystaple')
|
||||||
password.send_keys(Keys.ENTER)
|
password.send_keys(Keys.ENTER)
|
||||||
self.browser.execute_script("return jQuery('#g-recaptcha-response').val('PASSED')")
|
self.browser.execute_script(
|
||||||
|
"return jQuery('#g-recaptcha-response').val('PASSED')")
|
||||||
|
|
||||||
# Check we are logged in
|
# Check we are logged in
|
||||||
udd = self.browser.find_element_by_id('userdropdown')
|
udd = self.browser.find_element_by_id('userdropdown')
|
||||||
@@ -117,9 +128,12 @@ class UserRegistrationTest(LiveServerTestCase):
|
|||||||
|
|
||||||
# All is well
|
# All is well
|
||||||
|
|
||||||
|
|
||||||
class EventTest(LiveServerTestCase):
|
class EventTest(LiveServerTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.profile = models.Profile(username="EventTest", first_name="Event", last_name="Test", initials="ETU", is_superuser=True)
|
self.profile = models.Profile(
|
||||||
|
username="EventTest", first_name="Event", last_name="Test", initials="ETU", is_superuser=True)
|
||||||
self.profile.set_password("EventTestPassword")
|
self.profile.set_password("EventTestPassword")
|
||||||
self.profile.save()
|
self.profile.save()
|
||||||
|
|
||||||
@@ -131,16 +145,19 @@ class EventTest(LiveServerTestCase):
|
|||||||
os.environ['RECAPTCHA_TESTING'] = 'False'
|
os.environ['RECAPTCHA_TESTING'] = 'False'
|
||||||
|
|
||||||
def authenticate(self, n=None):
|
def authenticate(self, n=None):
|
||||||
self.assertIn(self.live_server_url + '/user/login/', self.browser.current_url)
|
self.assertIn(
|
||||||
|
self.live_server_url + '/user/login/', self.browser.current_url)
|
||||||
if n:
|
if n:
|
||||||
self.assertIn('?next=%s'%n, self.browser.current_url)
|
self.assertIn('?next=%s' % n, self.browser.current_url)
|
||||||
username = self.browser.find_element_by_id('id_username')
|
username = self.browser.find_element_by_id('id_username')
|
||||||
password = self.browser.find_element_by_id('id_password')
|
password = self.browser.find_element_by_id('id_password')
|
||||||
submit = self.browser.find_element_by_css_selector('input[type=submit]')
|
submit = self.browser.find_element_by_css_selector(
|
||||||
|
'input[type=submit]')
|
||||||
|
|
||||||
username.send_keys("EventTest")
|
username.send_keys("EventTest")
|
||||||
password.send_keys("EventTestPassword")
|
password.send_keys("EventTestPassword")
|
||||||
self.browser.execute_script("return jQuery('#g-recaptcha-response').val('PASSED')")
|
self.browser.execute_script(
|
||||||
|
"return jQuery('#g-recaptcha-response').val('PASSED')")
|
||||||
submit.click()
|
submit.click()
|
||||||
|
|
||||||
self.assertEqual(self.live_server_url + n, self.browser.current_url)
|
self.assertEqual(self.live_server_url + n, self.browser.current_url)
|
||||||
@@ -154,7 +171,8 @@ class EventTest(LiveServerTestCase):
|
|||||||
# Completes and comes back to rigboard
|
# Completes and comes back to rigboard
|
||||||
# Clicks add new
|
# Clicks add new
|
||||||
self.browser.find_element_by_partial_link_text("New").click()
|
self.browser.find_element_by_partial_link_text("New").click()
|
||||||
self.assertEqual(self.live_server_url + '/event/create/', self.browser.current_url)
|
self.assertEqual(
|
||||||
|
self.live_server_url + '/event/create/', self.browser.current_url)
|
||||||
self.browser.get(self.live_server_url + '/rigboard/')
|
self.browser.get(self.live_server_url + '/rigboard/')
|
||||||
|
|
||||||
def testRigCreate(self):
|
def testRigCreate(self):
|
||||||
@@ -164,7 +182,8 @@ class EventTest(LiveServerTestCase):
|
|||||||
self.authenticate('/event/create/')
|
self.authenticate('/event/create/')
|
||||||
|
|
||||||
# Check has slided up correctly - third save button hidden
|
# Check has slided up correctly - third save button hidden
|
||||||
save = self.browser.find_element_by_xpath('(//button[@type="submit"])[3]')
|
save = self.browser.find_element_by_xpath(
|
||||||
|
'(//button[@type="submit"])[3]')
|
||||||
self.assertFalse(save.is_displayed())
|
self.assertFalse(save.is_displayed())
|
||||||
|
|
||||||
# Click Rig button
|
# Click Rig button
|
||||||
@@ -175,7 +194,8 @@ class EventTest(LiveServerTestCase):
|
|||||||
form = self.browser.find_element_by_tag_name('form')
|
form = self.browser.find_element_by_tag_name('form')
|
||||||
|
|
||||||
# Create new person
|
# Create new person
|
||||||
add_person_button = self.browser.find_element_by_xpath('//a[@data-target="#id_person" and contains(@href, "add")]')
|
add_person_button = self.browser.find_element_by_xpath(
|
||||||
|
'//a[@data-target="#id_person" and contains(@href, "add")]')
|
||||||
add_person_button.click()
|
add_person_button.click()
|
||||||
|
|
||||||
# See modal has opened
|
# See modal has opened
|
||||||
@@ -185,16 +205,20 @@ class EventTest(LiveServerTestCase):
|
|||||||
self.assertIn("Add Person", modal.find_element_by_tag_name('h3').text)
|
self.assertIn("Add Person", modal.find_element_by_tag_name('h3').text)
|
||||||
|
|
||||||
# Fill person form out and submit
|
# Fill person form out and submit
|
||||||
modal.find_element_by_xpath('//div[@id="modal"]//input[@id="id_name"]').send_keys("Test Person 1")
|
modal.find_element_by_xpath(
|
||||||
modal.find_element_by_xpath('//div[@id="modal"]//input[@type="submit"]').click()
|
'//div[@id="modal"]//input[@id="id_name"]').send_keys("Test Person 1")
|
||||||
|
modal.find_element_by_xpath(
|
||||||
|
'//div[@id="modal"]//input[@type="submit"]').click()
|
||||||
self.browser.implicitly_wait(3)
|
self.browser.implicitly_wait(3)
|
||||||
self.assertFalse(modal.is_displayed())
|
self.assertFalse(modal.is_displayed())
|
||||||
|
|
||||||
# See new person selected
|
# See new person selected
|
||||||
person1 = models.Person.objects.get(name="Test Person 1")
|
person1 = models.Person.objects.get(name="Test Person 1")
|
||||||
self.assertEqual(person1.name, form.find_element_by_xpath('//button[@data-id="id_person"]/span').text)
|
self.assertEqual(person1.name, form.find_element_by_xpath(
|
||||||
|
'//button[@data-id="id_person"]/span').text)
|
||||||
# and backend
|
# and backend
|
||||||
option = form.find_element_by_xpath('//select[@id="id_person"]//option[@selected="selected"]')
|
option = form.find_element_by_xpath(
|
||||||
|
'//select[@id="id_person"]//option[@selected="selected"]')
|
||||||
self.assertEqual(person1.pk, int(option.get_attribute("value")))
|
self.assertEqual(person1.pk, int(option.get_attribute("value")))
|
||||||
|
|
||||||
# Change mind and add another
|
# Change mind and add another
|
||||||
@@ -204,33 +228,43 @@ class EventTest(LiveServerTestCase):
|
|||||||
self.assertTrue(modal.is_displayed())
|
self.assertTrue(modal.is_displayed())
|
||||||
self.assertIn("Add Person", modal.find_element_by_tag_name('h3').text)
|
self.assertIn("Add Person", modal.find_element_by_tag_name('h3').text)
|
||||||
|
|
||||||
modal.find_element_by_xpath('//div[@id="modal"]//input[@id="id_name"]').send_keys("Test Person 2")
|
modal.find_element_by_xpath(
|
||||||
modal.find_element_by_xpath('//div[@id="modal"]//input[@type="submit"]').click()
|
'//div[@id="modal"]//input[@id="id_name"]').send_keys("Test Person 2")
|
||||||
|
modal.find_element_by_xpath(
|
||||||
|
'//div[@id="modal"]//input[@type="submit"]').click()
|
||||||
self.browser.implicitly_wait(3)
|
self.browser.implicitly_wait(3)
|
||||||
self.assertFalse(modal.is_displayed())
|
self.assertFalse(modal.is_displayed())
|
||||||
|
|
||||||
person2 = models.Person.objects.get(name="Test Person 2")
|
person2 = models.Person.objects.get(name="Test Person 2")
|
||||||
self.assertEqual(person2.name, form.find_element_by_xpath('//button[@data-id="id_person"]/span').text)
|
self.assertEqual(person2.name, form.find_element_by_xpath(
|
||||||
|
'//button[@data-id="id_person"]/span').text)
|
||||||
# Have to do this explcitly to force the wait for it to update
|
# Have to do this explcitly to force the wait for it to update
|
||||||
option = form.find_element_by_xpath('//select[@id="id_person"]//option[@selected="selected"]')
|
option = form.find_element_by_xpath(
|
||||||
|
'//select[@id="id_person"]//option[@selected="selected"]')
|
||||||
self.assertEqual(person2.pk, int(option.get_attribute("value")))
|
self.assertEqual(person2.pk, int(option.get_attribute("value")))
|
||||||
|
|
||||||
# Was right the first time, change it back
|
# Was right the first time, change it back
|
||||||
person_select = form.find_element_by_xpath('//button[@data-id="id_person"]')
|
person_select = form.find_element_by_xpath(
|
||||||
|
'//button[@data-id="id_person"]')
|
||||||
person_select.send_keys(person1.name)
|
person_select.send_keys(person1.name)
|
||||||
person_dropped = form.find_element_by_xpath('//ul[contains(@class, "inner selectpicker")]//span[contains(text(), "%s")]'%person1.name)
|
person_dropped = form.find_element_by_xpath(
|
||||||
|
'//ul[contains(@class, "inner selectpicker")]//span[contains(text(), "%s")]' % person1.name)
|
||||||
person_dropped.click()
|
person_dropped.click()
|
||||||
|
|
||||||
self.assertEqual(person1.name, form.find_element_by_xpath('//button[@data-id="id_person"]/span').text)
|
self.assertEqual(person1.name, form.find_element_by_xpath(
|
||||||
option = form.find_element_by_xpath('//select[@id="id_person"]//option[@selected="selected"]')
|
'//button[@data-id="id_person"]/span').text)
|
||||||
|
option = form.find_element_by_xpath(
|
||||||
|
'//select[@id="id_person"]//option[@selected="selected"]')
|
||||||
self.assertEqual(person1.pk, int(option.get_attribute("value")))
|
self.assertEqual(person1.pk, int(option.get_attribute("value")))
|
||||||
|
|
||||||
# Edit Person 1 to have a better name
|
# Edit Person 1 to have a better name
|
||||||
form.find_element_by_xpath('//a[@data-target="#id_person" and contains(@href, "%s/edit/")]'%person1.pk).click()
|
form.find_element_by_xpath(
|
||||||
|
'//a[@data-target="#id_person" and contains(@href, "%s/edit/")]' % person1.pk).click()
|
||||||
self.browser.implicitly_wait(3)
|
self.browser.implicitly_wait(3)
|
||||||
self.assertTrue(modal.is_displayed())
|
self.assertTrue(modal.is_displayed())
|
||||||
self.assertIn("Edit Person", modal.find_element_by_tag_name('h3').text)
|
self.assertIn("Edit Person", modal.find_element_by_tag_name('h3').text)
|
||||||
name = modal.find_element_by_xpath('//div[@id="modal"]//input[@id="id_name"]')
|
name = modal.find_element_by_xpath(
|
||||||
|
'//div[@id="modal"]//input[@id="id_name"]')
|
||||||
self.assertEqual(person1.name, name.get_attribute('value'))
|
self.assertEqual(person1.name, name.get_attribute('value'))
|
||||||
name.clear()
|
name.clear()
|
||||||
name.send_keys('Rig ' + person1.name)
|
name.send_keys('Rig ' + person1.name)
|
||||||
@@ -238,7 +272,8 @@ class EventTest(LiveServerTestCase):
|
|||||||
self.browser.implicitly_wait(3)
|
self.browser.implicitly_wait(3)
|
||||||
self.assertFalse(modal.is_displayed())
|
self.assertFalse(modal.is_displayed())
|
||||||
person1 = models.Person.objects.get(pk=person1.pk)
|
person1 = models.Person.objects.get(pk=person1.pk)
|
||||||
self.assertEqual(person1.name, form.find_element_by_xpath('//button[@data-id="id_person"]/span').text)
|
self.assertEqual(person1.name, form.find_element_by_xpath(
|
||||||
|
'//button[@data-id="id_person"]/span').text)
|
||||||
|
|
||||||
# Create organisation
|
# Create organisation
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user