Skip to content

Commit

Permalink
add test cases and format code using ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
onlyjackfrost committed Jun 12, 2024
1 parent 7e1100a commit 21d3687
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 7 deletions.
1 change: 0 additions & 1 deletion ibis-server/app/model/metadata/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,3 @@ def get_constraints(self) -> list[Constraint]:
)
)
return constraints

2 changes: 1 addition & 1 deletion ibis-server/app/model/metadata/dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class MetadataDTO(BaseModel):
class WrenEngineColumnType(Enum):
# Boolean Types
BOOLEAN = "BOOLEAN"

# Numeric Types
TINYINT = "TINYINT"
INT2 = "INT2"
Expand Down
6 changes: 3 additions & 3 deletions ibis-server/app/model/metadata/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
from app.model.metadata.dto import Table, Constraint


class Metadata():
class Metadata:
def __init__(self, connection_info: ConnectionInfo):
self.connection_info = connection_info

def get_table_list(self) -> list[Table]:
raise NotImplementedError

def get_constraints(self) -> list[Constraint]:
raise NotImplementedError
raise NotImplementedError
3 changes: 1 addition & 2 deletions ibis-server/app/routers/ibis/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ def validate(rule_name: str, dto: ValidateDTO) -> Response:
def get_postgres_table_list(dto: MetadataDTO) -> list[Table]:
metadata = MetadataFactory(DataSource.postgres, dto.connection_info)
return metadata.get_table_list()


@router.post("/metadata/constraints", response_model=list[Constraint])
@log_dto
def get_postgres_constraints(dto: MetadataDTO) -> list[Constraint]:
metadata = MetadataFactory(DataSource.postgres, dto.connection_info)
return metadata.get_constraints()

16 changes: 16 additions & 0 deletions ibis-server/tests/routers/ibis/test_bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,19 @@ def test_validate_rule_column_is_valid_without_one_parameter(self):
)
assert response.status_code == 422
assert response.text == "Missing required parameter: `modelName`"

def test_metadata_list_tables(self):
connection_info = self.get_connection_info()
response = client.post(
url="/v2/ibis/bigquery/metadata/tables",
json={"connectionInfo": connection_info},
)
assert response.status_code == 200

def test_metadata_list_constraints(self):
connection_info = self.get_connection_info()
response = client.post(
url="/v2/ibis/bigquery/metadata/constraints",
json={"connectionInfo": connection_info},
)
assert response.status_code == 200
16 changes: 16 additions & 0 deletions ibis-server/tests/routers/ibis/test_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,3 +365,19 @@ def test_validate_rule_column_is_valid_without_one_parameter(
)
assert response.status_code == 422
assert response.text == "Missing required parameter: `modelName`"

def test_metadata_list_tables(self, postgres: PostgresContainer):
connection_info = self.to_connection_info(postgres)
response = client.post(
url="/v2/ibis/postgres/metadata/tables",
json={"connectionInfo": connection_info},
)
assert response.status_code == 200

def test_metadata_list_constraints(self, postgres: PostgresContainer):
connection_info = self.to_connection_info(postgres)
response = client.post(
url="/v2/ibis/postgres/metadata/constraints",
json={"connectionInfo": connection_info},
)
assert response.status_code == 200

0 comments on commit 21d3687

Please sign in to comment.