mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-22 16:02:16 +00:00
Add logic needed for captcha checking
This commit is contained in:
@@ -3,19 +3,23 @@ from django.core import mail
|
|||||||
from selenium import webdriver
|
from selenium import webdriver
|
||||||
from selenium.webdriver.common.keys import Keys
|
from selenium.webdriver.common.keys import Keys
|
||||||
import re
|
import re
|
||||||
|
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'
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.browser.quit()
|
self.browser.quit()
|
||||||
|
os.environ['RECAPTCHA_TESTING'] = 'False'
|
||||||
|
|
||||||
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)
|
||||||
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", tilte_text)
|
||||||
|
|
||||||
# Check the form invites correctly
|
# Check the form invites correctly
|
||||||
username = self.browser.find_element_by_id('id_username')
|
username = self.browser.find_element_by_id('id_username')
|
||||||
@@ -37,6 +41,7 @@ class UserRegistrationTest(LiveServerTestCase):
|
|||||||
self.assertEqual(initials.get_attribute('placeholder'), 'Initials')
|
self.assertEqual(initials.get_attribute('placeholder'), 'Initials')
|
||||||
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')
|
self.assertEqual(phone.get_attribute('placeholder'), 'Phone')
|
||||||
|
captcha = self.browser.find_element_by_id('g-recaptcha-response')
|
||||||
|
|
||||||
# Fill the form out incorrectly
|
# Fill the form out incorrectly
|
||||||
username.send_keys('TestUsername')
|
username.send_keys('TestUsername')
|
||||||
@@ -47,6 +52,7 @@ class UserRegistrationTest(LiveServerTestCase):
|
|||||||
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')
|
||||||
|
captcha.send_keys('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']")
|
||||||
@@ -54,6 +60,7 @@ class UserRegistrationTest(LiveServerTestCase):
|
|||||||
# Restablish error fields
|
# Restablish error fields
|
||||||
password1 = self.browser.find_element_by_id('id_password1')
|
password1 = self.browser.find_element_by_id('id_password1')
|
||||||
password2 = self.browser.find_element_by_id('id_password2')
|
password2 = self.browser.find_element_by_id('id_password2')
|
||||||
|
captcha = self.browser.find_element_by_id('g-recaptcha-response')
|
||||||
|
|
||||||
# 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
|
||||||
@@ -66,6 +73,7 @@ class UserRegistrationTest(LiveServerTestCase):
|
|||||||
# Correct error
|
# Correct error
|
||||||
password1.send_keys('correcthorsebatterystaple')
|
password1.send_keys('correcthorsebatterystaple')
|
||||||
password2.send_keys('correcthorsebatterystaple')
|
password2.send_keys('correcthorsebatterystaple')
|
||||||
|
captcha.send_keys('PASSED')
|
||||||
|
|
||||||
# Submit again
|
# Submit again
|
||||||
password2.send_keys(Keys.ENTER)
|
password2.send_keys(Keys.ENTER)
|
||||||
@@ -98,10 +106,12 @@ class UserRegistrationTest(LiveServerTestCase):
|
|||||||
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('placeholder'), 'Password')
|
||||||
self.assertEqual(password.get_attribute('type'), 'password')
|
self.assertEqual(password.get_attribute('type'), 'password')
|
||||||
|
captcha = self.browser.find_element_by_id('g-recaptcha-response')
|
||||||
|
|
||||||
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)
|
||||||
|
captcha.send_keys('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')
|
||||||
|
|||||||
Reference in New Issue
Block a user