Skip to content

Commit

Permalink
simple tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thingscouldbeworse committed Nov 25, 2024
1 parent 2434a07 commit dc67495
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/fides/api/schemas/detection_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ class StagedResourceResponse(BaseModel):
created_at: datetime
updated_at: datetime
diff_status: str
child_diff_statuses: List[str]
child_diff_statuses: dict
hidden: bool
114 changes: 114 additions & 0 deletions tests/ctl/api/test_stagedresource.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
from typing import Generator
import pytest
from starlette.testclient import TestClient
from fides.api.models.detection_discovery import StagedResource
from fides.config import CONFIG, FidesConfig
from sqlalchemy.orm import Session
from fides.api.util.endpoint_utils import API_PREFIX
from fides.config import FidesConfig


@pytest.fixture(scope="function")
def sample_projects(
db: Session,
) -> Generator:
"""Fixture to add sample projects to the database"""
resources = [
StagedResource(
urn="test_monitor_config_id.test_project",
name="test_project",
resource_type="Database",
monitor_config_id="test_monitor_config_id",
description="test project",
diff_status="addition",
child_diff_statuses={},
),
StagedResource(
urn="test_monitor_config_id.test_project2",
name="test_project2",
resource_type="Database",
monitor_config_id="test_monitor_config_id",
description="test project2",
diff_status="addition",
child_diff_statuses={},
hidden=True,
),
]
for resource in resources:
db.add(resource)
db.commit()
yield resources
for resource in resources:
db.delete(resource)
db.commit()


@pytest.fixture(scope="function")
def sample_datasets(
db: Session,
) -> Generator:
"""Fixture to add sample datasets to the database"""
resources = [
StagedResource(
urn="test_monitor_config_id.test_dataset",
name="test_dataset",
resource_type="schema",
monitor_config_id="test_monitor_config_id",
description="test dataset",
diff_status="addition",
child_diff_statuses={},
),
StagedResource(
urn="test_monitor_config_id.test_dataset2",
name="test_dataset2",
resource_type="schema",
monitor_config_id="test_monitor_config_id",
description="test dataset2",
diff_status="addition",
child_diff_statuses={},
hidden=True,
),
]
for resource in resources:
db.add(resource)
db.commit()
yield resources
for resource in resources:
db.delete(resource)
db.commit()


def test_lifecycle_get_projects(
test_config: FidesConfig,
test_client: TestClient,
sample_projects: None,
):

result = test_client.get(
test_config.cli.server_url + API_PREFIX + "/lifecycle/project",
headers=test_config.user.auth_header,
)
assert result.status_code == 200

expected_non_hidden = [
resource for resource in sample_projects if not resource.hidden
]
assert len(result.json()["items"]) == len(expected_non_hidden)


def test_lifecycle_get_datasets(
test_config: FidesConfig,
test_client: TestClient,
sample_datasets: None,
):

result = test_client.get(
test_config.cli.server_url + API_PREFIX + "/lifecycle/dataset",
headers=test_config.user.auth_header,
)
assert result.status_code == 200

expected_non_hidden = [
resource for resource in sample_datasets if not resource.hidden
]
assert len(result.json()["items"]) == len(expected_non_hidden)

0 comments on commit dc67495

Please sign in to comment.