"""Test the conductor REST module."""

from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import

from _pytest.python import raises
from future import standard_library

standard_library.install_aliases()

from responses import activate, GET, POST, add
from pytest import mark

from gobble.config import OS_URL
from gobble.conductor import API, build_api_request


request_functions = [
    ('authorize_user', '/user/authorize', GET),
    ('oauth_callback', '/oauth/callback', GET),
    ('update_user', '/user/update', POST),
    ('search_users', '/search/user', GET),
    ('search_packages', '/search/package', GET),
    ('prepare_upload', '/datastore/', POST)
]


@activate
@mark.parametrize('function, endpoint, verb', request_functions)
def test_api_requests_hit_correct_endpoints(function, endpoint, verb):
    endpoint_url = OS_URL + endpoint
    # Mock the request with responses
    add(verb, endpoint_url, status=200)
    response = getattr(API, function)()
    assert response.status_code == 200


def test_passing_endpoint_item_not_string_raises_type_error():
    with raises(TypeError):
        build_api_request('GET', 1000)()


def test_build_api_request_with_invalid_verb_raise_assertion_error():
    with raises(AssertionError):
        build_api_request('BAR', 'foo')

"""Test the conductor REST module."""

from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import

from _pytest.python import raises
from future import standard_library

standard_library.install_aliases()

import responses
import pytest

from gobble.config import OS_URL
from gobble.conductor import API, build_api_request

request_functions = [
    ('authorize_user', '/user/authorize', 'GET'),
    ('oauth_callback', '/oauth/callback', 'GET'),
    ('update_user', '/user/update', 'POST'),
    ('search_users', '/search/user', 'GET'),
    ('search_packages', '/search/package', 'GET'),
    ('prepare_upload', '/datastore/', 'POST')
]


@responses.activate
@pytest.mark.parametrize('function, endpoint, verb', request_functions)
def test_api_requests_hit_correct_endpoints(function, endpoint, verb):
    endpoint_url = OS_URL + endpoint
    # Mock the request with responses
    responses.add(verb, endpoint_url, status=200)
    response = getattr(API, function)()
    assert response.status_code == 200


def test_passing_endpoint_item_not_string_raises_type_error():
    with raises(TypeError):
        build_api_request('GET', 1000)()


def test_build_api_request_with_invalid_verb_raise_assertion_error():
    with raises(AssertionError):
        build_api_request('BAR', 'foo')

Switch to module imports for readability.