Example #1
0
def test_raises_for_status(response_mock):
    with mock.patch.object(requests.Session, 'get',
                           return_value=response_mock):
        c = CatmaidClient(BASE_URL)
        c.fetch('relative', 'GET')

    response_mock.raise_for_status.assert_called()
Example #2
0
def test_raises_on_wrapped_error(response_mock):
    with mock.patch.object(requests.Session, 'get', return_value=response_mock), \
          mock.patch.object(WrappedCatmaidException, 'raise_on_error') as raise_on_error:
        c = CatmaidClient(BASE_URL)
        c.fetch('relative', 'GET')

    raise_on_error.assert_called_with(response_mock)
Example #3
0
def test_raises_on_wrapped_error(response_mock):
    with mock.patch.object(
        requests.Session, "get", return_value=response_mock
    ), mock.patch.object(WrappedCatmaidException, "raise_for_status") as raise_on_error:
        c = CatmaidClient(BASE_URL)
        c.fetch("relative", "GET")

    raise_on_error.assert_called_with(response_mock)
Example #4
0
def test_response_raw_no_deserialise(response_mock):
    response_mock.text = "text"
    with mock.patch.object(requests.Session, "get", return_value=response_mock):
        c1 = CatmaidClient(BASE_URL)
        c1.fetch("relative", "GET", raw=False)
        count_not_raw = response_mock.json.call_count
        response_mock.json.reset_mock()
        ret = c1.fetch("relative", "GET", raw=True)
        count_raw = response_mock.json.call_count

    assert count_not_raw == count_raw + 1
    assert ret == "text"
Example #5
0
def test_fetch_uses_session(response_mock):
    url = make_url(BASE_URL, "relative")
    with mock.patch.object(requests.Session, "get", return_value=response_mock) as get:
        c = CatmaidClient(BASE_URL)
        c.fetch("relative", "GET")

    get.assert_called_with(url, params={})

    with mock.patch.object(
        requests.Session, "post", return_value=response_mock
    ) as post:
        c = CatmaidClient(BASE_URL)
        c.fetch("relative", "POST")

    post.assert_called_with(url, data={})
Example #6
0
def test_fetch_uses_session(response_mock):
    url = make_url(BASE_URL, 'relative')
    with mock.patch.object(requests.Session, 'get',
                           return_value=response_mock) as get:
        c = CatmaidClient(BASE_URL)
        c.fetch('relative', 'GET')

    get.assert_called_with(url, params={})

    with mock.patch.object(requests.Session,
                           'post',
                           return_value=response_mock) as post:
        c = CatmaidClient(BASE_URL)
        c.fetch('relative', 'POST')

    post.assert_called_with(url, data={})
Example #7
0
def test_response_json(response_mock, valid_response_dict):
    response_mock.json.return_value = valid_response_dict
    with mock.patch.object(requests.Session, "get", return_value=response_mock):
        c = CatmaidClient(BASE_URL)
        ret = c.fetch("relative", "GET")

    assert ret == valid_response_dict