added pytest conf and cookie view tests
parent
610b6e1056
commit
e4a6ee8f83
@ -0,0 +1,53 @@
|
||||
from apistar.frameworks.wsgi import WSGIApp
|
||||
from apistar.backends.sqlalchemy_backend import SQLAlchemyBackend, get_session
|
||||
|
||||
import pytest
|
||||
|
||||
from cookie_api.models import Base
|
||||
from cookie_api.renders import JSONRenderer
|
||||
from cookie_api.app import commands, routes, components
|
||||
|
||||
settings = {
|
||||
'DATABASE': {
|
||||
'URL': 'postgresql://apistar:local@localhost/test_cookie_api',
|
||||
'METADATA': Base.metadata
|
||||
},
|
||||
'RENDERERS': [JSONRenderer()],
|
||||
'JWT': {
|
||||
'SECRET': 'thisisasecret'
|
||||
}
|
||||
}
|
||||
|
||||
backend = SQLAlchemyBackend(settings)
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def create_db():
|
||||
Base.metadata.create_all(backend.engine)
|
||||
|
||||
yield
|
||||
|
||||
Base.metadata.drop_all(backend.engine)
|
||||
|
||||
|
||||
@pytest.fixture(name='rb_session')
|
||||
def db_session_fixure():
|
||||
"Returns a SQLAlchemy session that autorolls back"
|
||||
session = backend.Session()
|
||||
try:
|
||||
yield session
|
||||
session.rollback()
|
||||
except:
|
||||
session.rollback()
|
||||
raise
|
||||
finally:
|
||||
session.close()
|
||||
|
||||
|
||||
@pytest.fixture(name='app', scope='session')
|
||||
def apistar_app_fixture():
|
||||
"""Returns a session scoped WSGIApp instance"""
|
||||
return WSGIApp(settings=settings,
|
||||
commands=commands,
|
||||
components=components,
|
||||
routes=routes)
|
@ -1,29 +1,73 @@
|
||||
# CRUD Cookies
|
||||
import pytest
|
||||
from apistar import TestClient
|
||||
|
||||
from cookie_api.models import Cookie
|
||||
from cookie_api.app import get_cookies, get_cookie
|
||||
|
||||
def test_get_cookies():
|
||||
pass
|
||||
|
||||
def test_get_cookies_empty(app):
|
||||
client = TestClient(app)
|
||||
response = client.get('/cookies')
|
||||
assert response.status_code == 200
|
||||
assert response.json() == []
|
||||
|
||||
def test_get_cookie():
|
||||
pass
|
||||
|
||||
def test_get_empty_cookies(rb_session):
|
||||
assert [] == get_cookies(rb_session)
|
||||
|
||||
|
||||
def test_get_cookies(rb_session):
|
||||
cookie = Cookie(name='sugar',
|
||||
recipe_url='http://cookie.com/sugar',
|
||||
sku='SC',
|
||||
qoh=14,
|
||||
unit_cost=1.50)
|
||||
rb_session.add(cookie)
|
||||
rb_session.flush()
|
||||
cookies = rb_session.query(Cookie).all()
|
||||
assert [cookie.to_dict() for cookie in cookies] == get_cookies(rb_session)
|
||||
|
||||
|
||||
def test_get_cookie(rb_session):
|
||||
cookie = Cookie(name='sugar',
|
||||
recipe_url='http://cookie.com/sugar',
|
||||
sku='SC',
|
||||
qoh=14,
|
||||
unit_cost=1.50)
|
||||
|
||||
rb_session.add(cookie)
|
||||
rb_session.flush()
|
||||
cookie = rb_session.query(Cookie).filter_by(id=cookie.id).one()
|
||||
assert cookie.to_dict() == get_cookie(rb_session, 1)
|
||||
|
||||
|
||||
def test_get_cookie_that_doesnt_exist(rb_session):
|
||||
response = get_cookie(rb_session, 100)
|
||||
assert {"error": "404 Not Found"} == response.content
|
||||
assert 404 == response.status
|
||||
|
||||
|
||||
@pytest.mark.skip()
|
||||
def test_valid_create_cookie():
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.skip()
|
||||
def test_invalid_create_cookie():
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.skip()
|
||||
def test_valid_update_cookie():
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.skip()
|
||||
def test_invalid_update_cookie():
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.skip()
|
||||
def test_delete_cookie():
|
||||
pass
|
||||
|
Loading…
Reference in New Issue