-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from codeforamerica/add_user_logins
Add user logins
- Loading branch information
Showing
69 changed files
with
1,636 additions
and
381 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
.DS_Store | ||
.env | ||
migrations | ||
node_modules | ||
__pycache__ | ||
*.sw[op] | ||
*.pyc | ||
.coverage | ||
.coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# -*- coding: utf-8 -*- | ||
import os | ||
from pprint import pprint | ||
from nose.plugins.attrib import attr | ||
|
||
from tests.selenium_test_base import SeleniumBaseTestCase | ||
|
||
class TestAuthTasks(SeleniumBaseTestCase): | ||
|
||
user = { | ||
'email': os.environ.get('DEFAULT_ADMIN_EMAIL', '[email protected]'), | ||
'password': os.environ.get('DEFAULT_ADMIN_PASSWORD', 'this-sketch-is-too-silly'), | ||
} | ||
|
||
def open_email_inbox(self): | ||
self.get_email() | ||
self.wait(1) | ||
email_input = self.xpath("//input[@name='Email']") | ||
email_input.send_keys(self.user['email']) | ||
email_input.send_keys(self.keys.ENTER) | ||
self.wait(1) | ||
password_input = self.xpath("//input[@name='Passwd']") | ||
password_input.send_keys(self.user['password']) | ||
password_input.send_keys(self.keys.ENTER) | ||
self.wait(30) | ||
|
||
def test_redirect_to_login(self): | ||
self.get('/') | ||
self.assertIn('Log in', self.browser.title) | ||
email_input = self.browser.find_element_by_xpath('//input[@name=email]') | ||
print(email_input) | ||
|
||
def test_click_on_forgot_password_gets_email_form(self): | ||
self.get('/') | ||
self.assertIn('Log in', self.browser.title) | ||
email_input = self.browser.find_element_by_name('email') | ||
# find email | ||
|
||
def test_get_login_page(self): | ||
self.get('/login') | ||
self.assertIn('Log in', self.browser.title) | ||
self.screenshot('login.png') | ||
|
||
def test_able_to_login(self): | ||
self.get('/login') | ||
email_input = self.browser.find_element_by_name('email') | ||
email_input.send_keys(self.user['email']) | ||
password_input = self.browser.find_element_by_name('password') | ||
password_input.send_keys(self.user['password']) | ||
self.screenshot('login-filled.png') | ||
password_input.submit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from tests.selenium_test_base import SeleniumBaseTestCase | ||
|
||
class TestFormFillerTasks(SeleniumBaseTestCase): | ||
|
||
def test_index_get(self): | ||
self.get('/') | ||
self.assertIn('Clean Slate', self.browser.title) | ||
self.screenshot('index.png') |
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
from flask import url_for, request, session | ||
from flask.ext.login import current_user | ||
from sqlalchemy import func, distinct | ||
from pprint import pprint | ||
|
||
from typeseam.app import db | ||
from typeseam.auth.models import User | ||
from typeseam.auth.queries import create_user, get_user_by_email | ||
|
||
from tests.test_base import BaseTestCase | ||
|
||
|
||
class TestAuthViews(BaseTestCase): | ||
|
||
sample_user_data = dict( | ||
email="[email protected]", | ||
password="Hell0" | ||
) | ||
|
||
def setUp(self): | ||
BaseTestCase.setUp(self) | ||
self.client = self.app.test_client() | ||
create_user(**self.sample_user_data) | ||
|
||
def get_user(self): | ||
return get_user_by_email(self.sample_user_data['email']) | ||
|
||
def test_wrong_password_returns_to_login(self): | ||
response = self.login(password="not hello") | ||
self.assertIn('Sign in', response.data.decode('utf-8')) | ||
self.assertFalse(current_user.is_authenticated) | ||
|
||
def login(self, **kwargs): | ||
login_data = dict(**self.sample_user_data) | ||
login_data.update(**kwargs) | ||
get_response = self.client.get('/', follow_redirects=True) | ||
csrf_token = self.get_input_value('csrf_token', get_response) | ||
return self.client.post( | ||
url_for('user.login'), | ||
data=dict(csrf_token=csrf_token, **login_data), | ||
follow_redirects=True) | ||
|
||
def logout(self): | ||
return self.client.get(url_for('user.logout'), follow_redirects=True) | ||
|
||
def test_new_user_password_is_properly_encrypted(self): | ||
# check that the password was hashed with bcrypt | ||
raw_password = self.sample_user_data['password'] | ||
user = self.get_user() | ||
encoded_raw_password = raw_password.encode('utf-8') | ||
presumably_hashed_password = user.password.encode('utf-8') | ||
import bcrypt | ||
self.assertEqual( | ||
bcrypt.hashpw(encoded_raw_password, presumably_hashed_password), | ||
presumably_hashed_password) | ||
|
||
def test_unauthenticated_home_page_resolves_to_login_view(self): | ||
r = self.client.get('/') | ||
self.assertEqual(r.status_code, 302) # is it a redirect? | ||
r = self.client.get('/', follow_redirects=True) | ||
self.assertIn('Sign in', r.data.decode('utf-8')) # did it redirect to Log in? | ||
|
||
def test_login_form_includes_csrf_token(self): | ||
r = self.client.get(url_for('user.login')) | ||
self.assertIn('csrf_token', r.data.decode('utf-8')) | ||
|
||
def test_can_login(self): | ||
response = self.login() | ||
self.assertEqual(response.status_code, 200) | ||
|
||
def test_can_logout(self): | ||
self.login() | ||
response = self.logout() | ||
self.assertFalse(current_user.is_authenticated) | ||
|
||
def test_successful_login_has_message(self): | ||
response = self.login() | ||
self.assertIn('signed in successfully', response.data.decode('utf-8')) | ||
|
||
def test_login_fails_without_csrf(self): | ||
response = self.client.post( | ||
url_for('user.login'), | ||
data=dict(**self.sample_user_data), | ||
follow_redirects=True) | ||
self.assertEqual(response.status_code, 400) | ||
|
||
# def test_login_warns_about_http_and_links_to_https(self): | ||
# raise NotImplementedError | ||
|
||
# def test_login_has_forgot_password_link(self): | ||
# raise NotImplementedError | ||
|
||
# def test_forgot_password_post_sends_email(self): | ||
# raise NotImplementedError | ||
|
||
# def test_forgot_password_view_errors_on_unused_email(self): | ||
# raise NotImplementedError | ||
|
||
# def test_password_reset_email_contains_proper_link(self): | ||
# raise NotImplementedError | ||
|
||
# def test_password_reset_link_expires(self): | ||
# raise NotImplementedError | ||
|
||
# def test_password_reset_form_looks_sufficient(self): | ||
# raise NotImplementedError | ||
|
||
# def test_password_reset_has_csrf_and_https_warning(self): | ||
# raise NotImplementedError | ||
|
||
# def test_password_reset_fails_without_csrf(self): | ||
# raise NotImplementedError | ||
|
||
# def test_successful_password_reset_goes_to_next_with_message(self): | ||
# raise NotImplementedError | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from tests.test_base import BaseTestCase | ||
from typeseam.utils.sendgrid_mailer import email_dispatched | ||
from typeseam.auth.tasks import sendgrid_email | ||
|
||
|
||
class TestMail(BaseTestCase): | ||
|
||
def setUp(self): | ||
BaseTestCase.setUp(self) | ||
self.body = """Hey there, this is an email message.""" | ||
self.subject = "Hello from mail tests" | ||
|
||
def send_mail(self): | ||
sendgrid_email( | ||
subject="testing mail again", | ||
recipients=['[email protected]'], | ||
text_message="What is up?" | ||
) | ||
|
||
def test_can_send_mail(self): | ||
messages = [] | ||
def fire(app, message, **extra): | ||
messages.append(message) | ||
email_dispatched.connect(fire) | ||
self.send_mail() | ||
self.assertEqual(len(messages), 1) |
Oops, something went wrong.