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

build.tests.helpers   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 13
dl 0
loc 41
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A MockResponse.__str__() 0 2 1
A MockResponse.__init__() 0 9 1
A MockResponse.json() 0 3 1

1 Function

Rating   Name   Duplication   Size   Complexity  
A get_mocked_requests() 0 6 1
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