-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jakub Skiepko
committed
May 16, 2017
1 parent
9dd2172
commit db954ea
Showing
10 changed files
with
95 additions
and
8 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
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 |
---|---|---|
@@ -1,15 +1,34 @@ | ||
import flask | ||
from cached_property import cached_property | ||
from flask import views | ||
|
||
from dila.frontend.flask import template_tools | ||
from dila.frontend.flask import forms | ||
|
||
blueprint = flask.Blueprint('authenticate', __name__) | ||
template_tools.setup_language_context(blueprint) | ||
|
||
|
||
class LoginView(views.MethodView): | ||
def get(self): | ||
return flask.render_template('login.html', **self.context) | ||
|
||
def post(self): | ||
if self.form.validate(): | ||
username = self.form.username.data | ||
flask.session['username'] = username | ||
return flask.redirect(flask.url_for('main.home')) | ||
else: | ||
return self.get() | ||
|
||
|
||
@property | ||
def context(self): | ||
return { | ||
'form': self.form, | ||
} | ||
|
||
@cached_property | ||
def form(self): | ||
return forms.LoginForm() | ||
|
||
|
||
blueprint.add_url_rule('/login/', view_func=LoginView.as_view('login')) |
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 |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
|
||
setup( | ||
name='dila', | ||
version='0.3.1.dev0', | ||
version='0.4.0.dev0', | ||
description='Dila is a open source web-based translation platform for translators, content creators and developers.', | ||
author='Jakub Skiepko', | ||
author_email='[email protected]', | ||
|
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,28 @@ | ||
import re | ||
from unittest import mock | ||
|
||
|
||
def test_login_form(flask_client): | ||
response = flask_client.get('/login/') | ||
assert re.search('<input class="[^"]*" id="username" name="username" type="text" value="">', | ||
response.data.decode()) | ||
assert re.search('<input class="[^"]*" id="password" name="password" type="password" value="">', | ||
response.data.decode()) | ||
assert re.search('<input class="[^"]*" id="login" value="Log in" type="submit">', response.data.decode()) | ||
|
||
|
||
@mock.patch('dila.application.authenticate') | ||
def test_post_login(authenticate, flask_client): | ||
authenticate.return_value = True | ||
response = flask_client.post('/login/', data={'username': 'songo', 'password': 'ssj4'}) | ||
authenticate.assert_called_once_with('songo', 'ssj4') | ||
assert response.status_code == 302 | ||
assert response.location == 'http://localhost/' | ||
|
||
|
||
@mock.patch('dila.application.authenticate') | ||
def test_post_invalid_login(authenticate, flask_client): | ||
authenticate.return_value = False | ||
response = flask_client.post('/login/', data={'username': 'songo', 'password': 'ssj5'}) | ||
authenticate.assert_called_once_with('songo', 'ssj5') | ||
assert "Invalid login or password" in response.data.decode() |