@@ -15,10 +15,10 @@ def setUp(self):
15
15
self .client = Client ()
16
16
17
17
#setup a testuser
18
- self .user1 = User .objects .create_user ('user1' ,'' , 'passwd' )
19
- self .user2 = User .objects .create_user ('user2' ,'' , 'passwd' )
20
- self .user3 = User .objects .create_user ('user3' ,'' , 'passwd' )
21
- self .user4 = User .objects .create_user ('user4' ,'' , 'passwd' )
18
+ self .user1 = User .objects .create_user ('user1' , '' , 'passwd' )
19
+ self .user2 = User .objects .create_user ('user2' , '' , 'passwd' )
20
+ self .user3 = User .objects .create_user ('user3' , '' , 'passwd' )
21
+ self .user4 = User .objects .create_user ('user4' , '' , 'passwd' )
22
22
23
23
self .base_feature = {
24
24
'type' : 'Feature' ,
@@ -52,10 +52,12 @@ def test_create_and_get_feature(self):
52
52
53
53
response_json = json .loads (response .content )
54
54
#returned feature should include id
55
- self .assertContains (response ,
56
- '"id"' ,
57
- count = 1 ,
58
- status_code = 201 )
55
+ response_dict = json .loads (response .content )
56
+ self .assertTrue (response_dict .has_key ('id' ),
57
+ 'The response feature did not have a key' )
58
+ self .assertEquals (response .status_code ,
59
+ 201 ,
60
+ 'The response was not a 201 created' )
59
61
self .assertTrue (response_json ['private' ],
60
62
'The feature returned did not include a private key' )
61
63
@@ -200,6 +202,92 @@ def test_create_and_delete_feature(self):
200
202
'the feature was not deleted' )
201
203
202
204
def test_create_and_get_property (self ):
205
+ #login to the service
206
+ self .client .login (username = 'user1' ,
207
+ password = 'passwd' )
208
+
203
209
#get not existing property
204
- pass
210
+ response = self .client .get (reverse ('prop' ) + '/@me/test_group/3/500' )
211
+
212
+ self .assertEquals (response .status_code ,
213
+ 404 ,
214
+ "Querying a non existing feature did not return 404" )
215
+
216
+ #create a feature with property to group @self and user @me
217
+ new_feature = self .base_feature
218
+ new_feature .update ({'properties' : {'first' : False }})
219
+ response = self .client .post (reverse ('feat' ),
220
+ json .dumps (new_feature ),
221
+ content_type = 'application/json' )
222
+ self .assertEquals (response .status_code ,
223
+ 201 ,
224
+ "Creating a feature did not return a 201 created" )
225
+ feature_id = json .loads (response .content )['id' ]
226
+ property_id = json .loads (response .content )['properties' ]['id' ]
227
+
228
+ #query property saved with feature
229
+ response = self .client .get ('%s/@me/@self/%i/%i' % (reverse ('prop' ),
230
+ feature_id ,
231
+ property_id ))
232
+ self .assertEquals (response .status_code ,
233
+ 200 ,
234
+ "Querying a property did not return status code 200" )
235
+ self .assertEquals (json .loads (response .content )['group' ],
236
+ '@self' ,
237
+ 'The property did not belong to @self group' )
238
+
239
+
240
+ #create property without feature to group 'test_group'
241
+ response = self .client .post (reverse ('prop' ) + '/@me/test_group/@null' ,
242
+ json .dumps ({'key' : 'first saved' }),
243
+ content_type = 'application/json' )
244
+ self .assertEquals (response .status_code ,
245
+ 201 ,
246
+ "Creating a property did not return a 201 created" )
247
+
248
+ property_id = json .loads (response .content )['id' ]
249
+
250
+ #query property saved without feature
251
+ response = self .client .get ('%s/@me/test_group/@null/%i' % (reverse ('prop' ),
252
+ property_id ))
253
+ self .assertEquals (response .status_code ,
254
+ 200 ,
255
+ "Querying a property did not return status code 200" )
256
+ self .assertEquals (json .loads (response .content )['group' ],
257
+ 'test_group' ,
258
+ 'The property did not belong to test_group group' )
259
+
260
+ #query all user1 properties
261
+ response = self .client .get ('%s/user1' % reverse ('prop' ))
262
+ self .assertTrue (json .loads (response .content ).has_key ('totalResults' ),
263
+ 'The returned collection did not have key totalResults' )
264
+ self .assertTrue (json .loads (response .content ).has_key ('entry' ),
265
+ 'The returned collection did not have key entry' )
266
+
267
+ #update property
268
+ update_to_values = {'hello' : 'world' }
269
+ response = self .client .put ('%s/@me/test_group/@null/%i' % (reverse ('prop' ),
270
+ property_id ),
271
+ json .dumps (update_to_values ),
272
+ content_type = "application/json"
273
+ )
274
+
275
+ self .assertTrue (json .loads (response .content ).has_key ('hello' ),
276
+ 'A key was not found in updated property' )
277
+
278
+ #delete property
279
+ response = self .client .delete ('%s/@me/test_group/@null/%i' % (reverse ('prop' ),
280
+ property_id ))
281
+
282
+ self .assertEquals (response .status_code ,
283
+ 200 ,
284
+ 'Deleting a feature did not return 200 OK' )
285
+
286
+ #get property and check that it does not exist
287
+ response = self .client .get ('%s/@me/test_group/@null/%i' % (reverse ('prop' ),
288
+ property_id ))
289
+
290
+ self .assertEquals (response .status_code ,
291
+ 404 ,
292
+ 'Querying a deleted property did not return not found' )
205
293
0 commit comments