Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Commit

Permalink
Add the endpoints.
Browse files Browse the repository at this point in the history
  • Loading branch information
bartfeenstra committed Nov 17, 2017
1 parent d92bf03 commit f03bccc
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 8 deletions.
6 changes: 3 additions & 3 deletions requirements-dev-frozen.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ click==6.7
coverage==4.4.2
coveralls==1.2.0
docopt==0.6.2
flake8==3.3.0
flake8==3.5.0
Flask==0.12.2
idna==2.6
itsdangerous==0.24
Jinja2==2.10
MarkupSafe==1.0
mccabe==0.6.1
nose2==0.6.5
nose2==0.7.2
pycodestyle==2.3.1
pyflakes==1.5.0
pyflakes==1.6.0
requests==2.18.4
six==1.11.0
urllib3==1.22
Expand Down
6 changes: 3 additions & 3 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-r ./requirements.txt
autopep8 ~= 1.3
coverage ~= 4.4.1
coverage ~= 4.4.2
coveralls ~= 1.2.0
flake8 ~= 3.3.0
nose2 ~= 0.6.5
flake8 ~= 3.5.0
nose2 ~= 0.7.2
5 changes: 5 additions & 0 deletions requirements-frozen.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
certifi==2017.11.5
chardet==3.0.4
click==6.7
Flask==0.12.2
idna==2.6
itsdangerous==0.24
Jinja2==2.10
MarkupSafe==1.0
requests==2.18.4
urllib3==1.22
Werkzeug==0.12.2
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
flask ~= 0.12.2
flask ~= 0.12.2
requests ~= 2.18.4
13 changes: 12 additions & 1 deletion tk/flask/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,15 @@


class App(Flask):
pass
def __init__(self, *args, **kwargs):
super().__init__('tk', *args, **kwargs)
self._register_routes()

def _register_routes(self):
@self.route('/submit', methods=['POST'])
def submit():
return 'SUBMITTED'

@self.route('/retrieve/<id>')
def retrieve(id):
return id
42 changes: 42 additions & 0 deletions tk/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from unittest import TestCase

from tk.flask.app import App


def data_provider(data_provider):
def decorator(test_method):
def multiplier(self, *test_method_args, **test_method_kwargs):
"""
The replacement (decorated) test method.
:param self:
:param args:
:return:
"""
for fixture_name, test_method_fixture_args in data_provider().items():
try:
test_method(self, *test_method_args,
*test_method_fixture_args,
**test_method_kwargs)
except AssertionError:
raise AssertionError(
'Assertion failed with data set "%s"' % str(fixture_name))
except Exception:
raise AssertionError(
'Unexpected error with data set "%s"' % str(
fixture_name))

return multiplier

return decorator


class IntegrationTestCase(TestCase):
def setUp(self):
self._flask_app = App()
self._flask_app.config.update(SERVER_NAME='example.com')
self._flask_app_context = self._flask_app.app_context()
self._flask_app_context.push()
self._flask_app_client = self._flask_app.test_client()

def tearDown(self):
self._flask_app_context.pop()
31 changes: 31 additions & 0 deletions tk/tests/test_submit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from tk.tests import IntegrationTestCase, data_provider


def provide_disallowed_submit_methods():
return {
'GET': ('GET',),
'PUT': ('PUT',),
'PATCH': ('PATCH',),
'DELETE': ('DELETE',),
}


def provide_disallowed_retrieve_methods():
return {
'POST': ('POST',),
'PUT': ('PUT',),
'PATCH': ('PATCH',),
'DELETE': ('DELETE',),
}


class StaticEndpointRepositoryTest(IntegrationTestCase):
@data_provider(provide_disallowed_submit_methods)
def testSubmitWithDisallowedMethodShould405(self, method):
response = self._flask_app_client.open('/submit', method=method)
self.assertEquals(405, response.status_code)

@data_provider(provide_disallowed_retrieve_methods)
def testRetrieveWithDisallowedMethodShould405(self, method):
response = self._flask_app_client.open('/retrieve/foo', method=method)
self.assertEquals(405, response.status_code)

0 comments on commit f03bccc

Please sign in to comment.