Skip to content

Commit 777b84a

Browse files
committed
fix unit tests drifting from changes
1 parent 4ccf6b8 commit 777b84a

5 files changed

Lines changed: 29 additions & 27 deletions

File tree

.github/workflows/acceptance.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ jobs:
2222
- name: Run acceptance tests
2323
run: pytest tests/acceptance/ -v
2424
env:
25+
HYPHEN_DEV: ${{ vars.HYPHEN_DEV }}
2526
HYPHEN_API_KEY: ${{ secrets.HYPHEN_API_KEY }}
2627
HYPHEN_PUBLIC_API_KEY: ${{ secrets.HYPHEN_PUBLIC_API_KEY }}
27-
HYPHEN_APPLICATION_ID: ${{ secrets.HYPHEN_APPLICATION_ID }}
28-
HYPHEN_ORGANIZATION_ID: ${{ secrets.HYPHEN_ORGANIZATION_ID }}
29-
HYPHEN_LINK_DOMAIN: ${{ secrets.HYPHEN_LINK_DOMAIN }}
28+
HYPHEN_APPLICATION_ID: ${{ vars.HYPHEN_APPLICATION_ID }}
29+
HYPHEN_ORGANIZATION_ID: ${{ vars.HYPHEN_ORGANIZATION_ID }}
30+
HYPHEN_PROJECT_ID: ${{ vars.HYPHEN_PROJECT_ID }}
31+
HYPHEN_LINK_DOMAIN: ${{ vars.HYPHEN_LINK_DOMAIN }}

hyphen/feature_toggle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def __init__(
6363
)
6464

6565
self.environment = (
66-
environment or os.environ.get("HYPHEN_ENVIRONMENT") or "development"
66+
environment or os.environ.get("HYPHEN_ENVIRONMENT") or "production"
6767
)
6868
self.default_context = default_context
6969
self.on_error = on_error

tests/test_feature_toggle.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,9 @@ def test_build_payload_with_minimal_context(self) -> None:
9191

9292
payload = toggle._build_payload()
9393

94-
assert payload == {
95-
"application": "the_app_id",
96-
"environment": "the_environment",
97-
}
94+
assert payload["application"] == "the_app_id"
95+
assert payload["environment"] == "the_environment"
96+
assert "targetingKey" in payload # Always generated when not provided
9897

9998
def test_build_payload_with_full_context(self) -> None:
10099
"""Test payload building with full context."""

tests/test_link.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def test_create_short_code(mock_client_class: Mock) -> None:
6666
def test_update_short_code(mock_client_class: Mock) -> None:
6767
"""Test update_short_code method returns ShortCode."""
6868
mock_client = Mock()
69-
mock_client.put.return_value = {
69+
mock_client.patch.return_value = {
7070
"id": "sc_123",
7171
"code": "abc123",
7272
"long_url": "https://hyphen.ai",
@@ -81,7 +81,7 @@ def test_update_short_code(mock_client_class: Mock) -> None:
8181

8282
assert isinstance(result, ShortCode)
8383
assert result.title == "Updated"
84-
mock_client.put.assert_called_once_with(
84+
mock_client.patch.assert_called_once_with(
8585
"/api/organizations/org_123/link/codes/abc123",
8686
data={"title": "Updated"}
8787
)
@@ -152,7 +152,7 @@ def test_get_tags(mock_client_class: Mock) -> None:
152152

153153
assert len(result) == 3
154154
assert "tag1" in result
155-
mock_client.get.assert_called_once_with("/api/organizations/org_123/link/tags")
155+
mock_client.get.assert_called_once_with("/api/organizations/org_123/link/codes/tags")
156156

157157

158158
@patch("hyphen.link.BaseClient")
@@ -218,7 +218,7 @@ def test_get_qr_code(mock_client_class: Mock) -> None:
218218

219219
assert isinstance(result, QrCode)
220220
assert result.id == "qr_123"
221-
mock_client.get.assert_called_once_with("/api/organizations/org_123/link/codes/abc123/qr/qr_123")
221+
mock_client.get.assert_called_once_with("/api/organizations/org_123/link/codes/abc123/qrs/qr_123")
222222

223223

224224
@patch("hyphen.link.BaseClient")
@@ -240,7 +240,7 @@ def test_get_qr_codes(mock_client_class: Mock) -> None:
240240
assert result.total == 2
241241
assert len(result.data) == 2
242242
mock_client.get.assert_called_once_with(
243-
"/api/organizations/org_123/link/codes/abc123/qr", params=None
243+
"/api/organizations/org_123/link/codes/abc123/qrs", params=None
244244
)
245245

246246

@@ -255,4 +255,4 @@ def test_delete_qr_code(mock_client_class: Mock) -> None:
255255
result = link.delete_qr_code("abc123", "qr_123")
256256

257257
assert result is None
258-
mock_client.delete.assert_called_once_with("/api/organizations/org_123/link/codes/abc123/qr/qr_123")
258+
mock_client.delete.assert_called_once_with("/api/organizations/org_123/link/codes/abc123/qrs/qr_123")

tests/test_net_info.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test_get_ip_info(mock_client_class: Mock) -> None:
2727
assert result.ip_type == "ipv4"
2828
assert result.location.country == "United States"
2929
assert result.location.city == "Mountain View"
30-
mock_client.get.assert_called_once_with("/api/net-info/ip/8.8.8.8")
30+
mock_client.get.assert_called_once_with("/ip/8.8.8.8")
3131

3232

3333
@patch("hyphen.net_info.BaseClient")
@@ -53,10 +53,12 @@ def test_get_ip_info_error(mock_client_class: Mock) -> None:
5353
def test_get_ip_infos(mock_client_class: Mock) -> None:
5454
"""Test get_ip_infos method returns list of IpInfo."""
5555
mock_client = Mock()
56-
mock_client.post.return_value = [
57-
{"ip": "8.8.8.8", "type": "ipv4", "location": {"country": "United States"}},
58-
{"ip": "1.1.1.1", "type": "ipv4", "location": {"country": "Australia"}},
59-
]
56+
mock_client.post_raw.return_value = {
57+
"data": [
58+
{"ip": "8.8.8.8", "type": "ipv4", "location": {"country": "United States"}},
59+
{"ip": "1.1.1.1", "type": "ipv4", "location": {"country": "Australia"}},
60+
]
61+
}
6062
mock_client_class.return_value = mock_client
6163

6264
net_info = NetInfo(api_key="key_123")
@@ -69,20 +71,19 @@ def test_get_ip_infos(mock_client_class: Mock) -> None:
6971
assert isinstance(result[1], IpInfo)
7072
assert result[1].ip == "1.1.1.1"
7173
assert result[1].location.country == "Australia"
72-
mock_client.post.assert_called_once_with(
73-
"/api/net-info/ips",
74-
data={"ips": ["8.8.8.8", "1.1.1.1"]}
75-
)
74+
mock_client.post_raw.assert_called_once_with("/ip", data=["8.8.8.8", "1.1.1.1"])
7675

7776

7877
@patch("hyphen.net_info.BaseClient")
7978
def test_get_ip_infos_with_errors(mock_client_class: Mock) -> None:
8079
"""Test get_ip_infos method handles mixed results with errors."""
8180
mock_client = Mock()
82-
mock_client.post.return_value = [
83-
{"ip": "8.8.8.8", "type": "ipv4", "location": {"country": "United States"}},
84-
{"ip": "invalid", "type": "error", "errorMessage": "Invalid IP"},
85-
]
81+
mock_client.post_raw.return_value = {
82+
"data": [
83+
{"ip": "8.8.8.8", "type": "ipv4", "location": {"country": "United States"}},
84+
{"ip": "invalid", "type": "error", "errorMessage": "Invalid IP"},
85+
]
86+
}
8687
mock_client_class.return_value = mock_client
8788

8889
net_info = NetInfo(api_key="key_123")

0 commit comments

Comments
 (0)