forked from singer-io/singer-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_catalog.py
More file actions
144 lines (132 loc) · 5.31 KB
/
test_catalog.py
File metadata and controls
144 lines (132 loc) · 5.31 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import unittest
from singer.schema import Schema
from singer.catalog import Catalog, CatalogEntry, write_catalog
class TestWriteCatalog(unittest.TestCase):
def test_write_empty_catalog(self):
catalog = Catalog([])
write_catalog(catalog)
def test_write_catalog_with_streams(self):
catalog = Catalog([CatalogEntry(tap_stream_id='a',schema=Schema(),metadata=[])])
write_catalog(catalog)
class TestGetSelectedStreams(unittest.TestCase):
def test_one_selected_stream(self):
selected_entry = CatalogEntry(tap_stream_id='a',
schema=Schema(),
metadata=[{'metadata':
{'selected': True},
'breadcrumb': []}])
catalog = Catalog(
[selected_entry,
CatalogEntry(tap_stream_id='b',schema=Schema(),metadata=[]),
CatalogEntry(tap_stream_id='c',schema=Schema(),metadata=[])])
state = {}
selected_streams = catalog.get_selected_streams(state)
self.assertEquals([e for e in selected_streams],[selected_entry])
def test_resumes_currently_syncing_stream(self):
selected_entry_a = CatalogEntry(tap_stream_id='a',
schema=Schema(),
metadata=[{'metadata':
{'selected': True},
'breadcrumb': []}])
selected_entry_c = CatalogEntry(tap_stream_id='c',
schema=Schema(),
metadata=[{'metadata':
{'selected': True},
'breadcrumb': []}])
catalog = Catalog(
[selected_entry_a,
CatalogEntry(tap_stream_id='b',schema=Schema(),metadata=[]),
selected_entry_c])
state = {'currently_syncing': 'c'}
selected_streams = catalog.get_selected_streams(state)
self.assertEquals([e for e in selected_streams][0],selected_entry_c)
class TestToDictAndFromDict(unittest.TestCase):
dict_form = {
'streams': [
{
'stream': 'users',
'tap_stream_id': 'prod_users',
'stream_alias': 'users_alias',
'database_name': 'prod',
'table_name': 'users',
'schema': {
'type': 'object',
'selected': True,
'properties': {
'id': {'type': 'integer', 'selected': True},
'name': {'type': 'string', 'selected': True}
}
},
'metadata': [
{
'metadata': {
'metadata-key': 'metadata-value'
},
'breadcrumb': [
'properties',
'name',
],
},
],
},
{
'stream': 'orders',
'tap_stream_id': 'prod_orders',
'database_name': 'prod',
'table_name': 'orders',
'schema': {
'type': 'object',
'selected': True,
'properties': {
'id': {'type': 'integer', 'selected': True},
'amount': {'type': 'number', 'selected': True}
}
}
}
]
}
obj_form = Catalog(streams=[
CatalogEntry(
stream='users',
tap_stream_id='prod_users',
stream_alias='users_alias',
database='prod',
table='users',
schema=Schema(
type='object',
selected=True,
properties={
'id': Schema(type='integer', selected=True),
'name': Schema(type='string', selected=True)}),
metadata=[{
'metadata': {
'metadata-key': 'metadata-value'
},
'breadcrumb': [
'properties',
'name',
],
}]),
CatalogEntry(
stream='orders',
tap_stream_id='prod_orders',
database='prod',
table='orders',
schema=Schema(
type='object',
selected=True,
properties={
'id': Schema(type='integer', selected=True),
'amount': Schema(type='number', selected=True)}))])
def test_from_dict(self):
self.assertEqual(self.obj_form, Catalog.from_dict(self.dict_form))
def test_to_dict(self):
self.assertEqual(self.dict_form, self.obj_form.to_dict())
class TestGetStream(unittest.TestCase):
def test(self):
catalog = Catalog(
[CatalogEntry(tap_stream_id='a'),
CatalogEntry(tap_stream_id='b'),
CatalogEntry(tap_stream_id='c')])
entry = catalog.get_stream('b')
self.assertEquals('b', entry.tap_stream_id)