UPD: improved tests.
This commit is contained in:
@@ -36,7 +36,7 @@ class TestCase(ScreenshotTestCase):
|
||||
link = c.find_element_by_css_selector('#login-widget a')
|
||||
link.click()
|
||||
self.wait_on_presence(c, (By.ID, 'id_username'))
|
||||
self.save_screenshot(sequence=sequence_name)
|
||||
self.save_screenshot('empty_login_form', sequence=sequence_name)
|
||||
|
||||
# Fill in a password -> Save dots in password field
|
||||
username_field = c.find_element_by_id('id_username')
|
||||
@@ -45,7 +45,7 @@ class TestCase(ScreenshotTestCase):
|
||||
password_field = c.find_element_by_id('id_password')
|
||||
password_field.clear()
|
||||
password_field.send_keys(self.test_password)
|
||||
self.save_screenshot(sequence=sequence_name)
|
||||
self.save_screenshot('filled_login_form', sequence=sequence_name)
|
||||
|
||||
# Wrong username -> save error message
|
||||
username_field = c.find_element_by_id('id_username')
|
||||
@@ -56,7 +56,7 @@ class TestCase(ScreenshotTestCase):
|
||||
password_field.send_keys(self.test_password)
|
||||
password_field.send_keys(Keys.RETURN)
|
||||
alert_button = self.wait_on_presence(c, (By.CSS_SELECTOR, 'form .alert-danger button.close'))
|
||||
self.save_screenshot(sequence=sequence_name)
|
||||
self.save_screenshot('error_wrong_username', sequence=sequence_name)
|
||||
alert_button.click()
|
||||
|
||||
# Wrong password -> save error message
|
||||
@@ -68,7 +68,7 @@ class TestCase(ScreenshotTestCase):
|
||||
password_field.send_keys(self.test_password[::-1])
|
||||
password_field.send_keys(Keys.RETURN)
|
||||
alert_button = self.wait_on_presence(c, (By.CSS_SELECTOR, 'form .alert-danger button.close'))
|
||||
self.save_screenshot(sequence=sequence_name)
|
||||
self.save_screenshot('error_wrong_password', sequence=sequence_name)
|
||||
alert_button.click()
|
||||
|
||||
# Login of inactive user -> save error message
|
||||
@@ -82,7 +82,7 @@ class TestCase(ScreenshotTestCase):
|
||||
password_field.send_keys(self.test_password)
|
||||
password_field.send_keys(Keys.RETURN)
|
||||
alert_button = self.wait_on_presence(c, (By.CSS_SELECTOR, 'form .alert-danger button.close'))
|
||||
self.save_screenshot(sequence=sequence_name)
|
||||
self.save_screenshot('error_inactive_user', sequence=sequence_name)
|
||||
alert_button.click()
|
||||
# Reactivate test user again
|
||||
self.user.is_active = True
|
||||
@@ -97,40 +97,39 @@ class TestCase(ScreenshotTestCase):
|
||||
password_field.send_keys(self.test_password)
|
||||
password_field.send_keys(Keys.RETURN)
|
||||
alert_button = self.wait_on_presence(c, (By.CSS_SELECTOR, '#messages .alert-success button.close'))
|
||||
self.save_screenshot(sequence=sequence_name)
|
||||
self.save_screenshot('login_succeed', sequence=sequence_name)
|
||||
alert_button.click()
|
||||
|
||||
# Open user dropdown menu -> save menu
|
||||
dropdown_button = self.wait_on_presence(c, (By.ID, 'user_dropdown_button'))
|
||||
dropdown_button.click()
|
||||
self.save_screenshot(sequence=sequence_name)
|
||||
self.save_screenshot('user_menu', sequence=sequence_name)
|
||||
|
||||
# Click on 'set password' -> save set password page
|
||||
user_menu = c.find_element_by_css_selector('#login-widget ul')
|
||||
link = user_menu.find_element_by_partial_link_text(ugettext(u'Passwort ändern'))
|
||||
link.click()
|
||||
self.wait_on_presence(c, (By.ID, 'id_new_password'))
|
||||
self.save_screenshot(sequence=sequence_name)
|
||||
password_field = self.wait_on_presence(c, (By.ID, 'id_new_password'))
|
||||
self.save_screenshot('empty_set_password_form', sequence=sequence_name)
|
||||
|
||||
# Fill in a password -> Save dots in password field
|
||||
password_field = c.find_element_by_id('id_new_password')
|
||||
send_mail_field = c.find_element_by_id('id_send_password_mail')
|
||||
send_mail_field.click()
|
||||
password_field.clear()
|
||||
password_field.send_keys(self.test_password)
|
||||
password2_field = c.find_element_by_id('id_new_password_repeat')
|
||||
password2_field.clear()
|
||||
password2_field.send_keys(self.test_password)
|
||||
self.save_screenshot(sequence=sequence_name)
|
||||
self.save_screenshot('filled_set_password_form', sequence=sequence_name)
|
||||
|
||||
# New passwords mismatch -> save error message
|
||||
password_field = c.find_element_by_id('id_new_password')
|
||||
password_field.clear()
|
||||
password_field.send_keys(self.test_password)
|
||||
password2_field = c.find_element_by_id('id_new_password_repeat')
|
||||
password2_field.clear()
|
||||
password2_field.send_keys(self.test_password[::-1])
|
||||
password2_field.send_keys(Keys.RETURN)
|
||||
self.wait_until_stale(c, password2_field)
|
||||
self.save_screenshot(sequence=sequence_name)
|
||||
self.save_screenshot('error_mismatch', sequence=sequence_name)
|
||||
|
||||
# New passwords too common and too short -> save error message
|
||||
password = 'abcdef'
|
||||
@@ -142,7 +141,7 @@ class TestCase(ScreenshotTestCase):
|
||||
password2_field.send_keys(password)
|
||||
password2_field.send_keys(Keys.RETURN)
|
||||
self.wait_until_stale(c, password2_field)
|
||||
self.save_screenshot(sequence=sequence_name)
|
||||
self.save_screenshot('errors_too_common_too_short', sequence=sequence_name)
|
||||
|
||||
# New passwords entirely_numeric -> save error message
|
||||
password = '9126735804'
|
||||
@@ -154,7 +153,7 @@ class TestCase(ScreenshotTestCase):
|
||||
password2_field.send_keys(password)
|
||||
password2_field.send_keys(Keys.RETURN)
|
||||
self.wait_until_stale(c, password2_field)
|
||||
self.save_screenshot(sequence=sequence_name)
|
||||
self.save_screenshot('error_numeric', sequence=sequence_name)
|
||||
|
||||
# New passwords too similar -> save error message
|
||||
password = self.test_username
|
||||
@@ -166,7 +165,7 @@ class TestCase(ScreenshotTestCase):
|
||||
password2_field.send_keys(password)
|
||||
password2_field.send_keys(Keys.RETURN)
|
||||
self.wait_until_stale(c, password2_field)
|
||||
self.save_screenshot(sequence=sequence_name)
|
||||
self.save_screenshot('error_too_similar', sequence=sequence_name)
|
||||
|
||||
# Change password -> save success message
|
||||
password = self.test_password[::-1]
|
||||
@@ -178,7 +177,15 @@ class TestCase(ScreenshotTestCase):
|
||||
password2_field.send_keys(password)
|
||||
password2_field.send_keys(Keys.RETURN)
|
||||
self.wait_until_stale(c, password2_field)
|
||||
self.save_screenshot(sequence=sequence_name)
|
||||
self.save_screenshot('set_password_succeed', sequence=sequence_name)
|
||||
|
||||
# Get password reset page -> since we are logged in, it should
|
||||
# redirect to set password page again -> save
|
||||
html = c.find_element_by_tag_name('html')
|
||||
c.get(self.complete_url(reverse('dav_auth:reset_password')))
|
||||
self.wait_until_stale(c, html)
|
||||
self.wait_on_presence(c, (By.ID, 'id_new_password'))
|
||||
self.save_screenshot('empty_set_password_form', sequence=sequence_name)
|
||||
|
||||
# Click on 'logout' -> save page
|
||||
dropdown_button = self.wait_on_presence(c, (By.ID, 'user_dropdown_button'))
|
||||
@@ -187,4 +194,32 @@ class TestCase(ScreenshotTestCase):
|
||||
link = user_menu.find_element_by_partial_link_text(ugettext(u'Logout'))
|
||||
link.click()
|
||||
self.wait_until_stale(c, user_menu)
|
||||
self.save_screenshot(sequence=sequence_name)
|
||||
self.save_screenshot('logout_succeed', sequence=sequence_name)
|
||||
|
||||
# Click on 'login' to access password reset link
|
||||
link = c.find_element_by_css_selector('#login-widget a')
|
||||
link.click()
|
||||
self.wait_on_presence(c, (By.ID, 'id_username'))
|
||||
|
||||
# Locate password reset link, click it -> save password reset form
|
||||
link = c.find_element_by_partial_link_text(ugettext(u'Passwort vergessen'))
|
||||
link.click()
|
||||
username_field = self.wait_on_presence(c, (By.ID, 'id_username'))
|
||||
self.save_screenshot('empty_reset_password_form', sequence=sequence_name)
|
||||
|
||||
# Enter invalid username -> save result (login form, no message)
|
||||
username_field.send_keys(self.test_username[::-1])
|
||||
username_field.send_keys(Keys.RETURN)
|
||||
self.wait_until_stale(c, username_field)
|
||||
self.save_screenshot('reset_password_invalid_user', sequence=sequence_name)
|
||||
|
||||
# Locate password reset link, click it
|
||||
link = c.find_element_by_partial_link_text(ugettext(u'Passwort vergessen'))
|
||||
link.click()
|
||||
username_field = self.wait_on_presence(c, (By.ID, 'id_username'))
|
||||
|
||||
# Enter valid username -> save result (login page, success message)
|
||||
username_field.send_keys(self.test_username)
|
||||
username_field.send_keys(Keys.RETURN)
|
||||
self.wait_until_stale(c, username_field)
|
||||
self.save_screenshot('reset_password_valid_user', sequence=sequence_name)
|
||||
|
||||
@@ -179,7 +179,7 @@ class ViewsTestCase(TestCase):
|
||||
self.assertFalse(self.client.login(username=username, password=password), 'Old password still valid')
|
||||
self.assertTrue(self.client.login(username=username, password=new_password), 'New password not valid')
|
||||
|
||||
def test_reset_password_integrated_get(self):
|
||||
def test_reset_password_integrated_unauth_get(self):
|
||||
response = self.client.get(self.reset_password_url)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertTemplateUsed(response, 'dav_auth/forms/reset_password.html')
|
||||
@@ -189,6 +189,11 @@ class ViewsTestCase(TestCase):
|
||||
field = response.context['form'].fields['username']
|
||||
self.assertTrue(field.required)
|
||||
|
||||
def test_reset_password_integrated_auth_get(self):
|
||||
self.client.login(username=self.test_username, password=self.test_password)
|
||||
response = self.client.get(self.reset_password_url)
|
||||
self.assertRedirects(response, self.set_password_url)
|
||||
|
||||
def test_reset_password_integrated_post(self):
|
||||
location = self.reset_password_url
|
||||
|
||||
|
||||
@@ -2,8 +2,9 @@ import logging
|
||||
from django.apps import apps
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth import views as auth_views, get_user_model
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import resolve_url
|
||||
from django.urls import reverse_lazy
|
||||
from django.urls import reverse_lazy, reverse
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.views import generic
|
||||
|
||||
@@ -80,3 +81,8 @@ class ResetPasswordView(generic.FormView):
|
||||
logger.warning('Password reset for unknown user \'%s\'', username)
|
||||
|
||||
return super(ResetPasswordView, self).form_valid(form)
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
if request.user.is_authenticated:
|
||||
return HttpResponseRedirect(reverse('dav_auth:set_password'))
|
||||
return super(ResetPasswordView, self).get(request, *args, **kwargs)
|
||||
|
||||
@@ -172,42 +172,44 @@ class ScreenshotTestCase(SeleniumTestCase):
|
||||
self.selenium.set_window_size(self.window_width, self.window_height)
|
||||
|
||||
def sanitize_filename(self, location):
|
||||
location = location.lstrip('/')
|
||||
if location == '':
|
||||
return 'root'
|
||||
r = urllib.quote(location, '')
|
||||
return r
|
||||
return urllib.quote(location).replace('/', '--')
|
||||
|
||||
def save_screenshot(self, name=None, sequence=None):
|
||||
if name is not None:
|
||||
pass
|
||||
elif sequence is not None:
|
||||
def save_screenshot(self, title=None, sequence=None):
|
||||
if sequence is None:
|
||||
sequence = ''
|
||||
else:
|
||||
if sequence in self.screenshot_sequences:
|
||||
self.screenshot_sequences[sequence] += 1
|
||||
else:
|
||||
self.screenshot_sequences[sequence] = 1
|
||||
n = self.screenshot_sequences[sequence]
|
||||
name = '%s-%04d' % (sequence, n)
|
||||
else:
|
||||
sequence = u'%s-%04d-' % (sequence, n)
|
||||
if title is None:
|
||||
location = self.selenium.current_url
|
||||
if location.startswith(self.live_server_url):
|
||||
location = location[len(self.live_server_url):]
|
||||
name = location
|
||||
location = location.lstrip('/')
|
||||
if location == '':
|
||||
location = 'root'
|
||||
title = location
|
||||
|
||||
now = datetime.datetime.now()
|
||||
base_name = '{timestamp}-{prefix}{name}.png'.format(
|
||||
base_name = u'{timestamp}-{prefix}{sequence}{title}.png'.format(
|
||||
timestamp=datetime.datetime.now().strftime('%Y%m%d-%H%M%S'),
|
||||
prefix=self.screenshot_prefix,
|
||||
name=self.sanitize_filename(name),
|
||||
timestamp=now.strftime('%Y%m%d-%H%M%S')
|
||||
sequence=sequence,
|
||||
title=title,
|
||||
)
|
||||
path = os.path.join(self.screenshot_path, base_name)
|
||||
path = os.path.join(self.screenshot_path, self.sanitize_filename(base_name))
|
||||
if not os.path.isdir(self.screenshot_path):
|
||||
os.makedirs(self.screenshot_path, 0700)
|
||||
self.selenium.save_screenshot(path)
|
||||
|
||||
def get(self, location):
|
||||
return self.selenium.get(self.complete_url(location))
|
||||
|
||||
@skip_unless_tag_option()
|
||||
@tag('screenshots')
|
||||
def test_screenshots(self):
|
||||
for location in self.locations:
|
||||
self.selenium.get(self.complete_url(location))
|
||||
self.get(location)
|
||||
self.save_screenshot()
|
||||
|
||||
Reference in New Issue
Block a user