''' functional tests for ordr2.views.registration ''' from pyramid_mailer import get_mailer from . import testappsetup, testapp, get_token_url # noqa: F401 def test_registration_form(testapp): # noqa: F811 ''' test the registration form ''' response = testapp.get('/account/register') active = response.html.find('li', class_='active') assert active.a['href'] == 'http://localhost/account/register' assert 'Registration' in response.html.title.text def test_registration_form_invalid(testapp): # noqa: F811 ''' test the registration form with invalid data ''' response = testapp.get('/account/register') form = response.form form['email'] = 'not an email address' response = form.submit(name='create') assert 'Invalid email address' in response assert 'Registration' in response.html.title.text def test_registration_process(testapp): # noqa: F811 ''' test the registration process with valid data ''' response = testapp.get('/account/register') form = response.form form['username'] = 'AmyMcDonald', form['first_name'] = 'Amy', form['last_name'] = 'McDonald', form['email'] = 'amy.mcdonald@example.com', form['password'] = 'Make Amy McDonald A Rich Girl Fund', form['password-confirm'] = 'Make Amy McDonald A Rich Girl Fund', response = form.submit(name='create') assert response.location == 'http://localhost/account/register/verify' response = response.follow() active = response.html.find('li', class_='active') assert active.a['href'] == 'http://localhost/account/register' assert 'Please follow the link in the email' in response assert 'Registration' in response.html.title.text # click the email verification token mailer = get_mailer(testapp.app.registry) email = mailer.outbox[-1] assert email.subject == '[ordr] Please verify your email address' token_link = get_token_url(email, prefix='/account/register/') response = testapp.get(token_link) active = response.html.find('li', class_='active') assert active.a['href'] == 'http://localhost/account/register' assert 'Registration Completed' in response assert 'Registration' in response.html.title.text