Passed
Push — master ( 77800a...b0712d )
by Vinicius
02:58 queued 12s
created

build.tests.helpers.get_controller_mock()   A

Complexity

Conditions 1

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nop 0
1
"""Module to help to create tests."""
2
3
4
def get_mocked_requests(_):
5
    """Mock requests.get."""
6
    return MockResponse(
7
        {
8
        },
9
        200,
10
    )
11
12
13
class MockResponse:
14
    """
15
    Mock a requests response object.
16
17
    Just define a function and add the patch decorator to the test.
18
    Example:
19
    def mocked_requests_get(*args, **kwargs):
20
        return MockResponse({}, 200)
21
    @patch('requests.get', side_effect=mocked_requests_get)
22
23
    """
24
25
    def __init__(self, json_data, status_code):
26
        """Create mock response object with parameters.
27
28
        Args:
29
            json_data: JSON response content
30
            status_code: HTTP status code.
31
        """
32
        self.json_data = json_data
33
        self.status_code = status_code
34
35
    def json(self):
36
        """Return the response json data."""
37
        return self.json_data
38
39
    def __str__(self):
40
        return self.__class__.__name__
41