forked from openprocurement/openregistry.concierge
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
71 lines (57 loc) · 1.7 KB
/
Copy pathconftest.py
File metadata and controls
71 lines (57 loc) · 1.7 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# -*- coding: utf-8 -*-
import logging
import pytest
from StringIO import StringIO
from openregistry.concierge.worker import BotWorker, logger as LOGGER
TEST_CONFIG = {
"db": {
"host": "127.0.0.1",
"name": "lots_db",
"port": "5984",
"login": "",
"password": "",
"filter": "lots/status"
},
"errors_doc": "broken_lots",
"time_to_sleep": 2,
"lots": {
"api": {
"url": "http://192.168.50.9",
"token": "concierge",
"version": 0
}
},
"assets": {
"api": {
"url": "http://192.168.50.9",
"token": "concierge",
"version": 0
}
}
}
@pytest.fixture(scope='function')
def bot(mocker):
mocker.patch('openregistry.concierge.worker.LotsClient', autospec=True)
mocker.patch('openregistry.concierge.worker.AssetsClient', autospec=True)
return BotWorker(TEST_CONFIG)
class LogInterceptor(object):
def __init__(self, logger):
self.log_capture_string = StringIO()
self.test_handler = logging.StreamHandler(self.log_capture_string)
self.test_handler.setLevel(logging.INFO)
logger.addHandler(self.test_handler)
@pytest.fixture(scope='function')
def logger():
return LogInterceptor(LOGGER)
class AlmostAlwaysTrue(object):
def __init__(self, total_iterations=1):
self.total_iterations = total_iterations
self.current_iteration = 0
def __nonzero__(self):
if self.current_iteration < self.total_iterations:
self.current_iteration += 1
return bool(1)
return bool(0)
@pytest.fixture(scope='function')
def almost_always_true():
return AlmostAlwaysTrue