|
4 | 4 | # John A Stevenson <jostev@bgs.ac.uk> |
5 | 5 | # Colin Blackburn <colb@bgs.ac.uk> |
6 | 6 | # Bernhard Mallinger <bernhard.mallinger@eox.at> |
| 7 | +# Francesco Bartoli <xbartolone@gmail.com> |
7 | 8 | # |
8 | 9 | # Copyright (c) 2024 Tom Kralidis |
9 | 10 | # Copyright (c) 2022 John A Stevenson and Colin Blackburn |
| 11 | +# Copyright (c) 2026 Francesco Bartoli |
10 | 12 | # |
11 | 13 | # Permission is hereby granted, free of charge, to any person |
12 | 14 | # obtaining a copy of this software and associated documentation |
|
39 | 41 | import pytest |
40 | 42 |
|
41 | 43 | from pygeoapi.api import ( |
42 | | - API, APIRequest, FORMAT_TYPES, F_HTML, F_JSON, F_JSONLD, F_GZIP, |
43 | | - __version__, validate_bbox, validate_datetime, evaluate_limit, |
44 | | - validate_subset, landing_page, openapi_, conformance, describe_collections, |
45 | | - get_collection_schema, |
| 44 | + API, APIRequest, CONFORMANCE_CLASSES, FORMAT_TYPES, F_HTML, F_JSON, |
| 45 | + F_JSONLD, F_GZIP, __version__, validate_bbox, validate_datetime, |
| 46 | + evaluate_limit, validate_subset, landing_page, openapi_, conformance, |
| 47 | + describe_collections, get_collection_schema, |
46 | 48 | ) |
47 | 49 | from pygeoapi.util import yaml_load, get_api_rules, get_base_url |
48 | 50 |
|
@@ -567,6 +569,37 @@ def test_conformance(config, api_): |
567 | 569 | assert rsp_headers['Content-Language'] == 'en-US' |
568 | 570 |
|
569 | 571 |
|
| 572 | +def test_conformance_does_not_mutate_global_list(config, api_): |
| 573 | + """Test conformance method does not mutate CONFORMANCE_CLASSES. |
| 574 | +
|
| 575 | + This test verifies that the global CONFORMANCE_CLASSES list is not |
| 576 | + mutated by calls to the conformance function. The base conformance |
| 577 | + classes should remain unchanged after multiple calls. |
| 578 | + """ |
| 579 | + |
| 580 | + # Store the original length and content of the global list |
| 581 | + original_length = len(CONFORMANCE_CLASSES) |
| 582 | + original_classes = list(CONFORMANCE_CLASSES) |
| 583 | + |
| 584 | + req = mock_api_request() |
| 585 | + |
| 586 | + # Make multiple calls to conformance |
| 587 | + for _ in range(3): |
| 588 | + conformance(api_, req) |
| 589 | + |
| 590 | + # The global list should NOT have been mutated |
| 591 | + assert len(CONFORMANCE_CLASSES) == original_length, ( |
| 592 | + f'Global CONFORMANCE_CLASSES was mutated! ' |
| 593 | + f'Original length: {original_length}, ' |
| 594 | + f'Current length: {len(CONFORMANCE_CLASSES)}. ' |
| 595 | + f'The conformance() function should create a copy of the list ' |
| 596 | + f'before extending it.' |
| 597 | + ) |
| 598 | + assert CONFORMANCE_CLASSES == original_classes, ( |
| 599 | + 'Global CONFORMANCE_CLASSES content was modified' |
| 600 | + ) |
| 601 | + |
| 602 | + |
570 | 603 | def test_describe_collections(config, api_): |
571 | 604 | req = mock_api_request({"f": "html"}) |
572 | 605 | rsp_headers, code, response = describe_collections(api_, req) |
|
0 commit comments