Commit c417651cda6c97f165711cbec70b65ac1b303e88

Authored by Antoine Goutenoir
1 parent ffdaeb0e
Exists in master

Add a battery of tests.

Showing 2 changed files with 55 additions and 0 deletions   Show diff stats
tests/conftest.py 0 → 100644
... ... @@ -0,0 +1,26 @@
  1 +import pytest
  2 +
  3 +from flaskr import create_app
  4 +from flaskr.models import db, User
  5 +
  6 +
  7 +@pytest.fixture()
  8 +def testapp(request):
  9 + app = create_app('flaskr.settings.TestConfig')
  10 + client = app.test_client()
  11 +
  12 + db.app = app
  13 + db.create_all()
  14 +
  15 + if getattr(request.module, "create_user", True):
  16 + admin = User('admin', 'supersafepassword')
  17 + db.session.add(admin)
  18 + db.session.commit()
  19 +
  20 + def teardown():
  21 + db.session.remove()
  22 + db.drop_all()
  23 +
  24 + request.addfinalizer(teardown)
  25 +
  26 + return client
... ...
tests/test_models.py 0 → 100644
... ... @@ -0,0 +1,29 @@
  1 +#! ../env/bin/python
  2 +# -*- coding: utf-8 -*-
  3 +
  4 +import pytest
  5 +
  6 +from flaskr.models import db, User
  7 +
  8 +create_user = False
  9 +
  10 +
  11 +@pytest.mark.usefixtures("testapp")
  12 +class TestModels:
  13 + def test_user_save(self, testapp):
  14 + """ Test Saving the user model to the database """
  15 +
  16 + admin = User('admin', 'supersafepassword')
  17 + db.session.add(admin)
  18 + db.session.commit()
  19 +
  20 + user = User.query.filter_by(username="admin").first()
  21 + assert user is not None
  22 +
  23 + def test_user_password(self, testapp):
  24 + """ Test password hashing and checking """
  25 +
  26 + admin = User('admin', 'supersafepassword')
  27 +
  28 + assert admin.username == 'admin'
  29 + assert admin.check_password('supersafepassword')
... ...