-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
298 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
name: dummy | ||
|
||
models: | ||
basedosdados: | ||
dummy: | ||
+materialized: table | ||
+schema: dummy |
2 changes: 1 addition & 1 deletion
2
.../models/br_ibge_pib/br_ibge_pib__gini.sql → .../models/br_ibge_pib/br_ibge_pib__gini.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/models/br_ibge_pib/br_ibge_pib__uf.sql → ...ev/models/br_ibge_pib/br_ibge_pib__uf.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
tests/models/br_ibge_pib/schema.yml → ...osdados-dev/models/br_ibge_pib/schema.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
--- | ||
version: 2 | ||
|
||
models: | ||
|
16 changes: 16 additions & 0 deletions
16
tests/queries-basedosdados-dev/test_copy_models_from_dev_to_prod.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import os | ||
import pytest | ||
from databasers_utils import copy_models_from_dev_to_prod | ||
|
||
TESTS_DEV_DIR = os.path.join(os.getcwd(), "tests", "queries-basedosdados-dev") | ||
|
||
|
||
@pytest.mark.dependency( | ||
depends=[ | ||
"test_table_architecture.test_create_yaml_file", | ||
"test_table_architecture.test_create_sql_files", | ||
"test_table_architecture.test_update_dbt_project", | ||
] | ||
) | ||
def test_copy_models(): | ||
copy_models_from_dev_to_prod(datasets=["br_ibge_pib"], dir=TESTS_DEV_DIR) |
File renamed without changes.
113 changes: 113 additions & 0 deletions
113
tests/queries-basedosdados-dev/test_table_architecture.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import os | ||
import pytest | ||
import pandas as pd | ||
import ruamel.yaml as yaml | ||
import sys | ||
from databasers_utils import TableArchitecture | ||
|
||
TESTS_DEV_DIR = os.path.join(os.getcwd(), "tests", "queries-basedosdados-dev") | ||
|
||
|
||
def test_architecture(): | ||
table_arch = TableArchitecture( | ||
dataset_id="br_ibge_pib", | ||
tables={ | ||
"uf": "https://docs.google.com/spreadsheets/d/12F5NzhOYlN_bi9flLBEdXDWpa5iVakSP4EKm9UoyWuo/edit?usp=drive_link", | ||
"gini": "https://docs.google.com/spreadsheets/d/1K1svie4Gyqe6NnRjBgJbapU5sTsLqXWTQUmTRVIRwQc/edit?usp=drive_link", | ||
}, | ||
) | ||
|
||
tables = table_arch.tables() | ||
assert "uf" and "gini" in tables.keys() | ||
assert isinstance(tables["uf"], pd.DataFrame) | ||
assert isinstance(tables["gini"], pd.DataFrame) | ||
assert len(tables) == 2 | ||
|
||
|
||
@pytest.mark.dependency() | ||
def test_create_yaml_file(): | ||
table_arch = TableArchitecture( | ||
dataset_id="br_ibge_pib", | ||
tables={ | ||
"uf": "https://docs.google.com/spreadsheets/d/12F5NzhOYlN_bi9flLBEdXDWpa5iVakSP4EKm9UoyWuo/edit?usp=drive_link", | ||
"gini": "https://docs.google.com/spreadsheets/d/1K1svie4Gyqe6NnRjBgJbapU5sTsLqXWTQUmTRVIRwQc/edit?usp=drive_link", | ||
}, | ||
) | ||
|
||
os.makedirs(os.path.join(TESTS_DEV_DIR, "models"), exist_ok=True) | ||
|
||
table_arch.create_yaml_file(dir=TESTS_DEV_DIR) | ||
|
||
assert os.path.exists( | ||
os.path.join(TESTS_DEV_DIR, "models", "br_ibge_pib", "schema.yml") | ||
) | ||
|
||
|
||
@pytest.mark.dependency() | ||
def test_create_sql_files(): | ||
table_arch = TableArchitecture( | ||
dataset_id="br_ibge_pib", | ||
tables={ | ||
"uf": "https://docs.google.com/spreadsheets/d/12F5NzhOYlN_bi9flLBEdXDWpa5iVakSP4EKm9UoyWuo/edit?usp=drive_link", | ||
"gini": "https://docs.google.com/spreadsheets/d/1K1svie4Gyqe6NnRjBgJbapU5sTsLqXWTQUmTRVIRwQc/edit?usp=drive_link", | ||
}, | ||
) | ||
|
||
os.makedirs(os.path.join(TESTS_DEV_DIR, "models"), exist_ok=True) | ||
|
||
table_arch.create_sql_files(dir=TESTS_DEV_DIR) | ||
|
||
assert os.path.exists( | ||
os.path.join( | ||
TESTS_DEV_DIR, "models", "br_ibge_pib", "br_ibge_pib__gini.sql" | ||
) | ||
) | ||
|
||
assert os.path.exists( | ||
os.path.join( | ||
TESTS_DEV_DIR, "models", "br_ibge_pib", "br_ibge_pib__uf.sql" | ||
) | ||
) | ||
|
||
|
||
@pytest.mark.dependency() | ||
def test_update_dbt_project(): | ||
table_arch = TableArchitecture( | ||
dataset_id="br_ibge_pib", | ||
tables={ | ||
"uf": "https://docs.google.com/spreadsheets/d/12F5NzhOYlN_bi9flLBEdXDWpa5iVakSP4EKm9UoyWuo/edit?usp=drive_link", | ||
"gini": "https://docs.google.com/spreadsheets/d/1K1svie4Gyqe6NnRjBgJbapU5sTsLqXWTQUmTRVIRwQc/edit?usp=drive_link", | ||
}, | ||
) | ||
|
||
yaml_obj = yaml.YAML(typ="rt") | ||
yaml_obj.indent(mapping=2, sequence=4, offset=2) | ||
|
||
DBT_PROJECT_PATH = os.path.join(TESTS_DEV_DIR, "dbt_project.yml") | ||
|
||
with open(DBT_PROJECT_PATH, "r") as file: | ||
content = yaml_obj.load(file) | ||
file.close() | ||
|
||
assert content["models"]["basedosdados"].get("br_ibge_pib") is None | ||
|
||
table_arch.update_dbt_project(dir=TESTS_DEV_DIR) | ||
|
||
yaml_obj_2 = yaml.YAML(typ="rt") | ||
yaml_obj_2.indent(mapping=2, sequence=4, offset=2) | ||
|
||
with open(DBT_PROJECT_PATH, "r") as file: | ||
content_updated = yaml_obj_2.load(file) | ||
file.close() | ||
|
||
# Inspect changes | ||
yaml_obj_2.dump(content_updated, sys.stdout) | ||
|
||
added = content_updated["models"]["basedosdados"]["br_ibge_pib"] | ||
assert added["+materialized"] == "table" | ||
assert added["+schema"] == "br_ibge_pib" | ||
|
||
# Restore changes | ||
with open(DBT_PROJECT_PATH, "w") as io: | ||
yaml_obj.dump(content, io) | ||
io.close() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
name: dummy | ||
|
||
models: | ||
basedosdados: | ||
br_ibge_pib: | ||
+materialized: table | ||
+schema: br_ibge_pib | ||
dummy: | ||
+materialized: table | ||
+schema: dummy |
11 changes: 11 additions & 0 deletions
11
tests/queries-basedosdados/models/br_ibge_pib/br_ibge_pib__gini.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{{ config(alias="gini", schema="br_ibge_pib", materialized="table") }} | ||
select | ||
safe_cast(id_uf as string) id_uf, | ||
safe_cast(ano as int64) ano, | ||
safe_cast(gini_pib as int64) gini_pib, | ||
safe_cast(gini_va as int64) gini_va, | ||
safe_cast(gini_va_agro as int64) gini_va_agro, | ||
safe_cast(gini_va_industria as int64) gini_va_industria, | ||
safe_cast(gini_va_servicos as int64) gini_va_servicos, | ||
safe_cast(gini_va_adespss as int64) gini_va_adespss, | ||
from `basedosdados-staging.br_ibge_pib_staging.gini` as t |
13 changes: 13 additions & 0 deletions
13
tests/queries-basedosdados/models/br_ibge_pib/br_ibge_pib__uf.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{{ config(alias="uf", schema="br_ibge_pib", materialized="table") }} | ||
select | ||
safe_cast(ano as int64) ano, | ||
safe_cast(id_uf as string) id_uf, | ||
safe_cast(sigla_uf as string) sigla_uf, | ||
safe_cast(pib as int64) pib, | ||
safe_cast(impostos_liquidos as int64) impostos_liquidos, | ||
safe_cast(va as int64) va, | ||
safe_cast(va_agropecuaria as int64) va_agropecuaria, | ||
safe_cast(va_industria as int64) va_industria, | ||
safe_cast(va_servicos as int64) va_servicos, | ||
safe_cast(va_adespss as int64) va_adespss, | ||
from `basedosdados-staging.br_ibge_pib_staging.uf` as t |
Oops, something went wrong.