from osmaxx.api_client.API_client import RESTApiJWTClient
from requests_mock import ANY


def test_get_requests_combined_url(requests_mock):
    """
    The requested URL is the concatenation of
    the service_base of the RESTApiJWTClient instance and
    the relative URL passed to RESTApiJWTClient.get().
    """
    requests_mock.get(ANY, json={'some response': 'you got it'})
    c = RESTApiJWTClient('http://example.com/service/uri_base/')
    response = c.get('get/example')
    assert response.request.url == 'http://example.com/service/uri_base/get/example'


def test_get_specifies_body_content_type(requests_mock):
    # FIXME: Does this make any sense?
    # As far as I can tell, the 'Content-Type' in the request headers specifies
    # the content type of the body of the request, not of the body of the response.
    # While GET requests can have a body (which the server should ignore if present),
    # we don't send a body in the request. Specifying an absent body's content type
    # seems rather nonsensical.
    requests_mock.get(ANY, json={'some response': 'you got it'})
    c = RESTApiJWTClient('http://example.com/service/uri_base/')
    response = c.get('get/example')
    assert response.request.headers['Content-Type'] == 'application/json; charset=UTF-8'


def test_get_returns_received_response(requests_mock):
    requests_mock.get(ANY, json={'some response': 'you got it'})
    c = RESTApiJWTClient('http://example.com/service/uri_base/')
    response = c.get('get/example')
    assert response.json() == {'some response': 'you got it'}


def test_post_performs_request(requests_mock):
    requests_mock.post(ANY, json={'some response': 'you posted it'})
    c = RESTApiJWTClient('http://example.com/service/uri_base/')
    response = c.post('post/example', json_data={'pay': 'load'})
    assert response.request.url == 'http://example.com/service/uri_base/post/example'
    assert response.request.headers['Content-Type'] == 'application/json; charset=UTF-8'
    assert response.request.json() == {'pay': 'load'}
    assert response.json() == {'some response': 'you posted it'}

from osmaxx.api_client.API_client import RESTApiJWTClient
from requests_mock import ANY


def test_get_requests_combined_url(requests_mock):
    """
    The requested URL is the concatenation of
    the service_base of the RESTApiJWTClient instance and
    the relative URL passed to RESTApiJWTClient.get().
    """
    requests_mock.get(ANY)
    c = RESTApiJWTClient('http://example.com/service/uri_base/')
    response = c.get('get/example')
    assert response.request.url == 'http://example.com/service/uri_base/get/example'


def test_get_specifies_body_content_type(requests_mock):
    # FIXME: Does this make any sense?
    # As far as I can tell, the 'Content-Type' in the request headers specifies
    # the content type of the body of the request, not of the body of the response.
    # While GET requests can have a body (which the server should ignore if present),
    # we don't send a body in the request. Specifying an absent body's content type
    # seems rather nonsensical.
    requests_mock.get(ANY)
    c = RESTApiJWTClient('http://example.com/service/uri_base/')
    response = c.get('get/example')
    assert response.request.headers['Content-Type'] == 'application/json; charset=UTF-8'


def test_get_returns_received_response(requests_mock):
    requests_mock.get(ANY, json={'some response': 'you got it'})
    c = RESTApiJWTClient('http://example.com/service/uri_base/')
    response = c.get('get/example')
    assert response.json() == {'some response': 'you got it'}


def test_post_performs_request(requests_mock):
    requests_mock.post(ANY, json={'some response': 'you posted it'})
    c = RESTApiJWTClient('http://example.com/service/uri_base/')
    response = c.post('post/example', json_data={'pay': 'load'})
    assert response.request.url == 'http://example.com/service/uri_base/post/example'
    assert response.request.headers['Content-Type'] == 'application/json; charset=UTF-8'
    assert response.request.json() == {'pay': 'load'}
    assert response.json() == {'some response': 'you posted it'}

remove unnecessary response body from request registration