mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-17 05:22:16 +00:00
* Upgrade to heroku-20 stack * Move some gulp deps to dev rather than prod * npm upgrade * Fix audit time check in asset audit test * Attempt at parallelising tests where possible * Add basic calendar button test Mainly to pickup on FullCalendar loading errors * Upgrade python deps * Tends to help if I push valid yaml * You valid now? * Fix whoops in requirements.txt * Change python ver * Define service in coveralls task * Run parallelised RIGS tests as one matrix job * Update python version in tests * Cache python dependencies Should majorly speedup parallelillelelised testing * Purge old vagrant config * No Ruby compass bodge, no need for rubocop! * Purge old .idea config * Switch to gh-a artifact uploading instead of imgur 'hack' For test failure screenshots. Happy now @mattysmith22? ;p * Oops, remove unused import * Exclude tests from the coverage stats Seems to be artifically deflating our stats * Refactor asset audit tests with better selectors Also fixed a silly title error with the modal * Add title checking to the slightly insane assets test * Fix unauth test to not just immediately pass out * Upload failure screenshots as individual artifacts not a zip Turns out I can't unzip things from my phone, which is a pain * Should fix asset test on CI * What about this? * What about this? Swear I spend my life jiggerypokerying the damn test suite... * Does this help the coverage be less weird? * Revert "Does this help the coverage be less weird?" This reverts commit39ab9df836. * Use pytest as our test runner for better parallelism Also rewrote some asset tests to be in the pytest style. May do some more. Some warnings cleaned up in the process. * Bah, codestyle * Oops, remove obsolete if check * Fix screenshot uploading on CI (again) * Try this way of parallel coverage * Add codeclimate maintainability badge * Remove some unused gulp dependencies * Run asset building serverside * Still helps if I commit valid YAML * See below * Different approach to CI dependencies * Exclude node_modules from codestyle * Does this work? * Parallel parallel builds were giving me a headache, try this * Update codeclimate settings, purge some config files * Well the YAML was *syntactically* valid.... * Switch back to old coveralls method * Fix codeclimate config, mark 2 * Attempt to bodge asset test * Oops, again Probably bedtime.. * Might fix heroku building * Attempt #2 at fixing heroku * Belt and braces approach to coverage * Github, you need a Actions YAML validator! * Might fix actions? * Try ignoring some third party deprecation warnings * Another go at making coverage show up * Some template cleanup * Minor python cleanup * Import optimisation * Revert "Minor python cleanup" This reverts commit6a4620a2e5. * Add format arg to coverage command * Ignore test directories from Heroku slug * Maybe this works to purge deps postbuild * Bunch of test refactoring * Restore signals import, screw you import optimisation * Further template refactoring * Add support for running tests with geckodriver, do this on CI * Screw you codestyle * Disable firefox tests for now That was way more errors than I expected * Run cleanup script from the right location * Plausibly fix tests * Helps if I don't delete the pipeline folder prior to collectstatic * Enable whitenoise * Can I delete pipeline here? * Allow seconds difference in assert_times_equal * Disable codeclimate * Remove not working rm command * Maybe this fixes coverage? * Try different coverage reporter * Fix search_help to need login * Made versioning magic a bit less expansive We have more apps than I thought... * Fix IDI0T error in Assets URLS * Refactor 'no access to unauthed' test to cover all of PyRIGS * Add RAs/Checklists to sample data generator * Fix some HTML errors in templates Which apparently only Django's HTML parser cares about, browsers DGAF... * Port title test to project level * Fix more HTML * Fix cable type detail
169 lines
6.9 KiB
Python
169 lines
6.9 KiB
Python
import os
|
|
import re
|
|
|
|
from django.core import mail
|
|
from django.test import LiveServerTestCase
|
|
from selenium.webdriver.common.keys import Keys
|
|
|
|
from PyRIGS.tests.base import create_browser
|
|
from RIGS import models
|
|
|
|
|
|
# Functional Tests
|
|
class UserRegistrationTest(LiveServerTestCase):
|
|
def setUp(self):
|
|
self.browser = create_browser()
|
|
|
|
self.browser.implicitly_wait(3) # Set implicit wait session wide
|
|
os.environ['RECAPTCHA_TESTING'] = 'True'
|
|
|
|
def tearDown(self):
|
|
self.browser.quit()
|
|
os.environ['RECAPTCHA_TESTING'] = 'False'
|
|
|
|
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
|
|
self.assertIn("User Registration", title_text)
|
|
|
|
# Check the form invites correctly
|
|
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')
|
|
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')
|
|
self.assertEqual(password1.get_attribute('placeholder'), 'Password')
|
|
self.assertEqual(password1.get_attribute('type'), 'password')
|
|
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')
|
|
self.assertEqual(first_name.get_attribute('placeholder'), 'First 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')
|
|
self.assertEqual(initials.get_attribute('placeholder'), 'Initials')
|
|
# No longer required for new users
|
|
# phone = self.browser.find_element_by_id('id_phone')
|
|
# self.assertEqual(phone.get_attribute('placeholder'), 'Phone')
|
|
|
|
# Fill the form out incorrectly
|
|
username.send_keys('TestUsername')
|
|
email.send_keys('test@example.com')
|
|
password1.send_keys('correcthorsebatterystaple')
|
|
# deliberate mistake
|
|
password2.send_keys('correcthorsebatterystapleerror')
|
|
first_name.send_keys('John')
|
|
last_name.send_keys('Smith')
|
|
initials.send_keys('JS')
|
|
# phone.send_keys('0123456789')
|
|
self.browser.execute_script(
|
|
"return function() {jQuery('#g-recaptcha-response').val('PASSED'); return 0}()")
|
|
|
|
# Submit incorrect form
|
|
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')
|
|
|
|
# Read what the error is
|
|
alert = self.browser.find_element_by_css_selector(
|
|
'div.alert-danger').text
|
|
# TODO Use regex matching to handle smart/unsmart quotes...
|
|
self.assertIn("password fields didn", alert)
|
|
|
|
# Passwords should be empty
|
|
self.assertEqual(password1.get_attribute('value'), '')
|
|
self.assertEqual(password2.get_attribute('value'), '')
|
|
|
|
# Correct error
|
|
password1.send_keys('correcthorsebatterystaple')
|
|
password2.send_keys('correcthorsebatterystaple')
|
|
self.browser.execute_script("console.log('Hello, world!')")
|
|
self.browser.execute_script(
|
|
"return function() {jQuery('#g-recaptcha-response').val('PASSED'); return 0}()")
|
|
|
|
# Submit again
|
|
password2.send_keys(Keys.ENTER)
|
|
|
|
# Check we have a success message
|
|
alert = self.browser.find_element_by_css_selector(
|
|
'div.alert-success').text
|
|
self.assertIn('register', alert)
|
|
self.assertIn('email', alert)
|
|
|
|
# Check Email
|
|
self.assertEqual(len(mail.outbox), 1)
|
|
email = mail.outbox[0]
|
|
self.assertIn('John Smith "JS" activation required', email.subject)
|
|
urls = re.findall(
|
|
r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', email.body)
|
|
self.assertEqual(len(urls), 1)
|
|
|
|
mail.outbox = [] # empty this for later
|
|
|
|
# Follow link
|
|
self.browser.get(urls[0]) # go to the first link
|
|
|
|
# Complete registration
|
|
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')
|
|
self.assertEqual(username.get_attribute('placeholder'), 'Username')
|
|
password = self.browser.find_element_by_id('id_password')
|
|
self.assertEqual(password.get_attribute('placeholder'), 'Password')
|
|
self.assertEqual(password.get_attribute('type'), 'password')
|
|
|
|
# Expected to fail as not approved
|
|
username.send_keys('TestUsername')
|
|
password.send_keys('correcthorsebatterystaple')
|
|
self.browser.execute_script(
|
|
"return function() {jQuery('#g-recaptcha-response').val('PASSED'); return 0}()")
|
|
password.send_keys(Keys.ENTER)
|
|
|
|
# Test approval
|
|
profileObject = models.Profile.objects.all()[0]
|
|
self.assertFalse(profileObject.is_approved)
|
|
|
|
# Read what the error is
|
|
alert = self.browser.find_element_by_css_selector(
|
|
'div.alert-danger').text
|
|
self.assertIn("approved", alert)
|
|
|
|
# Approve the user so we can proceed
|
|
profileObject.is_approved = True
|
|
profileObject.save()
|
|
|
|
# Retry login
|
|
self.browser.get(self.live_server_url + '/user/login')
|
|
username = self.browser.find_element_by_id('id_username')
|
|
username.send_keys('TestUsername')
|
|
password = self.browser.find_element_by_id('id_password')
|
|
password.send_keys('correcthorsebatterystaple')
|
|
self.browser.execute_script(
|
|
"return function() {jQuery('#g-recaptcha-response').val('PASSED'); return 0}()")
|
|
password.send_keys(Keys.ENTER)
|
|
|
|
# Check we are logged in
|
|
udd = self.browser.find_element_by_class_name('navbar').text
|
|
self.assertIn('Hi John', udd)
|
|
|
|
# Check all the data actually got saved
|
|
self.assertEqual(profileObject.username, 'TestUsername')
|
|
self.assertEqual(profileObject.first_name, 'John')
|
|
self.assertEqual(profileObject.last_name, 'Smith')
|
|
self.assertEqual(profileObject.initials, 'JS')
|
|
# self.assertEqual(profileObject.phone, '0123456789')
|
|
self.assertEqual(profileObject.email, 'test@example.com')
|
|
|
|
# All is well
|