FakeAPITestCase   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 21
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 2 1
A fake_endpoint() 0 12 2
A tearDown() 0 3 1
1
# -*- coding: utf-8 -*-
2
#
3
# Copyright (c) 2013-2016 Online SAS and Contributors. All Rights Reserved.
4
#                         Julien Castets <[email protected]>
5
#                         Kevin Deldycke <[email protected]>
6
#
7
# Licensed under the BSD 2-Clause License (the "License"); you may not use this
8
# file except in compliance with the License. You may obtain a copy of the
9
# License at https://opensource.org/licenses/BSD-2-Clause
10
11
import json
12
13
import httpretty
14
from six.moves.urllib.parse import urljoin
15
16
17
class FakeAPITestCase(object):
18
19
    def setUp(self):
20
        httpretty.enable()
21
22
    def tearDown(self):
23
        httpretty.disable()
24
        httpretty.reset()
25
26
    def fake_endpoint(self, api, endpoint, method=httpretty.GET,
27
                      body=None, status=200):
28
29
        if not callable(body):
30
            body = json.dumps(body)
31
32
        httpretty.register_uri(
33
            method,
34
            urljoin(api.get_api_url(), endpoint),
35
            body=body,
36
            content_type='application/json',
37
            status=status
38
        )
39