Merge branch 'master' into checkin

This commit is contained in:
2023-05-14 22:14:04 +01:00
8 changed files with 958 additions and 1072 deletions

View File

@@ -6,6 +6,7 @@ from django.core import mail
from django.test import LiveServerTestCase
from django.test.utils import override_settings
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from PyRIGS.tests.base import create_browser
from RIGS import models
@@ -24,31 +25,31 @@ class UserRegistrationTest(LiveServerTestCase):
def test_registration(self):
# Navigate to the registration page
self.browser.get(self.live_server_url + '/user/register/')
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)
# Check the form invites correctly
username = self.browser.find_element_by_id('id_username')
username = self.browser.find_element(By.ID, 'id_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')
# 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('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('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')
last_name = self.browser.find_element_by_id('id_last_name')
last_name = self.browser.find_element(By.ID, 'id_last_name')
self.assertEqual(last_name.get_attribute('placeholder'), 'Last name')
initials = self.browser.find_element_by_id('id_initials')
initials = self.browser.find_element(By.ID, 'id_initials')
self.assertEqual(initials.get_attribute('placeholder'), 'Initials')
# No longer required for new users
# phone = self.browser.find_element_by_id('id_phone')
# phone = self.browser.find_element(By.ID, 'id_phone')
# self.assertEqual(phone.get_attribute('placeholder'), 'Phone')
# Fill the form out incorrectly
@@ -62,21 +63,20 @@ class UserRegistrationTest(LiveServerTestCase):
initials.send_keys('JS')
# phone.send_keys('0123456789')
time.sleep(1)
self.browser.switch_to.frame(self.browser.find_element_by_tag_name("iframe"))
self.browser.find_element_by_id('anchor').click()
self.browser.switch_to.frame(self.browser.find_element(By.TAG_NAME, "iframe"))
self.browser.find_element(By.ID, 'anchor').click()
self.browser.switch_to.default_content()
time.sleep(3)
# Submit incorrect form
submit = self.browser.find_element_by_xpath("//input[@type='submit']")
submit = self.browser.find_element(By.XPATH, "//input[@type='submit']")
submit.click()
# Restablish error fields
password1 = self.browser.find_element_by_id('id_password1')
password2 = self.browser.find_element_by_id('id_password2')
password1 = self.browser.find_element(By.ID, 'id_password1')
password2 = self.browser.find_element(By.ID, 'id_password2')
# 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, '.alert-danger').text
# TODO Use regex matching to handle smart/unsmart quotes...
self.assertIn("password fields didn", alert)
@@ -92,8 +92,7 @@ class UserRegistrationTest(LiveServerTestCase):
password2.send_keys(Keys.ENTER)
# 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, '.alert-success').text
self.assertIn('register', alert)
self.assertIn('email', alert)
@@ -111,14 +110,14 @@ class UserRegistrationTest(LiveServerTestCase):
self.browser.get(urls[0]) # go to the first link
# Complete registration
title_text = self.browser.find_element_by_tag_name('h2').text
title_text = self.browser.find_element(By.TAG_NAME, 'h2').text
self.assertIn('Complete', title_text)
# Test login
self.browser.get(self.live_server_url + '/user/login')
username = self.browser.find_element_by_id('id_username')
username = self.browser.find_element(By.ID, 'id_username')
self.assertEqual(username.get_attribute('placeholder'), 'Username')
password = self.browser.find_element_by_id('id_password')
password = self.browser.find_element(By.ID, 'id_password')
self.assertEqual(password.get_attribute('placeholder'), 'Password')
self.assertEqual(password.get_attribute('type'), 'password')
@@ -132,8 +131,7 @@ class UserRegistrationTest(LiveServerTestCase):
self.assertFalse(profileObject.is_approved)
# 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("approved", alert)
# Approve the user so we can proceed
@@ -142,14 +140,14 @@ class UserRegistrationTest(LiveServerTestCase):
# Retry login
self.browser.get(self.live_server_url + '/user/login')
username = self.browser.find_element_by_id('id_username')
username = self.browser.find_element(By.ID, 'id_username')
username.send_keys('TestUsername')
password = self.browser.find_element_by_id('id_password')
password = self.browser.find_element(By.ID, 'id_password')
password.send_keys('correcthorsebatterystaple')
password.send_keys(Keys.ENTER)
# Check we are logged in
udd = self.browser.find_element_by_class_name('navbar').text
udd = self.browser.find_element(By.CLASS_NAME, 'navbar').text
self.assertIn('Hi John', udd)
# Check all the data actually got saved