forked from tagtoo-bryan/python-bigquery-logger
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlogger_test.py
63 lines (53 loc) · 1.76 KB
/
logger_test.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
58
59
60
61
62
import unittest
from mock import *
from bigquery_logger import BigQueryClient, BigQueryHandler
class TestBigqueryLogger(unittest.TestCase):
def setUp(self):
self.mock_service = Mock()
self.mock_tabledata = Mock()
self.mock_service.tabledata.return_value = self.mock_tabledata
self.project_id = 'project_id'
self.dataset_id = 'dataset_id'
self.table_id = 'table_id'
self.record = 'logging record'
self.body = {
"kind": "bigquery#tableDataInsertAllRequest",
"rows": [{
"json": {'logging': self.record}
}]
}
def tearDown(self):
pass
def test_bigquerh_insertall(self):
self.mock_tabledata.insertAll.return_value.execute.return_value = {
"kind": "my#tableDataInsertAllResponse",
}
import logging
record = logging.LogRecord(
name = "test-name",
level = logging.DEBUG,
pathname = 'test-path-name',
lineno = 1,
msg = 'test-msg',
args = {},
exc_info = None
)
handler = BigQueryHandler(
self.mock_service,
self.project_id,
self.dataset_id,
self.table_id
)
handler.handle(record)
handler.flush()
# this part need to rewrite
# # self.assertEqual(response, {"kind": "my#tableDataInsertAllResponse"})
# self.mock_service.tabledata.assert_called_with()
# self.mock_tabledata.insertAll.assert_called_with(
# projectId = self.project_id,
# datasetId = self.dataset_id,
# tableId = self.table_id,
# body = self.body
# )
if __name__ == '__main__':
unittest.main()