Skip to content

Commit f5447da

Browse files
Tests: upload (#1753)
* test: test_upload/dataset.py * test: test_upload/dataset.py remove unecessary imports * test: adjust spacement and comments * tests: add some tests for upload * tests: fix lint in publish table.py * tests: add more tests in test_table.py and fix in test_storage.py * tests: last tests for table.py * tests: testing utils.py * ruff fixes * adjust ruff formatter in files
1 parent 1183da4 commit f5447da

File tree

14 files changed

+52348
-60
lines changed

14 files changed

+52348
-60
lines changed

python-package/basedosdados/upload/table.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ def update(self, mode="prod", custom_schema=None):
732732
)
733733

734734
def publish(
735-
self, if_exists="raise", custon_publish_sql=None, custom_schema=None
735+
self, if_exists="raise", custom_publish_sql=None, custom_schema=None
736736
):
737737
"""Creates BigQuery table at production dataset.
738738
@@ -765,13 +765,13 @@ def publish(
765765
publish_sql = self._make_publish_sql()
766766

767767
# create view using API metadata
768-
if custon_publish_sql is None:
768+
if custom_publish_sql is None:
769769
self.client["bigquery_prod"].query(publish_sql).result()
770770
self.update(mode="prod")
771771

772772
# create view using custon query
773-
if custon_publish_sql is not None:
774-
self.client["bigquery_prod"].query(custon_publish_sql).result()
773+
if custom_publish_sql is not None:
774+
self.client["bigquery_prod"].query(custom_publish_sql).result()
775775
# update schema using a custom schema
776776
if custom_schema is not None:
777777
self.update(custom_schema=custom_schema)

python-package/tests/test_backend.py

Lines changed: 35 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
from basedosdados.backend import Backend
22

3+
backend = Backend()
4+
35

46
def test_get_dataset():
57
"""
68
Test dataset output without parameters
79
"""
810

9-
backend = Backend()
10-
1111
out = backend.get_datasets()
1212
assert isinstance(out, dict)
1313
assert len(out) != 0
@@ -19,8 +19,6 @@ def test_get_dataset_with_input():
1919
Test dataset output with input
2020
"""
2121

22-
backend = Backend()
23-
2422
out = backend.get_datasets(dataset_name="br_me_caged")
2523
assert isinstance(out, dict)
2624
assert len(out) != 0
@@ -32,8 +30,6 @@ def test_get_tables():
3230
Test tables output without parameters
3331
"""
3432

35-
backend = Backend()
36-
3733
out = backend.get_tables()
3834
assert isinstance(out, dict)
3935
assert len(out) != 0
@@ -46,8 +42,6 @@ def test_get_tables_with_input():
4642
Test tables output with input
4743
"""
4844

49-
backend = Backend()
50-
5145
out = backend.get_tables(table_name="br_me_caged")
5246
assert isinstance(out, dict)
5347
assert len(out) != 0
@@ -60,8 +54,6 @@ def test_get_columns():
6054
Test columns output without parameters
6155
"""
6256

63-
backend = Backend()
64-
6557
out = backend.get_columns()
6658
assert isinstance(out, dict)
6759
assert len(out) != 0
@@ -74,36 +66,34 @@ def test_get_columns_with_input():
7466
Test columns output with input
7567
"""
7668

77-
backend = Backend()
78-
7969
out = backend.get_columns(column_name="description")
8070
assert isinstance(out, dict)
8171
assert len(out) != 0
8272
assert out["page_size"] >= 10
8373
assert out["page_total"] > 0
8474

8575

86-
def test_search():
76+
def test_search(capsys):
8777
"""
8878
Test search output without parameters
8979
"""
9080

91-
backend = Backend()
92-
9381
out = backend.search()
82+
_, res = capsys.readouterr()
83+
print("TEST SEARCH WITH INPUT", res)
9484
assert isinstance(out, dict)
9585
assert len(out) != 0
9686
assert out["page_size"] > 1
9787

9888

99-
def test_search_with_input():
89+
def test_search_with_input(capsys):
10090
"""
10191
Test search output with input
10292
"""
10393

104-
backend = Backend()
105-
10694
out = backend.search(q="description")
95+
_, res = capsys.readouterr()
96+
print("TEST SEARCH WITH INPUT", res)
10797
assert isinstance(out, dict)
10898
assert len(out) != 0
10999
assert out["page_size"] >= 10
@@ -113,7 +103,6 @@ def test_get_dataset_config():
113103
"""
114104
Test get_dataset_config output
115105
"""
116-
backend = Backend()
117106

118107
out = backend.get_dataset_config(dataset_id="br_me_rais")
119108
assert isinstance(out, dict)
@@ -126,14 +115,10 @@ def test_get_table_config():
126115
"""
127116
Test get_dataset_config output
128117
"""
129-
backend = Backend()
130118

131119
out = backend.get_table_config(
132120
dataset_id="br_me_rais", table_id="microdados_estabelecimentos"
133121
)
134-
print(out)
135-
print(len(out))
136-
print(type(out))
137122
assert isinstance(out, dict)
138123
assert len(out) > 0
139124
assert out != ""
@@ -144,7 +129,6 @@ def test_get_dataset_id_from_name():
144129
"""
145130
Test get dataset id from name
146131
"""
147-
backend = Backend()
148132

149133
out = backend._get_dataset_id_from_name("br_me_rais")
150134
assert isinstance(out, str)
@@ -156,7 +140,6 @@ def test_get_table_id_from_name():
156140
"""
157141
Test get table id from name
158142
"""
159-
backend = Backend()
160143

161144
out = backend._get_table_id_from_name(
162145
"br_me_rais", "microdados_estabelecimentos"
@@ -170,45 +153,45 @@ def test_execute_query():
170153
"""
171154
Test execute query
172155
"""
173-
backend = Backend()
156+
174157
example = {"items": [], "page": 1, "page_size": 10, "page_total": 0}
175158
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
188170
}
189171
}
190-
tags {
191-
edges {
192-
node {
193-
name
194-
}
172+
}
173+
tags {
174+
edges {
175+
node {
176+
name
195177
}
196178
}
197-
themes {
198-
edges {
199-
node {
200-
name
201-
}
179+
}
180+
themes {
181+
edges {
182+
node {
183+
name
202184
}
203185
}
204-
createdAt
205-
updatedAt
206186
}
187+
createdAt
188+
updatedAt
207189
}
208-
totalCount
209190
}
191+
totalCount
210192
}
211-
"""
193+
}
194+
"""
212195
out = backend._execute_query(query, example)
213196
assert isinstance(out, dict)
214197
assert len(out) != 0
@@ -220,11 +203,7 @@ def test_simplify_response():
220203
Test simplify query
221204
"""
222205

223-
backend = Backend()
224206
response = {"items": [], "page": 1, "page_size": 10, "page_total": 0}
225207
out = backend._simplify_response(response)
226-
print(out)
227-
print(type(out))
228-
print(len(out))
229208
assert isinstance(out, dict)
230209
assert len(out) != 0

python-package/tests/test_upload/__init__.py

Whitespace-only changes.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)