1
1
from basedosdados .backend import Backend
2
2
3
+ backend = Backend ()
4
+
3
5
4
6
def test_get_dataset ():
5
7
"""
6
8
Test dataset output without parameters
7
9
"""
8
10
9
- backend = Backend ()
10
-
11
11
out = backend .get_datasets ()
12
12
assert isinstance (out , dict )
13
13
assert len (out ) != 0
@@ -19,8 +19,6 @@ def test_get_dataset_with_input():
19
19
Test dataset output with input
20
20
"""
21
21
22
- backend = Backend ()
23
-
24
22
out = backend .get_datasets (dataset_name = "br_me_caged" )
25
23
assert isinstance (out , dict )
26
24
assert len (out ) != 0
@@ -32,8 +30,6 @@ def test_get_tables():
32
30
Test tables output without parameters
33
31
"""
34
32
35
- backend = Backend ()
36
-
37
33
out = backend .get_tables ()
38
34
assert isinstance (out , dict )
39
35
assert len (out ) != 0
@@ -46,8 +42,6 @@ def test_get_tables_with_input():
46
42
Test tables output with input
47
43
"""
48
44
49
- backend = Backend ()
50
-
51
45
out = backend .get_tables (table_name = "br_me_caged" )
52
46
assert isinstance (out , dict )
53
47
assert len (out ) != 0
@@ -60,8 +54,6 @@ def test_get_columns():
60
54
Test columns output without parameters
61
55
"""
62
56
63
- backend = Backend ()
64
-
65
57
out = backend .get_columns ()
66
58
assert isinstance (out , dict )
67
59
assert len (out ) != 0
@@ -74,36 +66,34 @@ def test_get_columns_with_input():
74
66
Test columns output with input
75
67
"""
76
68
77
- backend = Backend ()
78
-
79
69
out = backend .get_columns (column_name = "description" )
80
70
assert isinstance (out , dict )
81
71
assert len (out ) != 0
82
72
assert out ["page_size" ] >= 10
83
73
assert out ["page_total" ] > 0
84
74
85
75
86
- def test_search ():
76
+ def test_search (capsys ):
87
77
"""
88
78
Test search output without parameters
89
79
"""
90
80
91
- backend = Backend ()
92
-
93
81
out = backend .search ()
82
+ _ , res = capsys .readouterr ()
83
+ print ("TEST SEARCH WITH INPUT" , res )
94
84
assert isinstance (out , dict )
95
85
assert len (out ) != 0
96
86
assert out ["page_size" ] > 1
97
87
98
88
99
- def test_search_with_input ():
89
+ def test_search_with_input (capsys ):
100
90
"""
101
91
Test search output with input
102
92
"""
103
93
104
- backend = Backend ()
105
-
106
94
out = backend .search (q = "description" )
95
+ _ , res = capsys .readouterr ()
96
+ print ("TEST SEARCH WITH INPUT" , res )
107
97
assert isinstance (out , dict )
108
98
assert len (out ) != 0
109
99
assert out ["page_size" ] >= 10
@@ -113,7 +103,6 @@ def test_get_dataset_config():
113
103
"""
114
104
Test get_dataset_config output
115
105
"""
116
- backend = Backend ()
117
106
118
107
out = backend .get_dataset_config (dataset_id = "br_me_rais" )
119
108
assert isinstance (out , dict )
@@ -126,14 +115,10 @@ def test_get_table_config():
126
115
"""
127
116
Test get_dataset_config output
128
117
"""
129
- backend = Backend ()
130
118
131
119
out = backend .get_table_config (
132
120
dataset_id = "br_me_rais" , table_id = "microdados_estabelecimentos"
133
121
)
134
- print (out )
135
- print (len (out ))
136
- print (type (out ))
137
122
assert isinstance (out , dict )
138
123
assert len (out ) > 0
139
124
assert out != ""
@@ -144,7 +129,6 @@ def test_get_dataset_id_from_name():
144
129
"""
145
130
Test get dataset id from name
146
131
"""
147
- backend = Backend ()
148
132
149
133
out = backend ._get_dataset_id_from_name ("br_me_rais" )
150
134
assert isinstance (out , str )
@@ -156,7 +140,6 @@ def test_get_table_id_from_name():
156
140
"""
157
141
Test get table id from name
158
142
"""
159
- backend = Backend ()
160
143
161
144
out = backend ._get_table_id_from_name (
162
145
"br_me_rais" , "microdados_estabelecimentos"
@@ -170,45 +153,45 @@ def test_execute_query():
170
153
"""
171
154
Test execute query
172
155
"""
173
- backend = Backend ()
156
+
174
157
example = {"items" : [], "page" : 1 , "page_size" : 10 , "page_total" : 0 }
175
158
query = """
176
- query {
177
- allDataset(first: 5, offset: 10) {
178
- edges {
179
- node {
180
- slug
181
- name
182
- description
183
- organizations {
184
- edges {
185
- node {
186
- name
187
- }
159
+ query {
160
+ allDataset(first: 5, offset: 10) {
161
+ edges {
162
+ node {
163
+ slug
164
+ name
165
+ description
166
+ organizations {
167
+ edges {
168
+ node {
169
+ name
188
170
}
189
171
}
190
- tags {
191
- edges {
192
- node {
193
- name
194
- }
172
+ }
173
+ tags {
174
+ edges {
175
+ node {
176
+ name
195
177
}
196
178
}
197
- themes {
198
- edges {
199
- node {
200
- name
201
- }
179
+ }
180
+ themes {
181
+ edges {
182
+ node {
183
+ name
202
184
}
203
185
}
204
- createdAt
205
- updatedAt
206
186
}
187
+ createdAt
188
+ updatedAt
207
189
}
208
- totalCount
209
190
}
191
+ totalCount
210
192
}
211
- """
193
+ }
194
+ """
212
195
out = backend ._execute_query (query , example )
213
196
assert isinstance (out , dict )
214
197
assert len (out ) != 0
@@ -220,11 +203,7 @@ def test_simplify_response():
220
203
Test simplify query
221
204
"""
222
205
223
- backend = Backend ()
224
206
response = {"items" : [], "page" : 1 , "page_size" : 10 , "page_total" : 0 }
225
207
out = backend ._simplify_response (response )
226
- print (out )
227
- print (type (out ))
228
- print (len (out ))
229
208
assert isinstance (out , dict )
230
209
assert len (out ) != 0
0 commit comments