Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload tests #1753

Merged
merged 10 commits into from
Jan 16, 2025
Merged
8 changes: 4 additions & 4 deletions python-package/basedosdados/upload/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ def update(self, mode="prod", custom_schema=None):
)

def publish(
self, if_exists="raise", custon_publish_sql=None, custom_schema=None
self, if_exists="raise", custom_publish_sql=None, custom_schema=None
):
"""Creates BigQuery table at production dataset.

Expand Down Expand Up @@ -765,13 +765,13 @@ def publish(
publish_sql = self._make_publish_sql()

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

# create view using custon query
if custon_publish_sql is not None:
self.client["bigquery_prod"].query(custon_publish_sql).result()
if custom_publish_sql is not None:
self.client["bigquery_prod"].query(custom_publish_sql).result()
# update schema using a custom schema
if custom_schema is not None:
self.update(custom_schema=custom_schema)
Expand Down
91 changes: 35 additions & 56 deletions python-package/tests/test_backend.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from basedosdados.backend import Backend

backend = Backend()


def test_get_dataset():
"""
Test dataset output without parameters
"""

backend = Backend()

out = backend.get_datasets()
assert isinstance(out, dict)
assert len(out) != 0
Expand All @@ -19,8 +19,6 @@ def test_get_dataset_with_input():
Test dataset output with input
"""

backend = Backend()

out = backend.get_datasets(dataset_name="br_me_caged")
assert isinstance(out, dict)
assert len(out) != 0
Expand All @@ -32,8 +30,6 @@ def test_get_tables():
Test tables output without parameters
"""

backend = Backend()

out = backend.get_tables()
assert isinstance(out, dict)
assert len(out) != 0
Expand All @@ -46,8 +42,6 @@ def test_get_tables_with_input():
Test tables output with input
"""

backend = Backend()

out = backend.get_tables(table_name="br_me_caged")
assert isinstance(out, dict)
assert len(out) != 0
Expand All @@ -60,8 +54,6 @@ def test_get_columns():
Test columns output without parameters
"""

backend = Backend()

out = backend.get_columns()
assert isinstance(out, dict)
assert len(out) != 0
Expand All @@ -74,36 +66,34 @@ def test_get_columns_with_input():
Test columns output with input
"""

backend = Backend()

out = backend.get_columns(column_name="description")
assert isinstance(out, dict)
assert len(out) != 0
assert out["page_size"] >= 10
assert out["page_total"] > 0


def test_search():
def test_search(capsys):
"""
Test search output without parameters
"""

backend = Backend()

out = backend.search()
_, res = capsys.readouterr()
print("TEST SEARCH WITH INPUT", res)
assert isinstance(out, dict)
assert len(out) != 0
assert out["page_size"] > 1


def test_search_with_input():
def test_search_with_input(capsys):
"""
Test search output with input
"""

backend = Backend()

out = backend.search(q="description")
_, res = capsys.readouterr()
print("TEST SEARCH WITH INPUT", res)
assert isinstance(out, dict)
assert len(out) != 0
assert out["page_size"] >= 10
Expand All @@ -113,7 +103,6 @@ def test_get_dataset_config():
"""
Test get_dataset_config output
"""
backend = Backend()

out = backend.get_dataset_config(dataset_id="br_me_rais")
assert isinstance(out, dict)
Expand All @@ -126,14 +115,10 @@ def test_get_table_config():
"""
Test get_dataset_config output
"""
backend = Backend()

out = backend.get_table_config(
dataset_id="br_me_rais", table_id="microdados_estabelecimentos"
)
print(out)
print(len(out))
print(type(out))
assert isinstance(out, dict)
assert len(out) > 0
assert out != ""
Expand All @@ -144,7 +129,6 @@ def test_get_dataset_id_from_name():
"""
Test get dataset id from name
"""
backend = Backend()

out = backend._get_dataset_id_from_name("br_me_rais")
assert isinstance(out, str)
Expand All @@ -156,7 +140,6 @@ def test_get_table_id_from_name():
"""
Test get table id from name
"""
backend = Backend()

out = backend._get_table_id_from_name(
"br_me_rais", "microdados_estabelecimentos"
Expand All @@ -170,45 +153,45 @@ def test_execute_query():
"""
Test execute query
"""
backend = Backend()

example = {"items": [], "page": 1, "page_size": 10, "page_total": 0}
query = """
query {
allDataset(first: 5, offset: 10) {
edges {
node {
slug
name
description
organizations {
edges {
node {
name
}
query {
allDataset(first: 5, offset: 10) {
edges {
node {
slug
name
description
organizations {
edges {
node {
name
}
}
tags {
edges {
node {
name
}
}
tags {
edges {
node {
name
}
}
themes {
edges {
node {
name
}
}
themes {
edges {
node {
name
}
}
createdAt
updatedAt
}
createdAt
updatedAt
}
totalCount
}
totalCount
}
"""
}
"""
out = backend._execute_query(query, example)
assert isinstance(out, dict)
assert len(out) != 0
Expand All @@ -220,11 +203,7 @@ def test_simplify_response():
Test simplify query
"""

backend = Backend()
response = {"items": [], "page": 1, "page_size": 10, "page_total": 0}
out = backend._simplify_response(response)
print(out)
print(type(out))
print(len(out))
assert isinstance(out, dict)
assert len(out) != 0
Empty file.
Binary file not shown.
Binary file not shown.
Loading
Loading