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

Commit

Permalink
Make test fixtures more readable and compact.
Browse files Browse the repository at this point in the history
  • Loading branch information
bartfeenstra committed Nov 27, 2017
1 parent 17e8c02 commit 2efb30e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 29 deletions.
12 changes: 12 additions & 0 deletions tk/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ def multiplier(self, *test_method_args, **test_method_kwargs):
return decorator


def expand_data(values):
"""
Expands a data set.
:param data: An iterable of scalars.
:return:
"""
data = {}
for value in values:
data[value] = (value,)
return data


class IntegrationTestCase(TestCase):
"""
Provides scaffolding for light-weight integration tests.
Expand Down
35 changes: 6 additions & 29 deletions tk/tests/test_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import requests_mock

from tk.tests import IntegrationTestCase, data_provider
from tk.tests import IntegrationTestCase, data_provider, expand_data

PROFILE = """
<?xml version="1.0" encoding="UTF-8" ?>
Expand Down Expand Up @@ -34,62 +34,39 @@ def provide_disallowed_submit_methods():
Returns the HTTP methods disallowed by the /submit endpoint.
See data_provider().
"""
return {
'GET': ('GET',),
'PUT': ('PUT',),
'PATCH': ('PATCH',),
'DELETE': ('DELETE',),
}
return expand_data(('GET', 'PUT', 'PATCH', 'DELETE'))


def provide_disallowed_retrieve_methods():
"""
Returns the HTTP methods disallowed by the /retrieve/{} endpoint.
See data_provider().
"""
return {
'POST': ('POST',),
'PUT': ('PUT',),
'PATCH': ('PATCH',),
'DELETE': ('DELETE',),
}
return expand_data(('POST', 'PUT', 'PATCH', 'DELETE'))


def provide_disallowed_access_token_methods():
"""
Returns the HTTP methods disallowed by the /accesstoken/{} endpoint.
See data_provider().
"""
return {
'POST': ('POST',),
'PUT': ('PUT',),
'PATCH': ('PATCH',),
'DELETE': ('DELETE',),
}
return expand_data(('POST', 'PUT', 'PATCH', 'DELETE'))


def provide_4xx_codes():
"""
Returns the HTTP 4xx codes.
See data_provider().
"""
codes = list(range(400, 418)) + list(range(421, 424)) + [426, 428, 429, 431, 451]
data = {}
for code in codes:
data[code] = (code,)
return data
return expand_data(list(range(400, 418)) + list(range(421, 424)) + [426, 428, 429, 431, 451])


def provide_5xx_codes():
"""
Returns the HTTP 5xx codes.
See data_provider().
"""
codes = list(range(500, 508)) + [510, 511]
data = {}
for code in codes:
data[code] = (code,)
return data
return expand_data(list(range(500, 508)) + [510, 511])


class AccessTokenTest(IntegrationTestCase):
Expand Down

0 comments on commit 2efb30e

Please sign in to comment.