GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — v1 ( 120697...0b4edb )
by Maksim
01:20
created

MockerResourceWithNetworkClient   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 41
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setup_class() 0 15 1
A last_request() 0 2 1
A set_response() 0 10 2
A teardown_class() 0 5 1
1
# -*- coding: utf-8 -*-
2
3
import mock
4
5
6
class MockerResourceWithNetworkClient:
7
8
	resource_module = None
9
10
	mock_fluent_request_class = None
11
12
	@classmethod
13
	def setup_class(cls):
14
15
		# there are several similar modules-resources.
16
		# all we need to test them -- mock NetworkClient, to prevent
17
		# network access.
18
		# Let's do it with mock.patch.object
19
		#
20
		# Mocked client will be accessible in tests as `cls.client`
21
22
		# mock FluentRequest
23
		cls._patcher_fluent_request_class = mock.patch(
24
			'route4me.sdk._net.FluentRequest'
25
		)
26
		cls.mock_fluent_request_class = cls._patcher_fluent_request_class.start()
27
28
	@classmethod
29
	def teardown_class(cls):
30
		"""Teardown test environment for the entire class
31
		"""
32
		cls._patcher_fluent_request_class.stop()
33
34
	def set_response(self, status_code=200, data=None, **qw):
35
36
		x = mock.MagicMock()
37
		x.status_code = status_code
38
		x.json.return_value = data
39
40
		for k in qw:
41
			x.k = qw[k]
42
43
		self.mock_fluent_request_class.return_value.send.return_value = x
44
45
	def last_request(self):
46
		return self.mock_fluent_request_class.return_value
47