From 9edef94d91c1872427558f8a5e5cb93d25e30660 Mon Sep 17 00:00:00 2001 From: Artem Mezhenin Date: Sat, 29 Mar 2014 17:13:33 +0400 Subject: [PATCH] Create an automated test suite * fixes, #2 * unittest2 was replaced by py.test * previous test was repaired * notes on running tests was added to README.md --- README.md | 15 +++++++++++++++ requirements.txt | 2 +- review/filters.py | 2 +- review/test.py | 29 +++++++++++++++++------------ review/views.py | 1 - 5 files changed, 34 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index f2955dc..a2d610d 100644 --- a/README.md +++ b/README.md @@ -11,3 +11,18 @@ virtualenv --no-site-packages venv source venv/bin/activate pip install -r requirements.txt ``` + +### Testing + +Run all tests: + + $ nosetest + +Run all tests with coverage: + + $ nosetests --with-coverage + +Run some particular test: + + $ nosetests review.test + $ nosetests review.test:test_simple diff --git a/requirements.txt b/requirements.txt index 1c56a92..f4f5af4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,4 +19,4 @@ wsgiref==0.1.2 nose==1.3.0 coverage==3.7.1 coveralls -unittest2==0.5.1 +pytest==2.5.2 \ No newline at end of file diff --git a/review/filters.py b/review/filters.py index 40bb0f2..c42d12d 100644 --- a/review/filters.py +++ b/review/filters.py @@ -1,6 +1,6 @@ import humanize def show_stars(score): - return ''.join(['' for _ in range(score)]) + return '' * score def naturaltime(datetime): return humanize.naturaltime(datetime) diff --git a/review/test.py b/review/test.py index 0cd4ff6..c3ed84a 100644 --- a/review/test.py +++ b/review/test.py @@ -1,17 +1,22 @@ """Tests for review app.""" -from views import app -from unittest2 import TestCase +from .views import app +import pytest -class ReviewTest(TestCase): - - def setup(self): - self.app = app.test_client() - def test_simpe(self): - self.assertEquals(1 + 1, 2) +def test_main_list(): + """Can we successfully retrieve a list of reviews?""" + client = app.test_client() + response = client.get('/') + assert response.status_code == 200 + assert 'Reviews' in response.data + + +def test_simple(): + assert 1 + 1 == 2 + + +if __name__ == '__main__': + pytest.main() + - def _test_main_list(self): - """Can we successfully retrieve a list of reviews?""" - response = self.app.get('/') - assert 'All Reviews' in response.data diff --git a/review/views.py b/review/views.py index 357f1b9..f9a6aaa 100644 --- a/review/views.py +++ b/review/views.py @@ -21,7 +21,6 @@ def login(): if request.method == 'POST': if form.validate_on_submit(): user = User.query.get(form.email.data) - print user if user and bcrypt.check_password_hash(user.password, form.password.data): if login_user(user): user.authenticated = True