parent
8915d425e0
commit
1f9e6b171e
@ -0,0 +1,34 @@ |
|||||||
|
# -*- coding: utf-8 -*- |
||||||
|
import unittest |
||||||
|
from nose.tools import * # PEP8 asserts |
||||||
|
from flask.ext.testing import TestCase |
||||||
|
|
||||||
|
from {{ cookiecutter.repo_name }}.app import create_app |
||||||
|
from {{ cookiecutter.repo_name }}.models import User, db |
||||||
|
|
||||||
|
|
||||||
|
class TestUser(TestCase): |
||||||
|
TESTING = True |
||||||
|
DEBUG = True |
||||||
|
SQLALCHEMY_DATABASE_URI = 'sqlite://' |
||||||
|
|
||||||
|
def create_app(self): |
||||||
|
app = create_app(self, 'testing') |
||||||
|
with app.app_context(): |
||||||
|
db.create_all() |
||||||
|
return app |
||||||
|
|
||||||
|
def tearDown(self): |
||||||
|
db.session.remove() |
||||||
|
db.drop_all() |
||||||
|
|
||||||
|
def test_check_password(self): |
||||||
|
user = User(username="foo", email="foo@bar.com", |
||||||
|
password="foobarbaz123") |
||||||
|
db.session.add(user) |
||||||
|
db.session.commit() |
||||||
|
assert_true(user.check_password('foobarbaz123')) |
||||||
|
assert_false(user.check_password("barfoobaz")) |
||||||
|
|
||||||
|
if __name__ == '__main__': |
||||||
|
unittest.main() |
@ -1,29 +0,0 @@ |
|||||||
'''Unit testing''' |
|
||||||
|
|
||||||
import unittest |
|
||||||
try: |
|
||||||
from nose.tools import * # PEP8 asserts |
|
||||||
except ImportError: |
|
||||||
import sys |
|
||||||
print('nose required. Run "pip install nose".') |
|
||||||
|
|
||||||
from {{cookiecutter.repo_name}}.main import create_app |
|
||||||
|
|
||||||
class Test{{cookiecutter.repo_name | capitalize}}(unittest.TestCase): |
|
||||||
|
|
||||||
def setUp(self): |
|
||||||
app = create_app("{{cookiecutter.repo_name}}.settings.DevConfig", 'dev') |
|
||||||
app.config['TESTING'] = True |
|
||||||
self.app = app.test_client() |
|
||||||
|
|
||||||
def test_add(self): |
|
||||||
'''An example test.''' |
|
||||||
assert_equal(1 + 1, 2) |
|
||||||
|
|
||||||
def json_response(response, code=200): |
|
||||||
'''Checks that the status code is OK and returns the json as a dict.''' |
|
||||||
assert_equal(response.status_code, code) |
|
||||||
return json.loads(response.data) |
|
||||||
|
|
||||||
if __name__ == '__main__': |
|
||||||
unittest.main() |
|
Loading…
Reference in new issue