File: test_planetary_computer_00_stac_collection.py

package info (click to toggle)
python-azure 20251118%2Bgit-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 783,356 kB
  • sloc: python: 6,474,533; ansic: 804; javascript: 287; sh: 205; makefile: 198; xml: 109
file content (1230 lines) | stat: -rw-r--r-- 45,286 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
# pylint: disable=line-too-long,useless-suppression,too-many-lines
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------
"""
Unit tests for STAC Collection operations.
"""

import logging
import time
import datetime
from pathlib import Path
from devtools_testutils import recorded_by_proxy, is_live
from testpreparer import PlanetaryComputerProClientTestBase, PlanetaryComputerPreparer
from azure.planetarycomputer.models import (
    PartitionTypeScheme,
)

# Set up test logger
test_logger = logging.getLogger("test_stac_collection")
test_logger.setLevel(logging.DEBUG)

# Create logs directory if it doesn't exist
log_dir = Path(__file__).parent / "logs"
log_dir.mkdir(exist_ok=True)

# File handler for test logs
log_file = log_dir / "stac_collection_test_results.log"
file_handler = logging.FileHandler(log_file, mode="w")
file_handler.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
file_handler.setFormatter(formatter)
test_logger.addHandler(file_handler)


class TestPlanetaryComputerStacCollection(PlanetaryComputerProClientTestBase):
    """Test suite for STAC Collection operations."""

    @PlanetaryComputerPreparer()
    @recorded_by_proxy
    def test_01_list_collections(self, planetarycomputer_endpoint):
        """
        Test listing all STAC collections.

        Expected response:
        - Dictionary with 'collections' key
        - List of collection objects
        """
        test_logger.info("=" * 80)
        test_logger.info("TEST: test_01_list_collections")
        test_logger.info("=" * 80)
        test_logger.info(f"Input - endpoint: {planetarycomputer_endpoint}")

        client = self.create_client(endpoint=planetarycomputer_endpoint)

        test_logger.info("Calling: list_collections()")
        response = client.stac.list_collections()

        test_logger.info(f"Response type: {type(response)}")

        # Validate response structure
        assert response is not None, "Response should not be None"
        assert hasattr(
            response, "collections"
        ), "Response should have 'collections' attribute"

        collections = response.collections
        assert isinstance(
            collections, list
        ), f"Collections should be a list, got {type(collections)}"

        test_logger.info(f"Number of collections: {len(collections)}")

        if len(collections) > 0:
            first_collection = collections[0]
            test_logger.info(f"First collection ID: {first_collection.id}")
            test_logger.info(f"First collection title: {first_collection.title}")

        test_logger.info("Test PASSED\n")

    @PlanetaryComputerPreparer()
    @recorded_by_proxy
    def test_02_get_conformance_class(self, planetarycomputer_endpoint):
        """
        Test getting STAC conformance classes.

        Expected response:
        - Dictionary with 'conformsTo' key
        - List of conformance URIs
        """
        test_logger.info("=" * 80)
        test_logger.info("TEST: test_02_get_conformance_class")
        test_logger.info("=" * 80)
        test_logger.info(f"Input - endpoint: {planetarycomputer_endpoint}")

        client = self.create_client(endpoint=planetarycomputer_endpoint)

        test_logger.info("Calling: get_conformance_class()")
        response = client.stac.get_conformance_class()

        test_logger.info(f"Response type: {type(response)}")
        if hasattr(response, "as_dict"):
            response_dict = response.as_dict()
            test_logger.info(f"Response keys: {list(response_dict.keys())}")

        # Validate response structure
        assert response is not None, "Response should not be None"
        assert hasattr(
            response, "conforms_to"
        ), "Response should have 'conforms_to' attribute"

        conforms_to = response.conforms_to
        assert isinstance(
            conforms_to, list
        ), f"conformsTo should be a list, got {type(conforms_to)}"
        assert len(conforms_to) > 0, "Should have at least one conformance class"

        test_logger.info(f"Number of conformance classes: {len(conforms_to)}")
        for i, uri in enumerate(conforms_to[:5]):  # Log first 5
            test_logger.info(f"  {i + 1}. {uri}")

        test_logger.info("Test PASSED\n")

    @PlanetaryComputerPreparer()
    @recorded_by_proxy
    def test_03_get_collection(
        self, planetarycomputer_endpoint, planetarycomputer_collection_id
    ):
        """
        Test getting a specific STAC collection.

        Expected response:
        - StacCollection object
        - Contains id, title, description, extent, etc.
        """
        test_logger.info("=" * 80)
        test_logger.info("TEST: test_03_get_collection")
        test_logger.info("=" * 80)
        test_logger.info(f"Input - endpoint: {planetarycomputer_endpoint}")
        test_logger.info(f"Input - collection_id: {planetarycomputer_collection_id}")

        client = self.create_client(endpoint=planetarycomputer_endpoint)

        test_logger.info(
            f"Calling: get_collection(collection_id='{planetarycomputer_collection_id}')"
        )
        response = client.stac.get_collection(
            collection_id=planetarycomputer_collection_id
        )

        test_logger.info(f"Response type: {type(response)}")
        test_logger.info(f"Collection ID: {response.id}")
        test_logger.info(f"Collection Title: {response.title}")
        test_logger.info(f"Collection Description: {response.description[:100]}...")

        # Validate response structure
        assert response is not None, "Response should not be None"
        assert (
            response.id == planetarycomputer_collection_id
        ), "Collection ID should match requested ID"
        assert (
            response.title is not None and len(response.title) > 0
        ), "Collection should have a title"
        assert response.description is not None, "Collection should have a description"
        assert response.extent is not None, "Collection should have extent"
        assert response.license is not None, "Collection should have license"

        test_logger.info("Test PASSED\n")

    @PlanetaryComputerPreparer()
    @recorded_by_proxy
    def test_04_get_partition_type(
        self, planetarycomputer_endpoint, planetarycomputer_collection_id
    ):
        """
        Test getting partition type for a collection.

        Expected response:
        - PartitionType object
        - Contains scheme (e.g., NONE, YEAR, YEAR_MONTH)
        """
        test_logger.info("=" * 80)
        test_logger.info("TEST: test_04_get_partition_type")
        test_logger.info("=" * 80)
        test_logger.info(f"Input - endpoint: {planetarycomputer_endpoint}")
        test_logger.info(f"Input - collection_id: {planetarycomputer_collection_id}")

        client = self.create_client(endpoint=planetarycomputer_endpoint)

        test_logger.info(
            f"Calling: get_partition_type(collection_id='{planetarycomputer_collection_id}')"
        )
        response = client.stac.get_partition_type(planetarycomputer_collection_id)

        test_logger.info(f"Response type: {type(response)}")
        test_logger.info(f"Partition scheme: {response.scheme}")

        # Validate response structure
        assert response is not None, "Response should not be None"
        assert hasattr(response, "scheme"), "Response should have 'scheme' attribute"
        assert response.scheme is not None, "Partition scheme should not be None"

        # Validate scheme is a valid PartitionTypeScheme
        valid_schemes = [s.value for s in PartitionTypeScheme]
        assert (
            response.scheme in valid_schemes
        ), f"Partition scheme should be one of {valid_schemes}"

        test_logger.info("Test PASSED\n")

    @PlanetaryComputerPreparer()
    @recorded_by_proxy
    def test_05_list_render_options(
        self, planetarycomputer_endpoint, planetarycomputer_collection_id
    ):
        """
        Test listing render options for a collection.

        Expected response:
        - List of RenderOption objects
        - Each has id, name, type, options, etc.
        """
        test_logger.info("=" * 80)
        test_logger.info("TEST: test_05_list_render_options")
        test_logger.info("=" * 80)
        test_logger.info(f"Input - endpoint: {planetarycomputer_endpoint}")
        test_logger.info(f"Input - collection_id: {planetarycomputer_collection_id}")

        client = self.create_client(endpoint=planetarycomputer_endpoint)

        test_logger.info(
            f"Calling: list_render_options(collection_id='{planetarycomputer_collection_id}')"
        )
        response = client.stac.list_render_options(
            collection_id=planetarycomputer_collection_id
        )

        test_logger.info(f"Response type: {type(response)}")
        test_logger.info(f"Number of render options: {len(response)}")

        # Validate response structure
        assert isinstance(
            response, list
        ), f"Response should be a list, got {type(response)}"

        if len(response) > 0:
            first_option = response[0]
            test_logger.info(f"First render option ID: {first_option.id}")
            test_logger.info(f"First render option name: {first_option.name}")
            test_logger.info(f"First render option type: {first_option.type}")

            assert hasattr(first_option, "id"), "Render option should have 'id'"
            assert hasattr(first_option, "name"), "Render option should have 'name'"
            assert hasattr(first_option, "type"), "Render option should have 'type'"

        test_logger.info("Test PASSED\n")

    @PlanetaryComputerPreparer()
    @recorded_by_proxy
    def test_06_get_tile_settings(
        self, planetarycomputer_endpoint, planetarycomputer_collection_id
    ):
        """
        Test getting tile settings for a collection.

        Expected response:
        - TileSettings object
        - Contains max_items_per_tile, min_zoom, default_location
        """
        test_logger.info("=" * 80)
        test_logger.info("TEST: test_06_get_tile_settings")
        test_logger.info("=" * 80)
        test_logger.info(f"Input - endpoint: {planetarycomputer_endpoint}")
        test_logger.info(f"Input - collection_id: {planetarycomputer_collection_id}")

        client = self.create_client(endpoint=planetarycomputer_endpoint)

        test_logger.info(
            f"Calling: get_tile_settings(collection_id='{planetarycomputer_collection_id}')"
        )
        response = client.stac.get_tile_settings(
            collection_id=planetarycomputer_collection_id
        )

        test_logger.info(f"Response type: {type(response)}")
        if hasattr(response, "as_dict"):
            response_dict = response.as_dict()
            test_logger.info(f"Response keys: {list(response_dict.keys())}")

        # Validate response structure
        assert response is not None, "Response should not be None"

        # Log available attributes
        if hasattr(response, "max_items_per_tile"):
            test_logger.info(f"Max items per tile: {response.max_items_per_tile}")
        if hasattr(response, "min_zoom"):
            test_logger.info(f"Min zoom: {response.min_zoom}")
        if hasattr(response, "default_location"):
            test_logger.info(f"Default location: {response.default_location}")

        test_logger.info("Test PASSED\n")

    @PlanetaryComputerPreparer()
    @recorded_by_proxy
    def test_07_list_mosaics(
        self, planetarycomputer_endpoint, planetarycomputer_collection_id
    ):
        """
        Test listing mosaics for a collection.

        Expected response:
        - List of StacMosaic objects
        - Each has id, name, cql filter
        """
        test_logger.info("=" * 80)
        test_logger.info("TEST: test_07_list_mosaics")
        test_logger.info("=" * 80)
        test_logger.info(f"Input - endpoint: {planetarycomputer_endpoint}")
        test_logger.info(f"Input - collection_id: {planetarycomputer_collection_id}")

        client = self.create_client(endpoint=planetarycomputer_endpoint)

        test_logger.info(
            f"Calling: list_mosaics(collection_id='{planetarycomputer_collection_id}')"
        )
        response = client.stac.list_mosaics(
            collection_id=planetarycomputer_collection_id
        )

        test_logger.info(f"Response type: {type(response)}")
        test_logger.info(f"Number of mosaics: {len(response)}")

        # Validate response structure
        assert isinstance(
            response, list
        ), f"Response should be a list, got {type(response)}"

        if len(response) > 0:
            first_mosaic = response[0]
            test_logger.info(f"First mosaic ID: {first_mosaic.id}")
            test_logger.info(f"First mosaic name: {first_mosaic.name}")

            assert hasattr(first_mosaic, "id"), "Mosaic should have 'id'"
            assert hasattr(first_mosaic, "name"), "Mosaic should have 'name'"

        test_logger.info("Test PASSED\n")

    @PlanetaryComputerPreparer()
    @recorded_by_proxy
    def test_08_get_collection_queryables(
        self, planetarycomputer_endpoint, planetarycomputer_collection_id
    ):
        """
        Test getting queryables for a collection.

        Expected response:
        - Dictionary with 'properties' key
        - Properties contain queryable definitions
        """
        test_logger.info("=" * 80)
        test_logger.info("TEST: test_08_get_collection_queryables")
        test_logger.info("=" * 80)
        test_logger.info(f"Input - endpoint: {planetarycomputer_endpoint}")
        test_logger.info(f"Input - collection_id: {planetarycomputer_collection_id}")

        client = self.create_client(endpoint=planetarycomputer_endpoint)

        test_logger.info(
            f"Calling: get_collection_queryables(collection_id='{planetarycomputer_collection_id}')"
        )
        response = client.stac.get_collection_queryables(
            collection_id=planetarycomputer_collection_id
        )

        test_logger.info(f"Response type: {type(response)}")
        test_logger.info(
            f"Response keys: {list(response.keys()) if isinstance(response, dict) else 'N/A'}"
        )

        # Validate response structure
        assert isinstance(
            response, dict
        ), f"Response should be a dict, got {type(response)}"
        assert "properties" in response, "Response should have 'properties' key"

        properties = response["properties"]
        test_logger.info(f"Number of queryables: {len(properties)}")

        if len(properties) > 0:
            # Log first few queryables
            for i, (key, value) in enumerate(list(properties.items())[:5]):
                test_logger.info(f"  Queryable {i + 1}: {key}")

        test_logger.info("Test PASSED\n")

    @PlanetaryComputerPreparer()
    @recorded_by_proxy
    def test_09_list_queryables(self, planetarycomputer_endpoint):
        """
        Test listing all queryables (global).

        Expected response:
        - Dictionary with 'properties' key
        - Properties contain global queryable definitions
        """
        test_logger.info("=" * 80)
        test_logger.info("TEST: test_09_list_queryables")
        test_logger.info("=" * 80)
        test_logger.info(f"Input - endpoint: {planetarycomputer_endpoint}")

        client = self.create_client(endpoint=planetarycomputer_endpoint)

        test_logger.info("Calling: list_queryables()")
        response = client.stac.list_queryables()

        test_logger.info(f"Response type: {type(response)}")
        test_logger.info(
            f"Response keys: {list(response.keys()) if isinstance(response, dict) else 'N/A'}"
        )

        # Validate response structure
        assert isinstance(
            response, dict
        ), f"Response should be a dict, got {type(response)}"
        assert "properties" in response, "Response should have 'properties' key"

        properties = response["properties"]
        test_logger.info(f"Number of global queryables: {len(properties)}")

        test_logger.info("Test PASSED\n")

    @PlanetaryComputerPreparer()
    @recorded_by_proxy
    def test_10_get_collection_configuration(
        self, planetarycomputer_endpoint, planetarycomputer_collection_id
    ):
        """
        Test getting collection configuration.

        Expected response:
        - Configuration object with various settings
        - May include tile settings, render options, etc.
        """
        test_logger.info("=" * 80)
        test_logger.info("TEST: test_10_get_collection_configuration")
        test_logger.info("=" * 80)
        test_logger.info(f"Input - endpoint: {planetarycomputer_endpoint}")
        test_logger.info(f"Input - collection_id: {planetarycomputer_collection_id}")

        client = self.create_client(endpoint=planetarycomputer_endpoint)

        test_logger.info(
            f"Calling: get_collection_configuration(collection_id='{planetarycomputer_collection_id}')"
        )
        response = client.stac.get_collection_configuration(
            collection_id=planetarycomputer_collection_id
        )

        test_logger.info(f"Response type: {type(response)}")
        if hasattr(response, "as_dict"):
            response_dict = response.as_dict()
            test_logger.info(f"Response keys: {list(response_dict.keys())}")

        # Validate response structure
        assert response is not None, "Response should not be None"

        test_logger.info("Test PASSED\n")

    @PlanetaryComputerPreparer()
    @recorded_by_proxy
    def test_11_get_collection_thumbnail(
        self, planetarycomputer_endpoint, planetarycomputer_collection_id
    ):
        """
        Test getting collection thumbnail.

        Expected response:
        - Binary image data (streaming generator)
        - Valid image format (PNG/JPEG)
        """
        test_logger.info("=" * 80)
        test_logger.info("TEST: test_11_get_collection_thumbnail")
        test_logger.info("=" * 80)
        test_logger.info(f"Input - endpoint: {planetarycomputer_endpoint}")
        test_logger.info(f"Input - collection_id: {planetarycomputer_collection_id}")

        client = self.create_client(endpoint=planetarycomputer_endpoint)

        # First check if collection has thumbnail asset
        collection = client.stac.get_collection(
            collection_id=planetarycomputer_collection_id
        )

        if (
            not hasattr(collection, "assets")
            or collection.assets is None
            or "thumbnail" not in collection.assets
        ):
            assert False, "Collection does not have a thumbnail asset"

        test_logger.info(
            f"Calling: get_collection_thumbnail(collection_id='{planetarycomputer_collection_id}')"
        )
        response = client.stac.get_collection_thumbnail(
            collection_id=planetarycomputer_collection_id
        )

        test_logger.info(f"Response type: {type(response)}")

        # Collect the streaming response into bytes
        thumbnail_bytes = b"".join(response)
        test_logger.info(f"Thumbnail size: {len(thumbnail_bytes)} bytes")
        test_logger.info(f"First 16 bytes (hex): {thumbnail_bytes[:16].hex()}")

        # Validate image data
        assert len(thumbnail_bytes) > 0, "Thumbnail bytes should not be empty"
        assert (
            len(thumbnail_bytes) > 100
        ), f"Thumbnail should be substantial, got only {len(thumbnail_bytes)} bytes"

        # Check for common image format magic bytes
        # PNG: 89 50 4E 47
        # JPEG: FF D8 FF
        is_png = thumbnail_bytes[:8] == b"\x89PNG\r\n\x1a\n"
        is_jpeg = thumbnail_bytes[:3] == b"\xff\xd8\xff"

        assert is_png or is_jpeg, "Thumbnail should be either PNG or JPEG format"

        if is_png:
            test_logger.info("Thumbnail format: PNG")
        elif is_jpeg:
            test_logger.info("Thumbnail format: JPEG")

        test_logger.info("Test PASSED\n")

    @PlanetaryComputerPreparer()
    @recorded_by_proxy
    def test_12_create_render_option(
        self, planetarycomputer_endpoint, planetarycomputer_collection_id
    ):
        """
        Test creating a render option for a collection.
        """
        test_logger.info("=" * 80)
        test_logger.info("TEST: test_12_create_render_option")
        test_logger.info("=" * 80)

        client = self.create_client(endpoint=planetarycomputer_endpoint)

        from azure.planetarycomputer.models import RenderOption, RenderOptionType

        # Check if render option already exists and delete it
        try:
            client.stac.get_render_option(
                collection_id=planetarycomputer_collection_id,
                render_option_id="test-natural-color",
            )
            test_logger.info(
                "Render option 'test-natural-color' already exists, deleting it first"
            )
            client.stac.delete_render_option(
                collection_id=planetarycomputer_collection_id,
                render_option_id="test-natural-color",
            )
            test_logger.info("Existing render option deleted")
        except Exception as e:
            test_logger.info(f"Render option does not exist (expected): {e}")

        render_option = RenderOption(
            id="test-natural-color",
            name="Test Natural color",
            type=RenderOptionType.RASTER_TILE,
            options="assets=image&asset_bidx=image|1,2,3",
            min_zoom=6,
        )

        test_logger.info(
            f"Calling: create_render_option(collection_id='{planetarycomputer_collection_id}', body={render_option})"
        )
        response = client.stac.create_render_option(
            collection_id=planetarycomputer_collection_id, body=render_option
        )

        test_logger.info(f"Response: {response}")
        assert response is not None
        assert response.id == "test-natural-color"
        assert response.name == "Test Natural color"

        test_logger.info("Test PASSED\n")

    @PlanetaryComputerPreparer()
    @recorded_by_proxy
    def test_13_get_render_option(
        self, planetarycomputer_endpoint, planetarycomputer_collection_id
    ):
        """
        Test getting a specific render option.
        """
        test_logger.info("=" * 80)
        test_logger.info("TEST: test_13_get_render_option")
        test_logger.info("=" * 80)

        client = self.create_client(endpoint=planetarycomputer_endpoint)

        test_logger.info(
            f"Calling: get_render_option(collection_id='{planetarycomputer_collection_id}', render_option_id='test-natural-color')"
        )
        response = client.stac.get_render_option(
            collection_id=planetarycomputer_collection_id,
            render_option_id="test-natural-color",
        )

        test_logger.info(f"Response: {response}")
        assert response is not None
        assert response.id == "test-natural-color"
        assert response.name is not None

        test_logger.info("Test PASSED\n")

    @PlanetaryComputerPreparer()
    @recorded_by_proxy
    def test_14_replace_render_option(
        self, planetarycomputer_endpoint, planetarycomputer_collection_id
    ):
        """
        Test creating or replacing a render option.
        """
        test_logger.info("=" * 80)
        test_logger.info("TEST: test_14_replace_render_option")
        test_logger.info("=" * 80)

        client = self.create_client(endpoint=planetarycomputer_endpoint)

        from azure.planetarycomputer.models import RenderOption, RenderOptionType

        render_option = RenderOption(
            id="test-natural-color",
            name="Test Natural color updated",
            description="RGB from visual assets - updated",
            type=RenderOptionType.RASTER_TILE,
            options="assets=image&asset_bidx=image|1,2,3",
            min_zoom=6,
        )

        test_logger.info(
            f"Calling: create_or_replace_render_option(collection_id='{planetarycomputer_collection_id}', render_option_id='test-natural-color', body={render_option})"
        )
        response = client.stac.replace_render_option(
            collection_id=planetarycomputer_collection_id,
            render_option_id="test-natural-color",
            body=render_option,
        )

        test_logger.info(f"Response: {response}")
        assert response is not None
        assert response.id == "test-natural-color"
        assert response.description == "RGB from visual assets - updated"

        test_logger.info("Test PASSED\n")

    @PlanetaryComputerPreparer()
    @recorded_by_proxy
    def test_14a_delete_render_option(
        self, planetarycomputer_endpoint, planetarycomputer_collection_id
    ):
        """
        Test deleting a render option.
        First creates a render option specifically for deletion.
        """
        test_logger.info("=" * 80)
        test_logger.info("TEST: test_14a_delete_render_option")
        test_logger.info("=" * 80)

        client = self.create_client(endpoint=planetarycomputer_endpoint)

        from azure.planetarycomputer.models import RenderOption, RenderOptionType

        # Create a render option to be deleted
        render_option = RenderOption(
            id="test-render-opt-delete",
            name="Test Render Option To Be Deleted",
            type=RenderOptionType.RASTER_TILE,
            options="assets=image&asset_bidx=image|1,2,3",
            min_zoom=6,
        )

        test_logger.info(f"Creating render option for deletion: {render_option.id}")
        client.stac.create_render_option(
            collection_id=planetarycomputer_collection_id, body=render_option
        )

        # Verify it exists
        retrieved = client.stac.get_render_option(
            collection_id=planetarycomputer_collection_id,
            render_option_id="test-render-opt-delete",
        )
        assert retrieved is not None
        test_logger.info("Render option created successfully")

        # Now delete it
        test_logger.info(
            f"Calling: delete_render_option(collection_id='{planetarycomputer_collection_id}', render_option_id='test-render-opt-delete')"
        )
        client.stac.delete_render_option(
            collection_id=planetarycomputer_collection_id,
            render_option_id="test-render-opt-delete",
        )

        test_logger.info("Render option deleted successfully")

        # Verify deletion
        try:
            client.stac.get_render_option(
                collection_id=planetarycomputer_collection_id,
                render_option_id="test-render-opt-delete",
            )
            assert False, "Render option should have been deleted"
        except Exception as e:
            test_logger.info(f"Confirmed deletion (404 expected): {e}")
            assert (
                "404" in str(e)
                or "Not Found" in str(e)
                or "not found" in str(e).lower()
            )

        test_logger.info("Test PASSED\n")

    @PlanetaryComputerPreparer()
    @recorded_by_proxy
    def test_15_add_mosaic(
        self, planetarycomputer_endpoint, planetarycomputer_collection_id
    ):
        """
        Test adding a mosaic to a collection.
        """
        test_logger.info("=" * 80)
        test_logger.info("TEST: test_15_add_mosaic")
        test_logger.info("=" * 80)

        client = self.create_client(endpoint=planetarycomputer_endpoint)

        from azure.planetarycomputer.models import StacMosaic

        # Check if mosaic already exists and delete it
        try:
            client.stac.get_mosaic(
                collection_id=planetarycomputer_collection_id, mosaic_id="test-mosaic-1"
            )
            test_logger.info("Mosaic 'test-mosaic-1' already exists, deleting it first")
            client.stac.delete_mosaic(
                collection_id=planetarycomputer_collection_id, mosaic_id="test-mosaic-1"
            )
            test_logger.info("Existing mosaic deleted")
        except Exception as e:
            test_logger.info(f"Mosaic does not exist (expected): {e}")

        mosaic = StacMosaic(
            id="test-mosaic-1",
            name="Test Most recent available",
            cql=[],
        )

        test_logger.info(
            f"Calling: add_mosaic(collection_id='{planetarycomputer_collection_id}', body={mosaic})"
        )
        response = client.stac.add_mosaic(
            collection_id=planetarycomputer_collection_id, body=mosaic
        )

        test_logger.info(f"Response: {response}")
        assert response is not None
        assert response.id == "test-mosaic-1"
        assert response.name == "Test Most recent available"

        test_logger.info("Test PASSED\n")

    @PlanetaryComputerPreparer()
    @recorded_by_proxy
    def test_16_get_mosaic(
        self, planetarycomputer_endpoint, planetarycomputer_collection_id
    ):
        """
        Test getting a specific mosaic.
        """
        test_logger.info("=" * 80)
        test_logger.info("TEST: test_16_get_mosaic")
        test_logger.info("=" * 80)

        client = self.create_client(endpoint=planetarycomputer_endpoint)

        test_logger.info(
            f"Calling: get_mosaic(collection_id='{planetarycomputer_collection_id}', mosaic_id='test-mosaic-1')"
        )
        response = client.stac.get_mosaic(
            collection_id=planetarycomputer_collection_id, mosaic_id="test-mosaic-1"
        )

        test_logger.info(f"Response: {response}")
        assert response is not None
        assert response.id == "test-mosaic-1"
        assert response.name is not None

        test_logger.info("Test PASSED\n")

    @PlanetaryComputerPreparer()
    @recorded_by_proxy
    def test_17_replace_mosaic(
        self, planetarycomputer_endpoint, planetarycomputer_collection_id
    ):
        """
        Test creating or replacing a mosaic.
        """
        test_logger.info("=" * 80)
        test_logger.info("TEST: test_17_replace_mosaic")
        test_logger.info("=" * 80)

        client = self.create_client(endpoint=planetarycomputer_endpoint)

        from azure.planetarycomputer.models import StacMosaic

        mosaic = StacMosaic(
            id="test-mosaic-1",
            name="Test Most recent available",
            description="Most recent available imagery in this collection - updated",
            cql=[],
        )

        test_logger.info(
            f"Calling: create_or_replace_mosaic(collection_id='{planetarycomputer_collection_id}', mosaic_id='test-mosaic-1', body={mosaic})"
        )
        response = client.stac.replace_mosaic(
            collection_id=planetarycomputer_collection_id,
            mosaic_id="test-mosaic-1",
            body=mosaic,
        )

        test_logger.info(f"Response: {response}")
        assert response is not None
        assert response.id == "test-mosaic-1"
        assert response.description is not None

        test_logger.info("Test PASSED\n")

    @PlanetaryComputerPreparer()
    @recorded_by_proxy
    def test_17a_delete_mosaic(
        self, planetarycomputer_endpoint, planetarycomputer_collection_id
    ):
        """
        Test deleting a mosaic.
        First creates a mosaic specifically for deletion.
        """
        test_logger.info("=" * 80)
        test_logger.info("TEST: test_17a_delete_mosaic")
        test_logger.info("=" * 80)

        client = self.create_client(endpoint=planetarycomputer_endpoint)

        from azure.planetarycomputer.models import StacMosaic

        # Create a mosaic to be deleted
        mosaic = StacMosaic(
            id="test-mosaic-to-be-deleted",
            name="Test Mosaic To Be Deleted",
            cql=[],
        )

        test_logger.info(f"Creating mosaic for deletion: {mosaic.id}")
        client.stac.add_mosaic(
            collection_id=planetarycomputer_collection_id, body=mosaic
        )

        # Verify it exists
        retrieved = client.stac.get_mosaic(
            collection_id=planetarycomputer_collection_id,
            mosaic_id="test-mosaic-to-be-deleted",
        )
        assert retrieved is not None
        test_logger.info("Mosaic created successfully")

        # Now delete it
        test_logger.info(
            f"Calling: delete_mosaic(collection_id='{planetarycomputer_collection_id}', mosaic_id='test-mosaic-to-be-deleted')"
        )
        client.stac.delete_mosaic(
            collection_id=planetarycomputer_collection_id,
            mosaic_id="test-mosaic-to-be-deleted",
        )

        test_logger.info("Mosaic deleted successfully")

        # Verify deletion
        try:
            client.stac.get_mosaic(
                collection_id=planetarycomputer_collection_id,
                mosaic_id="test-mosaic-to-be-deleted",
            )
            assert False, "Mosaic should have been deleted"
        except Exception as e:
            test_logger.info(f"Confirmed deletion (404 expected): {e}")
            assert (
                "404" in str(e)
                or "Not Found" in str(e)
                or "not found" in str(e).lower()
            )

        test_logger.info("Test PASSED\n")

    @PlanetaryComputerPreparer()
    @recorded_by_proxy
    def test_18_replace_partition_type(self, planetarycomputer_endpoint):
        """
        Test replacing partition type by creating a temporary collection.
        """
        test_logger.info("=" * 80)
        test_logger.info("TEST: test_18_replace_partition_type")
        test_logger.info("=" * 80)

        client = self.create_client(endpoint=planetarycomputer_endpoint)

        from azure.planetarycomputer.models import (
            PartitionType,
            PartitionTypeScheme,
            StacExtensionSpatialExtent,
            StacCollectionTemporalExtent,
            StacExtensionExtent,
        )

        # Create a temporary collection for partition type testing
        test_collection_id = "test-partition-type-collection"
        test_logger.info(f"Creating temporary collection: {test_collection_id}")

        # Check if collection exists and delete it first
        try:
            existing_collection = client.stac.get_collection(
                collection_id=test_collection_id
            )
            if existing_collection:
                test_logger.info(
                    f"Collection '{test_collection_id}' already exists, deleting first..."
                )
                delete_poller = client.stac.begin_delete_collection(
                    collection_id=test_collection_id, polling=True
                )
                delete_poller.result()
                test_logger.info(f"Deleted existing collection '{test_collection_id}'")
        except Exception:
            test_logger.info(
                f"Collection '{test_collection_id}' does not exist, proceeding with creation"
            )

        # Define collection extents
        spatial_extent = StacExtensionSpatialExtent(bounding_box=[[-180, -90, 180, 90]])

        temporal_extent = StacCollectionTemporalExtent(
            interval=[
                [
                    datetime.datetime.fromisoformat("2020-01-01T00:00:00+00:00"),
                    datetime.datetime.fromisoformat("2099-12-31T23:59:59+00:00"),
                ]
            ]
        )

        extent = StacExtensionExtent(spatial=spatial_extent, temporal=temporal_extent)
        # Create collection payload
        collection_data = {
            "id": test_collection_id,
            "description": "Temporary collection for partition type testing",
            "extent": extent.as_dict(),
            "license": "proprietary",
            "links": [],
            "stac_version": "1.0.0",
            "title": "Test Partition Type Collection",
            "type": "Collection",
        }

        # Create the collection using the correct API
        test_logger.info("Creating collection using begin_create_collection")
        create_poller = client.stac.begin_create_collection(
            body=collection_data, polling=True
        )
        create_poller.result()
        test_logger.info("Temporary collection created")

        try:
            # Set partition type
            partition_type = PartitionType(scheme=PartitionTypeScheme.YEAR)

            test_logger.info(
                f"Calling: replace_partition_type(collection_id='{test_collection_id}', body={partition_type})"
            )
            client.stac.replace_partition_type(
                collection_id=test_collection_id, body=partition_type
            )

            # Verify the change
            updated_partition = client.stac.get_partition_type(test_collection_id)
            assert updated_partition.scheme == PartitionTypeScheme.YEAR

            test_logger.info("Partition type set successfully")

        finally:
            # Clean up: delete the temporary collection
            test_logger.info(f"Deleting temporary collection: {test_collection_id}")
            try:
                delete_poller = client.stac.begin_delete_collection(
                    collection_id=test_collection_id, polling=True
                )
                delete_poller.result()
                test_logger.info("Temporary collection deleted")
            except Exception as e:
                test_logger.warning(f"Failed to delete temporary collection: {e}")

        test_logger.info("Test PASSED\n")

    @PlanetaryComputerPreparer()
    @recorded_by_proxy
    def test_19_replace_tile_settings(
        self, planetarycomputer_endpoint, planetarycomputer_collection_id
    ):
        """
        Test replacing tile settings for a collection.
        """
        test_logger.info("=" * 80)
        test_logger.info("TEST: test_19_replace_tile_settings")
        test_logger.info("=" * 80)

        client = self.create_client(endpoint=planetarycomputer_endpoint)

        from azure.planetarycomputer.models import TileSettings

        tile_settings = TileSettings(
            default_location=None,
            max_items_per_tile=35,
            min_zoom=6,
        )

        test_logger.info(
            f"Calling: replace_tile_settings(collection_id='{planetarycomputer_collection_id}', body={tile_settings})"
        )
        response = client.stac.replace_tile_settings(
            collection_id=planetarycomputer_collection_id, body=tile_settings
        )

        test_logger.info(f"Response: {response}")
        assert response is not None
        assert response.max_items_per_tile == 35
        assert response.min_zoom == 6

        test_logger.info("Test PASSED\n")

    @PlanetaryComputerPreparer()
    @recorded_by_proxy
    def test_20_create_queryables(
        self, planetarycomputer_endpoint, planetarycomputer_collection_id
    ):
        """
        Test creating queryables for a collection.
        """
        test_logger.info("=" * 80)
        test_logger.info("TEST: test_20_create_queryables")
        test_logger.info("=" * 80)

        client = self.create_client(endpoint=planetarycomputer_endpoint)

        from azure.planetarycomputer.models import (
            StacQueryable,
            StacQueryableDefinitionDataType,
        )

        # Check if queryable already exists and delete it
        try:
            queryables = client.stac.get_collection_queryables(
                collection_id=planetarycomputer_collection_id
            )
            if "test:property" in queryables.get("properties", {}):
                test_logger.info(
                    "Queryable 'test:property' already exists, deleting it first"
                )
                client.stac.delete_queryable(
                    collection_id=planetarycomputer_collection_id,
                    queryable_name="test:property",
                )
                test_logger.info("Existing queryable deleted")
            else:
                test_logger.info("Queryable does not exist (expected)")
        except Exception as e:
            test_logger.info(f"Error checking queryable existence: {e}")

        queryable = StacQueryable(
            name="test:property",
            data_type=StacQueryableDefinitionDataType.NUMBER,
            create_index=False,
            definition={
                "data_type": StacQueryableDefinitionDataType.NUMBER,
            },
        )

        test_logger.info(
            f"Calling: create_queryables(collection_id='{planetarycomputer_collection_id}', body=[queryable])"
        )
        response = client.stac.create_queryables(
            collection_id=planetarycomputer_collection_id, body=[queryable]
        )

        test_logger.info(f"Response: {response}")
        assert response is not None

        # Response is a list of queryables
        assert isinstance(
            response, list
        ), f"Response should be a list, got {type(response)}"
        assert len(response) > 0, "Response should contain at least one queryable"

        # Verify our queryable was created
        queryable_names = [
            q.get("name") if isinstance(q, dict) else q.name for q in response
        ]
        assert (
            "test:property" in queryable_names
        ), "Created queryable 'test:property' should be in response"

        test_logger.info("Test PASSED\n")

    @PlanetaryComputerPreparer()
    @recorded_by_proxy
    def test_21_replace_queryable(
        self, planetarycomputer_endpoint, planetarycomputer_collection_id
    ):
        """
        Test creating or replacing a queryable.
        """
        test_logger.info("=" * 80)
        test_logger.info("TEST: test_21_replace_queryable")
        test_logger.info("=" * 80)

        client = self.create_client(endpoint=planetarycomputer_endpoint)

        from azure.planetarycomputer.models import (
            StacQueryable,
            StacQueryableDefinitionDataType,
        )

        queryable = StacQueryable(
            name="test:property",
            data_type=StacQueryableDefinitionDataType.NUMBER,
            create_index=False,
            definition={
                "description": "Test property - updated",
            },
        )

        test_logger.info(
            f"Calling: create_or_replace_queryable(collection_id='{planetarycomputer_collection_id}', queryable_name='test:property', body=queryable)"
        )
        response = client.stac.replace_queryable(
            collection_id=planetarycomputer_collection_id,
            queryable_name="test:property",
            body=queryable,
        )

        test_logger.info(f"Response: {response}")
        assert response is not None

        test_logger.info("Test PASSED\n")

    @PlanetaryComputerPreparer()
    @recorded_by_proxy
    def test_21a_delete_queryable(
        self, planetarycomputer_endpoint, planetarycomputer_collection_id
    ):
        """
        Test deleting a queryable.
        First creates a queryable specifically for deletion.
        """
        test_logger.info("=" * 80)
        test_logger.info("TEST: test_21a_delete_queryable")
        test_logger.info("=" * 80)

        client = self.create_client(endpoint=planetarycomputer_endpoint)

        from azure.planetarycomputer.models import (
            StacQueryable,
            StacQueryableDefinitionDataType,
        )

        # Create a queryable to be deleted
        queryable = StacQueryable(
            name="test:property_to_be_deleted",
            data_type=StacQueryableDefinitionDataType.NUMBER,
            create_index=False,
            definition={
                "description": "Test property for deletion",
            },
        )

        test_logger.info(f"Creating queryable for deletion: {queryable.name}")
        client.stac.create_queryables(
            collection_id=planetarycomputer_collection_id, body=[queryable]
        )

        # Verify it exists
        queryables = client.stac.get_collection_queryables(
            collection_id=planetarycomputer_collection_id
        )
        assert "test:property_to_be_deleted" in queryables["properties"]
        test_logger.info("Queryable created successfully")

        # Now delete it
        test_logger.info(
            f"Calling: delete_queryable(collection_id='{planetarycomputer_collection_id}', queryable_name='test:property_to_be_deleted')"
        )
        client.stac.delete_queryable(
            collection_id=planetarycomputer_collection_id,
            queryable_name="test:property_to_be_deleted",
        )

        test_logger.info("Queryable deleted successfully")

        # Verify deletion
        queryables_after = client.stac.get_collection_queryables(
            collection_id=planetarycomputer_collection_id
        )
        assert (
            "test:property_to_be_deleted" not in queryables_after["properties"]
        ), "Queryable should have been deleted"

        test_logger.info("Test PASSED\n")