Skip to content

Commit

Permalink
add unit tests for new details functions
Browse files Browse the repository at this point in the history
  • Loading branch information
LavMatt committed Aug 6, 2024
1 parent 4b79d8d commit 50c3cd5
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
2 changes: 1 addition & 1 deletion home/service/details.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from .base import GenericService


def _parse_parent(relationships) -> EntityRef | None:
def _parse_parent(relationships: dict) -> EntityRef | None:
"""
returns the EntityRef of the first parent if one exists
"""
Expand Down
61 changes: 61 additions & 0 deletions tests/home/service/test_details.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest
from data_platform_catalogue.entities import (
AccessInformation,
Chart,
Expand All @@ -18,6 +19,8 @@
DashboardDetailsService,
DatabaseDetailsService,
DatasetDetailsService,
_parse_parent,
is_access_requirements_a_url,
)
from tests.conftest import (
generate_dashboard_metadata,
Expand All @@ -26,6 +29,63 @@
)


@pytest.mark.parametrize(
"input, expected_output",
[
(
{
RelationshipType.PARENT: [
EntitySummary(
entity_ref=EntityRef(urn="urn:li:db", display_name="db"),
description="test",
entity_type="database",
tags=[],
)
]
},
EntityRef(urn="urn:li:db", display_name="db"),
),
({}, None),
(
{
RelationshipType.DATA_LINEAGE: [
EntitySummary(
entity_ref=EntityRef(urn="urn:li:db", display_name="db"),
description="test",
entity_type="database",
tags=[],
)
]
},
None,
),
],
)
def test_parse_parent(input, expected_output):
result = _parse_parent(input)
assert result == expected_output


@pytest.mark.parametrize(
"input, expected_output",
[
("122", False),
("https://test.gov.uk", True),
("https://test.gov.uk/data/#readme", True),
("http://test.co.uk", True),
("ftp.example.com/how-to-access.txt", False),
("Just some instructions", False),
("", False),
(123, False),
(None, False),
(["https://test.gov.uk"], False),
],
)
def test_is_access_requirements_a_url(input, expected_output):
result = is_access_requirements_a_url(input)
assert result == expected_output


class TestDatasetDetailsService:
def test_get_context_contains_table_metadata(self, dataset_with_parent):
service = DatasetDetailsService(dataset_with_parent["urn"])
Expand Down Expand Up @@ -156,6 +216,7 @@ def test_get_context(self, mock_catalogue):
"parent_entity": None,
"parent_type": "dashboard",
"h1_value": "test",
"is_access_requirements_url": False,
}

assert context == expected
Expand Down

0 comments on commit 50c3cd5

Please sign in to comment.