Skip to content
This repository has been archived by the owner on Nov 14, 2023. It is now read-only.

Commit

Permalink
added docstring to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
silvanocerza committed Aug 30, 2016
1 parent 35ead51 commit cfcc4eb
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 24 deletions.
1 change: 1 addition & 0 deletions tests/tests_integration/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

@missing_app_tokens
def test_good_request():
"""Verifies that a correctly formed api request returns 200."""
new_api = Api(sandbox_mode=True)
response = new_api.request('/games', 'get')

Expand Down
3 changes: 3 additions & 0 deletions tests/tests_integration/test_mkm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

@missing_app_tokens
def test_response_is_as_expected():
"""Verifies the list of games returned from backend is as expected."""
response = mkm_sandbox.market_place.games()
json_response = response.json()

Expand All @@ -26,6 +27,7 @@ def test_response_is_as_expected():

@missing_app_tokens
def test_sandbox_url():
"""Verifies that mkm_sandbox sends its requests to sandbox backend."""
response = mkm_sandbox.market_place.games()

assert response.status_code == 200
Expand All @@ -34,6 +36,7 @@ def test_sandbox_url():

@missing_app_tokens
def test_card_search():
"""Verifies the search for a product with special chars in its names works correctly."""
response = mkm_sandbox.market_place.products(name='Jace, the Mind Sculptor', game=1, language=1, match=False)

assert response.status_code == 200
16 changes: 4 additions & 12 deletions tests/tests_integration/test_oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@

@missing_app_tokens
def test_oauth_is_received():
"""
Checks if OAuth1 is received
"""
"""Verifies if OAuth1 is received."""
url = 'https://sandbox.mkmapi.eu/ws/v1.1/output.json/games'
auth = MKMOAuth1(os.environ.get('MKM_APP_TOKEN'),
client_secret=os.environ.get('MKM_APP_SECRET'),
Expand All @@ -25,9 +23,7 @@ def test_oauth_is_received():

@missing_app_tokens
def test_widget_app_oauth1_is_correct():
"""
Checks if response from server is positive
"""
"""Verifies if response from backend is positive using custom Client."""
url = 'https://sandbox.mkmapi.eu/ws/v1.1/output.json/games'
auth = MKMOAuth1(os.environ.get('MKM_APP_TOKEN'),
client_secret=os.environ.get('MKM_APP_SECRET'),
Expand All @@ -44,9 +40,7 @@ def test_widget_app_oauth1_is_correct():
@missing_app_tokens
@missing_widget_tokens
def test_dedicated_app_oauth1_is_correct():
"""
Checks if response from server is positive
"""
"""Verifies if response from backend is positive using custom OAuth header."""
url = 'https://sandbox.mkmapi.eu/ws/v1.1/output.json/games'
auth = MKMOAuth1(os.environ.get('MKM_APP_TOKEN'),
client_secret=os.environ.get('MKM_APP_SECRET'),
Expand All @@ -62,9 +56,7 @@ def test_dedicated_app_oauth1_is_correct():
@missing_app_tokens
@missing_widget_tokens
def test_account_entity_is_as_expected():
"""
Checks if the account entity received is as expected
"""
"""Verifies the account entity received is as expected."""
url = 'https://sandbox.mkmapi.eu/ws/v1.1/output.json/account'
auth = MKMOAuth1(os.environ.get('MKM_APP_TOKEN'),
client_secret=os.environ.get('MKM_APP_SECRET'),
Expand Down
1 change: 1 addition & 0 deletions tests/tests_integration/test_resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

@missing_app_tokens
def test_resolve_with_data():
"""Verifies posting data to backend returns a positive response."""
resolver = SimpleResolver(sandbox_mode=True)

simple_api_map = {'url': '/stock',
Expand Down
12 changes: 12 additions & 0 deletions tests/tests_unit/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@


def test_create_auth():
"""
Verifies that the default Client is used
when all the tokens are not empty strings.
"""
api = Api()
auth = api.create_auth('https://www.mkmapi.eu/ws/v1.1/output.json',
app_token='app_token',
Expand All @@ -24,6 +28,11 @@ def test_create_auth():


def test_create_auth_with_empty_string_token():
"""
Verifies that the custom MKMClient is used
when access token and access token secret
are empty strings.
"""
api = Api()
auth = api.create_auth('https://www.mkmapi.eu/ws/v1.1/output.json',
app_token='app_token',
Expand All @@ -39,20 +48,23 @@ def test_create_auth_with_empty_string_token():


def test_missing_env_var_raise_exception_correctly(mocker):
"""Verifies that an expection is thrown when necessary env vars are missing."""
os_mocked = mocker.patch('mkmsdk.utils.os')
os_mocked.environ = {}
with pytest.raises(exceptions.MissingConfig):
get_mkm_app_secret()


def test_endpoint():
"""Verifies the live endpoint is used by default."""
api = Api()
expected_live_base_endpoint = 'https://www.mkmapi.eu/ws/v1.1/output.json'

assert api.base_endpoint == expected_live_base_endpoint


def test_sandbox_mode():
"""Verifies the sandbox endpoint is used when specified."""
sandbox_api = Api(sandbox_mode=True)
expected_sandbox_base_endpoint = 'https://sandbox.mkmapi.eu/ws/v1.1/output.json'

Expand Down
5 changes: 2 additions & 3 deletions tests/tests_unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@


def test_get_oauth_params():
"""
Tests if oauth_token is added to the list of params when an empty string
"""
"""Verifies oauth_token is added to the list of params when an empty string."""

client = MKMClient(client_key='app_token',
client_secret='app_secret',
resource_owner_key='',
Expand Down
1 change: 1 addition & 0 deletions tests/tests_unit/test_mkm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


def test_simple_call(mocker):
"""Verifies resolver is called when making a call."""
mock_resolve = mocker.patch('mkmsdk.resolvers.SimpleResolver.resolve')
mkm.account_management.account()

Expand Down
4 changes: 4 additions & 0 deletions tests/tests_unit/test_oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@


def test_header_signature_is_correctly_decoded():
"""
Verifies oauth_signature is decoded correctly.
This is done so the backend accepts the Authorization header.
"""
given_header = {'Authorization': b'oauth_signature="test%20signature"'}
expected_signature = 'oauth_signature="test signature"'

Expand Down
8 changes: 0 additions & 8 deletions tests/tests_unit/test_requests.py

This file was deleted.

8 changes: 7 additions & 1 deletion tests/tests_unit/test_resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@


def test_if_bad_api_map_is_handled_correctly():
"""Verifies setup throws an exception if api map used is empty."""

live_resolver = SimpleResolver(sandbox_mode=False)
empty_api_map = {}

Expand All @@ -16,6 +18,8 @@ def test_if_bad_api_map_is_handled_correctly():


def test_if_setup_works_correctly():
"""Verifies setup correctly formats the url."""

live_resolver = SimpleResolver(sandbox_mode=False)
simple_api_map = {'url': '/account', 'method': 'get'}
expected_url = '/account'
Expand All @@ -35,17 +39,19 @@ def test_if_setup_works_correctly():


def test_if_bad_parameters_are_handled_correctly():
"""Verifies exception is thrown when user passes an unexisting parameter."""
live_resolver = SimpleResolver(sandbox_mode=False)
simple_api_map_with_parameters = {'url': '/user/{user}', 'method': 'get'}

with pytest.raises(exceptions.MissingParam):
live_resolver.setup(simple_api_map_with_parameters)

with pytest.raises(exceptions.MissingParam):
live_resolver.setup(simple_api_map_with_parameters, bad_param='Worse parameter ever')
live_resolver.setup(simple_api_map_with_parameters, bad_param='Worst parameter ever')


def test_setup_escapes_additional_parameters():
"""Verifies setup escapes parameters containing spaces or special chars."""
live_resolver = SimpleResolver(sandbox_mode=False)
simple_api_map = {'url': '/products/{name}/{game}/{language}/{match}', 'method': 'get'}
expected_url = '/products/Jace%2C%20the%20Mind%20Sculptor/1/1/False'
Expand Down

0 comments on commit cfcc4eb

Please sign in to comment.