Skip to content

Commit 371e4e9

Browse files
committed
test(spp_api_v2): fix test setup for no-identifier coverage tests
1 parent a208752 commit 371e4e9

2 files changed

Lines changed: 20 additions & 32 deletions

File tree

spp_api_v2/tests/test_group_api.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -136,18 +136,9 @@ def test_read_group_not_found(self):
136136

137137
def test_read_group_no_identifiers_returns_404(self):
138138
"""GET group without valid identifiers returns 404"""
139-
no_id_group = self.env["res.partner"].create(
140-
{
141-
"name": "No Identifier Group",
142-
"is_registrant": True,
143-
"is_group": True,
144-
}
145-
)
146-
self.env["spp.registry.id"].create(
147-
{
148-
"registrant_id": no_id_group.id,
149-
"value": "NO-TYPE-GRP-001",
150-
}
139+
no_id_group = self.create_test_group(
140+
name="Will Lose IDs Group",
141+
identifier_value="WILL-LOSE-GRP-001",
151142
)
152143

153144
no_consent_client = self.create_api_client(
@@ -158,9 +149,13 @@ def test_read_group_no_identifiers_returns_404(self):
158149
)
159150
token = self.generate_jwt_token(no_consent_client)
160151

161-
url = f"{self.api_base_url}/urn:openspp:vocab:id-type%23test_national_id|NO-TYPE-GRP-001"
152+
# Delete all registry IDs to simulate missing identifiers
153+
no_id_group.reg_ids.unlink()
154+
155+
url = f"{self.api_base_url}/urn:openspp:vocab:id-type%23test_household_id|WILL-LOSE-GRP-001"
162156
response = self.url_open(url, headers=self._get_headers(token=token))
163157

158+
# Partner's identifier was deleted, so lookup by identifier returns 404
164159
self.assertEqual(response.status_code, 404)
165160

166161
def test_read_group_invalid_format(self):

spp_api_v2/tests/test_individual_api.py

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -110,22 +110,13 @@ def test_read_individual_not_found(self):
110110

111111
def test_read_individual_no_identifiers_returns_404(self):
112112
"""GET individual without valid identifiers returns 404"""
113-
# Create individual without registry IDs but with a known identifier
114-
# to look it up. The partner exists but has no reg_ids, so
115-
# to_api_schema returns None and the router returns 404.
116-
no_id_partner = self.env["res.partner"].create(
117-
{
118-
"name": "No Identifier Person",
119-
"is_registrant": True,
120-
"is_group": False,
121-
}
122-
)
123-
# Add a reg_id with a value but no id_type (invalid identifier)
124-
self.env["spp.registry.id"].create(
125-
{
126-
"registrant_id": no_id_partner.id,
127-
"value": "NO-TYPE-001",
128-
}
113+
# Create individual with a known identifier, then remove all reg_ids
114+
# so to_api_schema returns None and the router returns 404.
115+
no_id_partner = self.create_test_individual(
116+
name="Will Lose IDs",
117+
given_name="Will",
118+
family_name="LoseIDs",
119+
identifier_value="WILL-LOSE-001",
129120
)
130121

131122
no_consent_client = self.create_api_client(
@@ -136,11 +127,13 @@ def test_read_individual_no_identifiers_returns_404(self):
136127
)
137128
token = self.generate_jwt_token(no_consent_client)
138129

139-
url = f"{self.api_base_url}/urn:openspp:vocab:id-type%23test_national_id|NO-TYPE-001"
130+
# Delete all registry IDs to simulate missing identifiers
131+
no_id_partner.reg_ids.unlink()
132+
133+
url = f"{self.api_base_url}/urn:openspp:vocab:id-type%23test_national_id|WILL-LOSE-001"
140134
response = self.url_open(url, headers=self._get_headers(token=token))
141135

142-
# Partner exists but to_api_schema returns None (no valid identifiers)
143-
# Router should return 404
136+
# Partner's identifier was deleted, so lookup by identifier returns 404
144137
self.assertEqual(response.status_code, 404)
145138

146139
def test_read_individual_invalid_format(self):

0 commit comments

Comments
 (0)