-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtest_gsheet_loader.py
88 lines (70 loc) · 2.51 KB
/
test_gsheet_loader.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# coding=utf-8
import unittest
from tap_gsheets.gsheet_loader import GSheetsLoader
import json
import os
import base64
test_config = {
"type": "service_account",
"project_id": os.getenv('PROJECT_ID'),
"private_key_id": os.getenv('PRIVATE_KEY_ID'),
"private_key": base64.b64decode(os.getenv('PRIVATE_KEY')),
"client_email": os.getenv('CLIENT_EMAIL'),
"client_id": os.getenv('CLIENT_ID'),
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": os.getenv('CERT_URL')
}
class TestSum(unittest.TestCase):
def test_authentication(self):
"""
Test that we are able to authenitcate provided some valid configs
are passed
"""
GSheetsLoader(test_config).client.session.close()
def test_get_schema(self):
"""
Test that the tap is able to infer a simple schema from a sample sheet
"""
loader = GSheetsLoader(test_config)
expected_schema = {
"properties": {
"ID": {"type": "integer"},
"Name": {"type": "string"},
"RegisteredAt": {"type": "string"}
},
"type": "object"
}
self.assertEqual(
expected_schema,
loader.get_schema('Tap Gsheets Integration Tests')
)
loader.client.session.close()
def test_get_data(self):
"""
Test that the tap outputs the expected sheet contents
"""
loader = GSheetsLoader(test_config)
expected_contents = [
{'ID': 30, 'Name': 'Napoleón Bonaparte', 'RegisteredAt': '2019-03-04'},
{'ID': 50, 'Name': 'San Juan Bautista', 'RegisteredAt': '2019-04-02'}
]
self.assertEqual(
expected_contents,
loader.get_records_as_json('Tap Gsheets Integration Tests')
)
loader.client.session.close()
def test_worksheet(self):
"""Test that worksheet selection"""
loader = GSheetsLoader(test_config)
self.assertEqual(
[
{'ID': 30, 'Name': 'Bon Jovi', 'RegisteredAt': '2019-03-04'},
{'ID': 50, 'Name': 'Cat Stevens', 'RegisteredAt': '2019-04-02'}
],
loader.get_records_as_json('Tap Gsheets Integration Tests', 'OtherWorksheet')
)
loader.client.session.close()
if __name__ == '__main__':
unittest.main()