Skip to content

Commit 6df5df4

Browse files
Kathryn Dalemattjreynolds
authored andcommitted
Update unit tests
1 parent 32e772e commit 6df5df4

2 files changed

Lines changed: 27 additions & 7 deletions

File tree

metrics/interfaces/charts/common/chart_output.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class ChartOutput:
2929
data_classification: str | None = None
3030

3131
def __post_init__(self) -> None:
32-
if (not self.is_public) and self.data_classification and AUTH_ENABLED:
32+
if (not self.is_public) and (self.data_classification) and (AUTH_ENABLED):
3333
self._apply_watermark()
3434

3535
def _apply_watermark(self) -> None:

tests/unit/metrics/interfaces/charts/common/test_chart_output.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ def test_handles_empty_string(self):
7676

7777
class TestPostInitAppliesWatermark:
7878
@mock.patch(f"{MODULE_PATH}.ChartOutput._apply_watermark")
79-
def test_applies_watermark_when_not_public_and_classified(
79+
@mock.patch(f"{MODULE_PATH}.AUTH_ENABLED", True)
80+
def test_applies_watermark_when_not_public_and_classified_and_auth_enabled(
8081
self, spy_apply_watermark: mock.MagicMock
8182
):
8283
"""
@@ -97,6 +98,7 @@ def test_applies_watermark_when_not_public_and_classified(
9798
spy_apply_watermark.assert_called_once()
9899

99100
@mock.patch(f"{MODULE_PATH}.ChartOutput._apply_watermark")
101+
@mock.patch(f"{MODULE_PATH}.AUTH_ENABLED", True)
100102
def test_does_not_apply_watermark_when_public(
101103
self, spy_apply_watermark: mock.MagicMock
102104
):
@@ -117,6 +119,7 @@ def test_does_not_apply_watermark_when_public(
117119
spy_apply_watermark.assert_not_called()
118120

119121
@mock.patch(f"{MODULE_PATH}.ChartOutput._apply_watermark")
122+
@mock.patch(f"{MODULE_PATH}.AUTH_ENABLED", True)
120123
def test_does_not_apply_watermark_when_no_classification(
121124
self, spy_apply_watermark: mock.MagicMock
122125
):
@@ -135,18 +138,35 @@ def test_does_not_apply_watermark_when_no_classification(
135138
# Then
136139
spy_apply_watermark.assert_not_called()
137140

141+
@mock.patch(f"{MODULE_PATH}.ChartOutput._apply_watermark")
142+
@mock.patch(f"{MODULE_PATH}.AUTH_ENABLED", False)
143+
def test_does_not_apply_watermark_when_no_auth_enabled(
144+
self, spy_apply_watermark: mock.MagicMock
145+
):
146+
"""
147+
Given an instance that has no data_classification
148+
When __post_init__() is triggered
149+
Then _apply_watermark() is not called
150+
"""
151+
# Given / When
152+
ChartOutput(
153+
figure=go.Figure(),
154+
description="Test chart",
155+
is_headline=False,
156+
is_public=False,
157+
data_classification="official",
158+
)
138159

139-
from unittest import mock
140-
import plotly.graph_objects as go
160+
# Then
161+
spy_apply_watermark.assert_not_called()
141162

142163

143164
class TestApplyWatermark:
144165
@mock.patch(f"{MODULE_PATH}.wrap_text")
145166
@mock.patch(f"{MODULE_PATH}.DataClassification")
167+
@mock.patch(f"{MODULE_PATH}.AUTH_ENABLED", True)
146168
def test_adds_wrapped_watermark_annotation(
147-
self,
148-
mock_data_classification,
149-
mock_wrap_text,
169+
self, mock_data_classification, mock_wrap_text
150170
):
151171
"""
152172
Given a ChartOutput with a valid data_classification

0 commit comments

Comments
 (0)