Skip to content

Commit

Permalink
Add test for entity url encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchdawson1982 committed Dec 16, 2024
1 parent 4013389 commit ebeb7d5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
6 changes: 3 additions & 3 deletions feedback/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ class IssueChoices(models.TextChoices):
data_custodian_email = models.CharField(max_length=250)

@property
def formatted_entity_url(self):
def encoded_entity_url(self):
parsed_url = urlparse(self.entity_url)
encoded_path = quote(parsed_url.path)
formatted_entity_url = urlunparse(
encoded_entity_url = urlunparse(
(
parsed_url.scheme,
parsed_url.netloc,
Expand All @@ -72,4 +72,4 @@ def formatted_entity_url(self):
parsed_url.fragment,
)
)
return formatted_entity_url
return encoded_entity_url
2 changes: 1 addition & 1 deletion feedback/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def send(
"userEmail": issue.created_by.email if issue.created_by else "",
"assetName": issue.entity_name,
"userMessage": issue.additional_info,
"assetUrl": issue.formatted_entity_url,
"assetUrl": issue.encoded_entity_url,
}

reference = str(issue.id)
Expand Down
21 changes: 20 additions & 1 deletion tests/feedback/test_notify_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ def test_send_all_notifications(mock_notifications_client, reporter):


@pytest.mark.django_db
def test_send_notifications_no_data_custodian_email(mock_notifications_client, reporter):
def test_send_notifications_no_data_custodian_email(
mock_notifications_client, reporter
):
data = {
"reason": "Other",
"additional_info": "This is some additional information.",
Expand Down Expand Up @@ -76,3 +78,20 @@ def test_send_all_notifications_no_reporter_no_data_custodian_email(
send(issue=issue, client=mock_notifications_client, send_email_to_reporter=False)

assert mock_notifications_client.send_email_notification.call_count == 1


@pytest.mark.django_db
def test_entity_url_encoding(reporter):
data = {
"reason": "Other",
"additional_info": "This is some additional information.",
"entity_name": "my_entity",
"entity_url": "http://localhost:8000/details/table/urn:li:dataset:(urn:li:dataPlatform:dbt,cadet.awsdatacatalog.derived_oasys_dim.dim_ref_question,PROD)", # noqa: E501
"created_by": reporter,
}

encoded_entity_url = "http://localhost:8000/details/table/urn%3Ali%3Adataset%3A%28urn%3Ali%3AdataPlatform%3Adbt%2Ccadet.awsdatacatalog.derived_oasys_dim.dim_ref_question%2CPROD%29" # noqa: E501

issue = Issue.objects.create(**data)
assert issue
assert issue.encoded_entity_url == encoded_entity_url

0 comments on commit ebeb7d5

Please sign in to comment.