File: conftest.py

package info (click to toggle)
python-globus-sdk 4.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,172 kB
  • sloc: python: 35,227; sh: 44; makefile: 35
file content (57 lines) | stat: -rw-r--r-- 1,306 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from unittest import mock

import pytest
import responses

import globus_sdk


@pytest.fixture(autouse=True)
def mocksleep():
    with mock.patch("time.sleep") as m:
        yield m


@pytest.fixture(autouse=True)
def mocked_responses():
    """
    All tests enable `responses` patching of the `requests` package, replacing
    all HTTP calls.
    """
    responses.start()

    yield

    responses.stop()
    responses.reset()


@pytest.fixture
def make_response():
    def _make_response(
        response_class=None,
        status=200,
        headers=None,
        json_body=None,
        text=None,
        client=None,
    ):
        """
        Construct and return an SDK response object with a mocked requests.Response

        Unlike mocking of an API route, this is meant for unit testing in which we
        want to directly create the response.
        """
        from tests.common import PickleableMockResponse

        r = PickleableMockResponse(
            status, headers=headers, json_body=json_body, text=text
        )
        http_res = globus_sdk.GlobusHTTPResponse(
            r, client=client if client is not None else mock.Mock()
        )
        if response_class is not None:
            return response_class(http_res)
        return http_res

    return _make_response