|
2 | 2 | # Gramps Web API - A RESTful API for the Gramps genealogy program |
3 | 3 | # |
4 | 4 | # Copyright (C) 2020 Christopher Horn |
| 5 | +# Copyright (C) 2025 David Straub |
5 | 6 | # |
6 | 7 | # This program is free software; you can redistribute it and/or modify |
7 | 8 | # it under the terms of the GNU Affero General Public License as published by |
|
19 | 20 |
|
20 | 21 | """Tests for the /api/filters endpoints using example_gramps.""" |
21 | 22 |
|
| 23 | +import uuid |
22 | 24 | import unittest |
23 | 25 |
|
24 | 26 | from jsonschema import validate |
|
33 | 35 | check_resource_missing, |
34 | 36 | check_success, |
35 | 37 | ) |
| 38 | +from .util import fetch_header |
36 | 39 |
|
37 | 40 | TEST_URL = BASE_URL + "/filters/" |
38 | 41 |
|
@@ -259,3 +262,54 @@ def setUpClass(cls): |
259 | 262 | def test_filters_endpoint_notes_filter(self): |
260 | 263 | """Test creation and application of a notes filter.""" |
261 | 264 | check_filter_create_update_delete(self, BASE_URL, TEST_URL, "notes") |
| 265 | + |
| 266 | + |
| 267 | +def make_handle() -> str: |
| 268 | + """Make a new valid handle.""" |
| 269 | + return str(uuid.uuid4()) |
| 270 | + |
| 271 | + |
| 272 | +class TestHasAssociationType(unittest.TestCase): |
| 273 | + """Test cases for the HasAssociationType filter.""" |
| 274 | + |
| 275 | + @classmethod |
| 276 | + def setUpClass(cls): |
| 277 | + """Test class setup.""" |
| 278 | + cls.client = get_test_client() |
| 279 | + |
| 280 | + def test_has_association_type(self): |
| 281 | + payload = {} |
| 282 | + # check authorization required to post to endpoint |
| 283 | + handle = make_handle() |
| 284 | + payload = { |
| 285 | + "_class": "Person", |
| 286 | + "handle": handle, |
| 287 | + "person_ref_list": [ |
| 288 | + { |
| 289 | + "_class": "PersonRef", |
| 290 | + "rel": "DNA", |
| 291 | + "ref": handle, # self-reference, why not |
| 292 | + } |
| 293 | + ], |
| 294 | + } |
| 295 | + headers = fetch_header(self.client) |
| 296 | + url = '/api/people/?rules={"rules":[{"name":"HasAssociationType","values":["DNA"]}]}' |
| 297 | + # no result |
| 298 | + rv = self.client.get(url, headers=headers) |
| 299 | + assert rv.json == [] |
| 300 | + # add person |
| 301 | + rv = self.client.post("/api/people/", json=payload, headers=headers) |
| 302 | + assert rv.status_code == 201 |
| 303 | + # one result |
| 304 | + rv = self.client.get(url, headers=headers) |
| 305 | + assert rv.json |
| 306 | + assert rv.json[0]["handle"] == handle |
| 307 | + # no result for wrong type |
| 308 | + rv = self.client.get(url.replace("DNA", "NotDNA"), headers=headers) |
| 309 | + assert rv.json == [] |
| 310 | + # delete person |
| 311 | + rv = self.client.delete(f"/api/people/{handle}", headers=headers) |
| 312 | + assert rv.status_code == 200 |
| 313 | + # no result |
| 314 | + rv = self.client.get(url, headers=headers) |
| 315 | + assert rv.json == [] |
0 commit comments