Skip to content

Commit

Permalink
Use WebTest for more concise tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcarp committed Aug 29, 2015
1 parent f6bc4ca commit ecf5829
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 236 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Flask==0.10.1
Flask-Admin==1.0.8
Flask-SQLAlchemy==1.0
SQLAlchemy==0.9.7
WebTest>=2.0.18
WTForms==2.0.1
coverage==3.7.1
pytest==2.6.3
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def run_tests(self):
install_requires=[
'Flask>=0.10.1',
'Flask-SQLAlchemy>=1.0',
'pytest-flask==0.4.0',
'Flask-Admin>=1.0.8',
'WebTest>=2.0.18',
'python-dateutil>=2.4.2',
'six>=1.9.0',
],
Expand Down
10 changes: 8 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
sys.path.insert(0, os.path.abspath('.'))

import pytest
from webtest import TestApp

from sandman2 import get_app, db



@pytest.yield_fixture(scope='function')
def app(request):
"""Yield the application instance."""
Expand All @@ -39,9 +39,15 @@ def app(request):
exclude_tables=exclude_tables)
application.testing = True

yield application
with application.test_request_context():
yield application

with application.app_context():
db.session.remove()
db.drop_all()
os.unlink(test_database_path)


@pytest.fixture
def client(app):
return TestApp(app)
13 changes: 3 additions & 10 deletions tests/test_automap_base_models.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
"""Test using user-defined models with sandman2."""
import json

from flask import url_for
from pytest_flask.fixtures import client

from tests.resources import (
GET_ERROR_MESSAGE,
INVALID_ACTION_MESSAGE,
)

model_module = 'tests.automap_models'
database = 'blog.sqlite3'


def test_get_automap_collection(client):
"""Do we see a model's __unicode__ definition being used in the admin?"""
response = client.get(url_for('blog.index_view'))
assert response.status_code == 200
assert 'Jeff Knupp' in response.get_data(as_text=True)
res = client.get(url_for('blog.index_view'))
assert res.status_code == 200
assert 'Jeff Knupp' in res
11 changes: 4 additions & 7 deletions tests/test_extended_functionality.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
"""Tests for non-core functionality in sandman2."""

from pytest_flask.fixtures import client

exclude_tables = ('Invoice')

def test_pagination(client):
"""Do we return paginated results when a 'page' parameter is provided?"""
response = client.get('/artist?page=2')
assert response.status_code == 200
assert len(response.json['resources']) == 20
assert response.json['resources'][0]['ArtistId'] == 21
res = client.get('/artist?page=2')
assert res.status_code == 200
assert len(res.json['resources']) == 20
assert res.json['resources'][0]['ArtistId'] == 21
Loading

0 comments on commit ecf5829

Please sign in to comment.