Passed
Push — master ( a90ba0...0fd7f1 )
by Abouzar
02:13
created

tests.test_client.TestClient.send()   C

Complexity

Conditions 9

Size

Total Lines 29
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 27
nop 5
dl 0
loc 29
rs 6.6666
c 0
b 0
f 0
1
from base64 import b64encode
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2
from werkzeug.exceptions import HTTPException
3
import json
0 ignored issues
show
introduced by
standard import "import json" should be placed before "from werkzeug.exceptions import HTTPException"
Loading history...
4
5
6
class TestClient():
0 ignored issues
show
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
7
  def __init__(self, app, username, password):
8
    self.app = app
9
    if username is None:
10
      self.auth = None
11
    else:
12
      self.auth = 'Basic ' + b64encode(
13
          (username + ':' + password).encode('utf-8')).decode('utf-8')
14
15
  def send(self, url, method='GET', data=None, headers=None):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
16
    if headers is None:
17
      headers = {}
18
    headers = headers.copy()
19
    if self.auth is not None:
20
      headers['Authorization'] = self.auth
21
    headers['Content-Type'] = 'application/json'
22
    headers['Accept'] = 'application/json'
23
    if data:
24
      data = json.dumps(data)
25
26
    with self.app.test_request_context(
27
        url, method=method, data=data, headers=headers):
28
      try:
29
        rv = self.app.preprocess_request()
0 ignored issues
show
Coding Style Naming introduced by
The name rv does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
30
        if rv is None:
31
          rv = self.app.dispatch_request()
0 ignored issues
show
Coding Style Naming introduced by
The name rv does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
32
        rv = self.app.make_response(rv)
0 ignored issues
show
Coding Style Naming introduced by
The name rv does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
33
        rv = self.app.process_response(rv)
0 ignored issues
show
Coding Style Naming introduced by
The name rv does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
34
      except HTTPException as e:
0 ignored issues
show
Coding Style Naming introduced by
The name e does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
35
        rv = self.app.handle_user_exception(e)
0 ignored issues
show
Coding Style Naming introduced by
The name rv does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
36
37
    try:
38
      json_data = json.loads(rv.data.decode('utf-8'))
39
    except AttributeError:
40
      json_data = None
41
    except json.decoder.JSONDecodeError:
42
      json_data = None
43
    return rv, json_data
44
45
  def get(self, url, headers=None):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
46
    if headers is None:
47
      headers = {}
48
    return self.send(url, 'GET', headers=headers)
49
50
  def post(self, url, data, headers=None):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
51
    if headers is None:
52
      headers = {}
53
    return self.send(url, 'POST', data, headers=headers)
54
55
  def put(self, url, data, headers=None):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
56
    if headers is None:
57
      headers = {}
58
    return self.send(url, 'PUT', data, headers=headers)
59
60
  def delete(self, url, headers=None):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
61
    if headers is None:
62
      headers = {}
63
    return self.send(url, 'DELETE', headers=headers)
64
65
  def head(self, url, headers=None):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
66
    if headers is None:
67
      headers = {}
68
    return self.send(url, 'HEAD', headers=headers)
69