From 442b8acdc5ab89aa5cf1fda954241e76750b8355 Mon Sep 17 00:00:00 2001 From: androiddrew Date: Tue, 15 May 2018 16:59:17 -0400 Subject: [PATCH] Updating dependencies and tests --- .gitignore | 1 + README.md | 4 ++-- cookie_api/resources/cookies.py | 2 +- cookie_api/util/__init__.py | 2 +- cookie_api/util/http.py | 1 + requirements.txt | 4 +++- tests/test_cookies.py | 6 +++--- wsgi.py | 2 +- 8 files changed, 13 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index bbbf9b1..78bcdd3 100644 --- a/.gitignore +++ b/.gitignore @@ -51,6 +51,7 @@ htmlcov/ nosetests.xml coverage.xml *,cover +.pytest_cache/ # Translations *.mo diff --git a/README.md b/README.md index 180ea69..64ab6b0 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,6 @@ The Cookie API serves as a simple experimentation application for testing concep # Testing ```python -pip install -e . [testing] -py +pip install -e .[testing] +pytest ``` \ No newline at end of file diff --git a/cookie_api/resources/cookies.py b/cookie_api/resources/cookies.py index cde9c68..73f6864 100644 --- a/cookie_api/resources/cookies.py +++ b/cookie_api/resources/cookies.py @@ -15,7 +15,7 @@ logger = logbook.Logger(__name__) def get_cookies(session: Session) -> typing.List[CookieSchema]: cookies = session.query(Cookie).all() logger.debug('Cookies collection hit') - return [CookieSchema(cookie) for cookie in cookies] + return MetaJSONResponse([CookieSchema(cookie) for cookie in cookies]) def get_cookie(session: Session, id) -> CookieSchema: diff --git a/cookie_api/util/__init__.py b/cookie_api/util/__init__.py index dd253f8..25ca187 100644 --- a/cookie_api/util/__init__.py +++ b/cookie_api/util/__init__.py @@ -1,5 +1,5 @@ from .app import MetaApp from .http import MetaJSONResponse, ExtJSONResponse -from .component import SQLAlchemySession +from .component import SQLAlchemySession, DBSession from .hook import SQLAlchemyHook from .validators import Decimal \ No newline at end of file diff --git a/cookie_api/util/http.py b/cookie_api/util/http.py index eb37594..a63aa94 100644 --- a/cookie_api/util/http.py +++ b/cookie_api/util/http.py @@ -41,6 +41,7 @@ class MetaJSONResponse(Response): meta: typing.Any = None) -> None: self.status_code = status_code self.meta = self._build_meta(meta) + self._content = content self.content = self.render(content) self.headers = MutableHeaders(headers) self.set_default_headers() diff --git a/requirements.txt b/requirements.txt index 5067db3..b949484 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,10 +1,11 @@ alembic==0.9.9 -apistar==0.5.12 +apistar==0.5.18 apistar-jwt==0.4.2 bcrypt==3.1.4 certifi==2018.4.16 cffi==1.11.5 chardet==3.0.4 +click=6.7 idna==2.6 Jinja2==2.10 Logbook==1.3.3 @@ -15,6 +16,7 @@ pycparser==2.18 PyJWT==1.6.1 python-dateutil==2.7.2 python-editor==1.0.3 +pyyaml=3.12 requests==2.18.4 six==1.11.0 SQLAlchemy==1.2.7 diff --git a/tests/test_cookies.py b/tests/test_cookies.py index 0d87da6..501e045 100644 --- a/tests/test_cookies.py +++ b/tests/test_cookies.py @@ -13,13 +13,13 @@ def test_get_cookies_empty(app): client = TestClient(app) response = client.get('/cookies') assert response.status_code == 200 - assert response.json() == [] + assert response.json()['data'] == [] def test_get_empty_cookies(rb_session): extended_response = get_cookies(rb_session) assert extended_response.status_code == 200 - assert json.dumps([], default=ExtJSONResponse.default).encode('utf-8') == extended_response.content + assert extended_response._content == [] def test_get_cookies(rb_session): @@ -32,7 +32,7 @@ def test_get_cookies(rb_session): rb_session.flush() cookies = rb_session.query(Cookie).all() extended_response = get_cookies(rb_session) - assert len(extended_response.content) == 1 + assert len(extended_response._content) == 1 diff --git a/wsgi.py b/wsgi.py index b62adfd..b93baa0 100644 --- a/wsgi.py +++ b/wsgi.py @@ -12,4 +12,4 @@ app = application_factory() if __name__ == '__main__': app = application_factory() - app.serve('127.0.0.1', 5000, debug=True) + app.serve('127.0.0.1', 8080, debug=True)