-
Notifications
You must be signed in to change notification settings - Fork 70
/
conftest.py
57 lines (42 loc) · 1.15 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import mock
import pytest
import requests as requests_lib
import requests_mock
@pytest.yield_fixture
def requests():
with requests_mock.Mocker() as m:
yield m
@pytest.fixture
def cpp(monkeypatch):
printers = {}
def add_printer(name):
printer = mock.Mock(name='cpp printer ' + name)
printer.name = name
printers[name] = printer
return printer
cpp = mock.Mock(name='cpp')
cpp.auth.session = requests_lib
cpp.get_printers.side_effect = lambda: list(printers.values())
cpp.include = []
cpp.exclude = []
def get_printer_info(cpp, name):
try:
printer = printers[name]
return printer.ppd, printer.description
except KeyError:
return None, None
monkeypatch.setattr(
'cloudprint.cloudprint.get_printer_info',
get_printer_info,
)
cpp.test_add_printer = add_printer
return cpp
@pytest.fixture
def cups():
printers = {}
def add_printer(name):
printers[name] = 1
cups = mock.Mock(name='cups')
cups.getPrinters.side_effect = printers.copy
cups.test_add_printer = add_printer
return cups