@@ -44,6 +44,141 @@ def test_create_item_conflict(app_client, load_test_data):
44
44
assert resp .status_code == 409
45
45
46
46
47
+ def test_create_item_duplicate (app_client , load_test_data ):
48
+ """Test creation of an item id which already exists but in a different collection(transactions extension)"""
49
+
50
+ # add test_item to test-collection
51
+ test_item = load_test_data ("test_item.json" )
52
+ resp = app_client .post (
53
+ f"/collections/{ test_item ['collection' ]} /items" , json = test_item
54
+ )
55
+ assert resp .status_code == 200
56
+
57
+ # add test_item to test-collection again, resource already exists
58
+ test_item = load_test_data ("test_item.json" )
59
+ resp = app_client .post (
60
+ f"/collections/{ test_item ['collection' ]} /items" , json = test_item
61
+ )
62
+ assert resp .status_code == 409
63
+
64
+ # create "test-collection-2"
65
+ collection_2 = load_test_data ("test_collection.json" )
66
+ collection_2 ["id" ] = "test-collection-2"
67
+ resp = app_client .post ("/collections" , json = collection_2 )
68
+ assert resp .status_code == 200
69
+
70
+ # add test_item to test-collection-2, posts successfully
71
+ test_item ["collection" ] = "test-collection-2"
72
+ resp = app_client .post (
73
+ f"/collections/{ test_item ['collection' ]} /items" , json = test_item
74
+ )
75
+ assert resp .status_code == 200
76
+
77
+
78
+ def test_delete_item_duplicate (app_client , load_test_data ):
79
+ """Test creation of an item id which already exists but in a different collection(transactions extension)"""
80
+
81
+ # add test_item to test-collection
82
+ test_item = load_test_data ("test_item.json" )
83
+ resp = app_client .post (
84
+ f"/collections/{ test_item ['collection' ]} /items" , json = test_item
85
+ )
86
+ assert resp .status_code == 200
87
+
88
+ # create "test-collection-2"
89
+ collection_2 = load_test_data ("test_collection.json" )
90
+ collection_2 ["id" ] = "test-collection-2"
91
+ resp = app_client .post ("/collections" , json = collection_2 )
92
+ assert resp .status_code == 200
93
+
94
+ # add test_item to test-collection-2
95
+ test_item ["collection" ] = "test-collection-2"
96
+ resp = app_client .post (
97
+ f"/collections/{ test_item ['collection' ]} /items" , json = test_item
98
+ )
99
+ assert resp .status_code == 200
100
+
101
+ # delete test_item from test-collection
102
+ test_item ["collection" ] = "test-collection"
103
+ resp = app_client .delete (
104
+ f"/collections/{ test_item ['collection' ]} /items/{ test_item ['id' ]} "
105
+ )
106
+ assert resp .status_code == 200
107
+
108
+ # test-item in test-collection has already been deleted
109
+ resp = app_client .delete (
110
+ f"/collections/{ test_item ['collection' ]} /items/{ test_item ['id' ]} "
111
+ )
112
+ assert resp .status_code == 404
113
+
114
+ # test-item in test-collection-2 still exists, was not deleted
115
+ test_item ["collection" ] = "test-collection-2"
116
+ resp = app_client .post (
117
+ f"/collections/{ test_item ['collection' ]} /items" , json = test_item
118
+ )
119
+ assert resp .status_code == 409
120
+
121
+
122
+ def test_update_item_duplicate (app_client , load_test_data ):
123
+ """Test creation of an item id which already exists but in a different collection(transactions extension)"""
124
+
125
+ # add test_item to test-collection
126
+ test_item = load_test_data ("test_item.json" )
127
+ resp = app_client .post (
128
+ f"/collections/{ test_item ['collection' ]} /items" , json = test_item
129
+ )
130
+ assert resp .status_code == 200
131
+
132
+ # create "test-collection-2"
133
+ collection_2 = load_test_data ("test_collection.json" )
134
+ collection_2 ["id" ] = "test-collection-2"
135
+ resp = app_client .post ("/collections" , json = collection_2 )
136
+ assert resp .status_code == 200
137
+
138
+ # add test_item to test-collection-2
139
+ test_item ["collection" ] = "test-collection-2"
140
+ resp = app_client .post (
141
+ f"/collections/{ test_item ['collection' ]} /items" , json = test_item
142
+ )
143
+ assert resp .status_code == 200
144
+
145
+ # update gsd in test_item, test-collection-2
146
+ test_item ["properties" ]["gsd" ] = 16
147
+ resp = app_client .put (
148
+ f"/collections/{ test_item ['collection' ]} /items" , json = test_item
149
+ )
150
+ assert resp .status_code == 200
151
+ updated_item = resp .json ()
152
+ assert updated_item ["properties" ]["gsd" ] == 16
153
+
154
+ # update gsd in test_item, test-collection
155
+ test_item ["collection" ] = "test-collection"
156
+ test_item ["properties" ]["gsd" ] = 17
157
+ resp = app_client .put (
158
+ f"/collections/{ test_item ['collection' ]} /items" , json = test_item
159
+ )
160
+ assert resp .status_code == 200
161
+ updated_item = resp .json ()
162
+ assert updated_item ["properties" ]["gsd" ] == 17
163
+
164
+ # test_item in test-collection, updated gsd = 17
165
+ resp = app_client .get (
166
+ f"/collections/{ test_item ['collection' ]} /items/{ test_item ['id' ]} "
167
+ )
168
+ assert resp .status_code == 200
169
+ item = resp .json ()
170
+ assert item ["properties" ]["gsd" ] == 17
171
+
172
+ # test_item in test-collection-2, updated gsd = 16
173
+ test_item ["collection" ] = "test-collection-2"
174
+ resp = app_client .get (
175
+ f"/collections/{ test_item ['collection' ]} /items/{ test_item ['id' ]} "
176
+ )
177
+ assert resp .status_code == 200
178
+ item = resp .json ()
179
+ assert item ["properties" ]["gsd" ] == 16
180
+
181
+
47
182
def test_delete_missing_item (app_client , load_test_data ):
48
183
"""Test deletion of an item which does not exist (transactions extension)"""
49
184
test_item = load_test_data ("test_item.json" )
@@ -102,7 +237,7 @@ def test_update_item_missing_collection(app_client, load_test_data):
102
237
resp = app_client .put (
103
238
f"/collections/{ test_item ['collection' ]} /items" , json = test_item
104
239
)
105
- assert resp .status_code == 422
240
+ assert resp .status_code == 404
106
241
107
242
108
243
def test_update_item_geometry (app_client , load_test_data ):
0 commit comments