1
1
import json
2
2
import os
3
3
4
+ import pytest
5
+
4
6
from pycsw .core .util import parse_ini_config
5
7
from pycsw .ogc .api .records import API
6
8
@@ -14,15 +16,125 @@ def get_test_file_path(filename):
14
16
return f'tests/unittests/{ filename } '
15
17
16
18
17
- def test_landing_page ():
19
+ @pytest .fixture ()
20
+ def config ():
21
+ return parse_ini_config (get_test_file_path ('oarec-default.cfg' ))
22
+
18
23
19
- api_ = API (parse_ini_config (get_test_file_path ('oarec-default.cfg' )))
24
+ @pytest .fixture ()
25
+ def api (config ):
26
+ return API (config )
20
27
21
- headers , status , content = api_ .landing_page ({}, {'f' : 'json' })
28
+
29
+ def test_landing_page (api ):
30
+ headers , status , content = api .landing_page ({}, {'f' : 'json' })
22
31
content = json .loads (content )
23
32
24
33
assert headers ['Content-Type' ] == 'application/json'
25
34
assert status == 200
26
35
assert len (content ['links' ]) == 10
27
36
28
- headers , status , content = api_ .landing_page ({}, {'f' : 'json' })
37
+ for link in content ['links' ]:
38
+ assert link ['href' ].startswith (api .config ['server' ]['url' ])
39
+
40
+ headers , status , content = api .landing_page ({}, {'f' : 'html' })
41
+ assert status == 200
42
+ assert headers ['Content-Type' ] == 'text/html'
43
+
44
+
45
+ def test_conformance (api ):
46
+ content = json .loads (api .conformance ({}, {})[2 ])
47
+
48
+ assert len (content ['conformsTo' ]) == 6
49
+
50
+
51
+ def test_collections (api ):
52
+ content = json .loads (api .collections ({}, {})[2 ])
53
+
54
+ assert len (content ['links' ]) == 2
55
+ assert len (content ['collections' ]) == 1
56
+
57
+ content = json .loads (api .collections ({}, {}, True )[2 ])
58
+ assert len (content ['links' ]) == 2
59
+ assert content ['id' ] == 'metadata:main'
60
+ assert content ['title' ] == 'pycsw Geospatial Catalogue'
61
+ assert content ['description' ] == 'pycsw is an OGC CSW server implementation written in Python' # noqa
62
+ assert content ['itemType' ] == 'record'
63
+
64
+
65
+ def test_queryables (api ):
66
+ content = json .loads (api .queryables ({}, {})[2 ])
67
+
68
+ assert content ['type' ] == 'object'
69
+ assert content ['title' ] == 'pycsw Geospatial Catalogue'
70
+ assert content ['$id' ] == 'http://localhost/pycsw/oarec/collections/metadata:main/queryables' # noqa
71
+ assert content ['$schema' ] == 'http://json-schema.org/draft/2019-09/schema'
72
+
73
+ assert len (content ['properties' ]) == 59
74
+
75
+
76
+ def test_items (api ):
77
+ content = json .loads (api .items ({}, {})[2 ])
78
+
79
+ assert content ['type' ] == 'FeatureCollection'
80
+ assert len (content ['links' ]) == 4
81
+ assert content ['numberMatched' ] == 12
82
+ assert content ['numberReturned' ] == 10
83
+ assert len (content ['features' ]) == 10
84
+ assert len (content ['features' ]) == content ['numberReturned' ]
85
+
86
+ params = {'q' : 'Lorem' }
87
+ content = json .loads (api .items ({}, params )[2 ])
88
+ assert content ['numberMatched' ] == 5
89
+ assert content ['numberReturned' ] == 5
90
+ assert len (content ['features' ]) == content ['numberReturned' ]
91
+
92
+ params = {'bbox' : '-50,0,50,80' }
93
+ content = json .loads (api .items ({}, params )[2 ])
94
+ assert content ['numberMatched' ] == 3
95
+ assert content ['numberReturned' ] == 3
96
+ assert len (content ['features' ]) == content ['numberReturned' ]
97
+
98
+ params = {'bbox' : '-50,0,50,80' , 'q' : 'Lorem' }
99
+ content = json .loads (api .items ({}, params )[2 ])
100
+ assert content ['numberMatched' ] == 1
101
+ assert content ['numberReturned' ] == 1
102
+ assert len (content ['features' ]) == content ['numberReturned' ]
103
+
104
+ params = {'filter' : 'title LIKE "%%Lorem%%"' }
105
+ content = json .loads (api .items ({}, params )[2 ])
106
+ assert content ['numberMatched' ] == 2
107
+ assert content ['numberReturned' ] == 2
108
+ assert len (content ['features' ]) == content ['numberReturned' ]
109
+
110
+ params = {'filter' : 'title LIKE "%%Lorem%%"' , 'q' : 'iPsUm' }
111
+ content = json .loads (api .items ({}, params )[2 ])
112
+ assert content ['numberMatched' ] == 2
113
+ assert content ['numberReturned' ] == 2
114
+ assert len (content ['features' ]) == content ['numberReturned' ]
115
+
116
+ params = {'limit' : 4 }
117
+ content = json .loads (api .items ({}, params )[2 ])
118
+ assert content ['numberMatched' ] == 12
119
+ assert content ['numberReturned' ] == 4
120
+ assert len (content ['features' ]) == content ['numberReturned' ]
121
+
122
+ params = {'limit' : 4 , 'startindex' : 10 }
123
+ content = json .loads (api .items ({}, params )[2 ])
124
+ assert content ['numberMatched' ] == 12
125
+ assert content ['numberReturned' ] == 2
126
+ assert len (content ['features' ]) == content ['numberReturned' ]
127
+
128
+
129
+ def test_item (api ):
130
+ item = 'urn:uuid:19887a8a-f6b0-4a63-ae56-7fba0e17801f'
131
+ content = json .loads (api .item ({}, {}, item )[2 ])
132
+
133
+ assert content ['id' ] == item
134
+ assert content ['type' ] == 'Feature'
135
+ assert content ['properties' ]['title' ] == 'Lorem ipsum'
136
+ assert content ['properties' ]['keywords' ] == ['Tourism--Greece' ]
137
+
138
+ item = 'urn:uuid:19887a8a-f6b0-4a63-ae56-7fba0e17801f'
139
+ params = {'f' : 'xml' }
140
+ content = api .item ({}, params , item )[2 ]
0 commit comments