Skip to content

Commit a67b707

Browse files
committed
Fixing test suite
1 parent 28d4414 commit a67b707

File tree

2 files changed

+87
-56
lines changed

2 files changed

+87
-56
lines changed

databox test/test_push.py

Lines changed: 67 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -19,55 +19,72 @@ def test_push(self):
1919
assert self.client.push("templj", 10.0) is True
2020
assert self.client.push("templj", 12.0, date="2015-01-01 09:00:00") is True
2121

22-
def test_push_validation(self):
23-
self.assertRaises(
24-
Client.KPIValidationException,
25-
lambda: self.client.push(None, None)
26-
)
27-
28-
def test_insert_all(self):
29-
assert self.client.insert_all([
30-
{'key': 'templj', 'value': 83.3},
22+
def test_push_with_attributes(self):
23+
self.client._push_json = lambda data=None, path='/': dict({
24+
'status': 'ok',
25+
}.items() + data.items())
26+
27+
push = self.client.push("meta", 100, attributes={
28+
'n': 100
29+
})
30+
31+
assert self.client.last_push_content['data'][0]['$meta'] == 100
32+
assert self.client.last_push_content['data'][0]['n'] == 100
33+
34+
35+
def test_push_validation(self):
36+
self.assertRaises(
37+
Client.KPIValidationException,
38+
lambda: self.client.push(None, None)
39+
)
40+
41+
42+
def test_insert_all(self):
43+
assert self.client.insert_all([
44+
{'key': 'templj', 'value': 83.3},
45+
{'key': 'templj', 'value': 83.3, 'date': "2015-01-01 09:00:00"},
46+
{'key': 'templj', 'value': 12.3},
47+
]) is True
48+
49+
self.assertRaises(
50+
Client.KPIValidationException,
51+
lambda: self.client.insert_all([
52+
{'value': 83.3},
3153
{'key': 'templj', 'value': 83.3, 'date': "2015-01-01 09:00:00"},
3254
{'key': 'templj', 'value': 12.3},
33-
]) is True
34-
35-
self.assertRaises(
36-
Client.KPIValidationException,
37-
lambda: self.client.insert_all([
38-
{'value': 83.3},
39-
{'key': 'templj', 'value': 83.3, 'date': "2015-01-01 09:00:00"},
40-
{'key': 'templj', 'value': 12.3},
41-
])
42-
)
43-
44-
def test_last_push(self):
45-
self.client._push_json = lambda data=None, path='/': {
46-
'err': [],
47-
'no_err': 0
48-
}
49-
50-
assert self.client.last_push()['err'] == []
51-
52-
def test_last_push_with_number(self):
53-
self.client._push_json = lambda data=None, path='/': path
54-
assert self.client.last_push(3) == '/lastpushes/3'
55-
56-
def test_short(self):
57-
Client._push_json = mock_push_json
58-
59-
assert push("templj", 22, token=self.databox_push_token) is True
60-
61-
assert insert_all([
62-
{
63-
'key': 'templj',
64-
'value': 83.3
65-
},
66-
], token=self.databox_push_token) is True
67-
68-
Client._push_json = lambda data=None, path='/': {
69-
'err': [],
70-
'no_err': 0
71-
}
72-
73-
assert last_push(token=self.databox_push_token)['err'] == []
55+
])
56+
)
57+
58+
59+
def test_last_push(self):
60+
self.client._push_json = lambda data=None, path='/': {
61+
'err': [],
62+
'no_err': 0
63+
}
64+
65+
assert self.client.last_push()['err'] == []
66+
67+
68+
def test_last_push_with_number(self):
69+
self.client._push_json = lambda data=None, path='/': path
70+
assert self.client.last_push(3) == '/lastpushes/3'
71+
72+
73+
def test_short(self):
74+
Client._push_json = mock_push_json
75+
76+
assert push("templj", 22, token=self.databox_push_token) is True
77+
78+
assert insert_all([
79+
{
80+
'key': 'templj',
81+
'value': 83.3
82+
},
83+
], token=self.databox_push_token) is True
84+
85+
Client._push_json = lambda data=None, path='/': {
86+
'err': [],
87+
'no_err': 0
88+
}
89+
90+
assert last_push(token=self.databox_push_token)['err'] == []

databox/__init__.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
class Client(object):
88
push_token = None
99
push_host = 'https://push2new.databox.com'
10+
last_push_content = None
1011

1112
class MissingToken(Exception):
1213
pass
@@ -58,15 +59,28 @@ def _push_json(self, data=None, path="/"):
5859

5960
return response.json()
6061

61-
def push(self, key, value, date=None):
62-
return self._push_json({
63-
'data': [self.process_kpi(key=key, value=value, date=date)]
64-
})['status'] == 'ok'
62+
63+
def push(self, key, value, date=None, attributes=None):
64+
self.last_push_content = self._push_json({
65+
'data': [self.process_kpi(
66+
key=key,
67+
value=value,
68+
date=date,
69+
attributes=attributes
70+
)]
71+
})
72+
73+
return self.last_push_content['status'] == 'ok'
74+
75+
6576

6677
def insert_all(self, rows):
67-
return self._push_json({
78+
self.last_push_content = self._push_json({
6879
'data': [self.process_kpi(**row) for row in rows]
69-
})['status'] == 'ok'
80+
})
81+
82+
return self.last_push_content['status'] == 'ok'
83+
7084

7185
def last_push(self, number=1):
7286
return self._push_json(path='/lastpushes/{n}'.format(**{'n': number}))

0 commit comments

Comments
 (0)