def test_post_password_reset_via_email_page_invalid(test_client): """ GIVEN a Flask application WHEN the '/users/password_reset_via_email' page is posted to (POST) with an invalid email address THEN check that an error message is flashed """ with mail.record_messages() as outbox: response = test_client.post('/users/password_reset_via_email', data={'email': '*****@*****.**'}, follow_redirects=True) assert response.status_code == 200 assert len(outbox) == 0 assert b'Error! Invalid email address!' in response.data
def test_get_resend_email_confirmation_not_logged_in(test_client): """ GIVEN a Flask application configured for testing with the user not logged in WHEN the '/users/resend_email_confirmation' page is retrieved (GET) THEN check that an email was not queued up to send """ with mail.record_messages() as outbox: response = test_client.get('/users/resend_email_confirmation', follow_redirects=True) assert response.status_code == 200 assert b'Email sent to confirm your email address. Please check your email!' not in response.data assert len(outbox) == 0 assert b'Please log in to access this page.' in response.data
def test_post_password_reset_via_email_page_not_confirmed(test_client, log_in_default_user): """ GIVEN a Flask application configured for testing WHEN the '/users/password_reset_via_email' page is posted to (POST) with a email address that has not been confirmed THEN check that an error message is flashed """ with mail.record_messages() as outbox: response = test_client.post('/users/password_reset_via_email', data={'email': '*****@*****.**'}, follow_redirects=True) assert response.status_code == 200 assert len(outbox) == 0 assert b'Your email address must be confirmed before attempting a password reset.' in response.data
def test_post_password_reset_via_email_page_invalid(test_client): """ GIVEN a Flask application configured for testing WHEN the '/users/password_reset_via_email' page is posted to (POST) with an invalid email address THEN check that an error message is flashed """ with mail.record_messages() as outbox: response = test_client.post('/users/password_reset_via_email', data={'email': 'andrewflaskdev'}, follow_redirects=True) assert response.status_code == 200 print(response.data) assert len(outbox) == 0 assert b'validation-error' in response.data assert b'Invalid email address.' in response.data
def test_get_resend_email_confirmation_logged_in(test_client, log_in_default_user): """ GIVEN a Flask application configured for testing with the user logged in WHEN the '/users/resend_email_confirmation' page is retrieved (GET) THEN check that an email was queued up to send """ with mail.record_messages() as outbox: response = test_client.get('/users/resend_email_confirmation', follow_redirects=True) assert response.status_code == 200 assert b'Email sent to confirm your email address. Please check your email!' in response.data assert len(outbox) == 1 assert outbox[ 0].subject == 'Recipie App - Please Confirm Your Email Address' assert outbox[0].sender == '*****@*****.**' assert outbox[0].recipients[0] == '*****@*****.**' assert 'http://localhost/users/confirm/' in outbox[0].html
def test_post_password_reset_via_email_page_valid(test_client, confirm_email_default_user): """ GIVEN a Flask application configured for testing WHEN the '/users/password_reset_via_email' page is posted to (POST) with a valid email address THEN check that an email was queued up to send """ with mail.record_messages() as outbox: response = test_client.post('/users/password_reset_via_email', data={'email': '*****@*****.**'}, follow_redirects=True) assert response.status_code == 200 assert b'Please check your email for a password reset link.' in response.data assert len(outbox) == 1 assert outbox[0].subject == 'Recipie App - Password Reset Requested' assert outbox[0].sender == '*****@*****.**' assert outbox[0].recipients[0] == '*****@*****.**' assert 'Questions? Comments?' in outbox[0].html assert '*****@*****.**' in outbox[0].html assert 'http://localhost/users/password_reset_via_token/' in outbox[0].html
def test_valid_registration(test_client): """ GIVEN a Flask application configured for testing WHEN the '/users/register' page is posted to (POST) with valid data THEN check the response is valid and the user is registered """ with mail.record_messages() as outbox: response = test_client.post('/users/register', data={ 'email': '*****@*****.**', 'password': '******' }, follow_redirects=True) assert response.status_code == 200 assert b'Thanks for registering, [email protected]! Please check your email address' in response.data assert b'Flask Stock Portfolio App' in response.data assert len(outbox) == 1 assert outbox[ 0].subject == 'Flask Stock Portfolio App - Confirm Your Email Address' assert outbox[0].sender == '*****@*****.**' assert outbox[0].recipients[0] == '*****@*****.**' assert 'http://localhost/users/confirm/' in outbox[0].html
def test_valid_registration(test_client): """ GIVEN a Flask application configured for testing WHEN the '/users/register' page is posted to (POST) with valid data THEN check the response is valid and the user is registered, and an email is queued to send """ with mail.record_messages() as outbox: response = test_client.post('/users/register', data={ 'email': '*****@*****.**', 'password_hashed': 'password123', 'username': '******', 'first_name': 'Andrew', 'last_name': 'Flaskdev' }, follow_redirects=True) assert response.status_code == 200 assert b'Thanks for registering, andrewflaskdev! Please check your email to confirm your email address.' in response.data assert len(outbox) == 1 assert outbox[ 0].subject == 'Recipie App - Please Confirm Your Email Address' assert outbox[0].sender == '*****@*****.**' assert outbox[0].recipients[0] == '*****@*****.**'