@@ -277,7 +277,7 @@ def test_list_retrieve_subscription(self):
277277 self .assert_200 (response )
278278 self .assertEqual (response .data ["user" ], self .user1 .id )
279279
280- # Test create Subscription without country and region
280+ # Test Create Subscription
281281 def test_create_subscription_without_country_and_region (self ):
282282 data = {
283283 "title" : "title-1-test" ,
@@ -291,7 +291,38 @@ def test_create_subscription_without_country_and_region(self):
291291 response = self .client .post (url , data = data , format = "json" )
292292 self .assert_400 (response )
293293
294- # Test Create Subscription
294+ def test_create_subscription_without_country (self ):
295+ data = {
296+ "title" : "title-2-test" ,
297+ "user" : self .user1 .id ,
298+ "hazard_types" : [self .hazard_type1 .id , self .hazard_type2 .id ],
299+ "source" : AlertSubscription .AlertSource .MONTANDON ,
300+ "regions" : [self .region .id ],
301+ }
302+ url = "/api/v2/alert-subscription/"
303+ self .authenticate (self .user1 )
304+ response = self .client .post (url , data = data , format = "json" )
305+ self .assert_201 (response )
306+ subscription = AlertSubscription .objects .get (id = response .data ["id" ])
307+ self .assertEqual (subscription .user , self .user1 )
308+
309+ def test_create_subscription_without_region (self ):
310+ data = {
311+ "title" : "title-2-test" ,
312+ "user" : self .user1 .id ,
313+ "hazard_types" : [self .hazard_type1 .id , self .hazard_type2 .id ],
314+ "source" : AlertSubscription .AlertSource .MONTANDON ,
315+ "countries" : [self .country .id , self .country_1 .id ],
316+ "alert_per_day" : AlertSubscription .AlertPerDay .FIFTY ,
317+ }
318+ url = "/api/v2/alert-subscription/"
319+ self .authenticate (self .user1 )
320+ response = self .client .post (url , data = data , format = "json" )
321+ self .assert_201 (response )
322+ subscription = AlertSubscription .objects .get (id = response .data ["id" ])
323+ self .assertEqual (subscription .user , self .user1 )
324+ self .assertEqual (subscription .alert_per_day , AlertSubscription .AlertPerDay .FIFTY )
325+
295326 def test_create_subscription (self ):
296327
297328 data = {
@@ -328,3 +359,16 @@ def test_update_subscription(self):
328359 self .alert_subscription .refresh_from_db ()
329360 self .assertEqual (self .alert_subscription .countries .first ().id , self .country_1 .id )
330361 self .assertEqual (self .alert_subscription .alert_per_day , AlertSubscription .AlertPerDay .TEN )
362+
363+ def test_delete_subscription (self ):
364+ self .alert_subscription = AlertSubscriptionFactory .create (
365+ title = "Test title" ,
366+ user = self .user1 ,
367+ countries = self .countries ,
368+ regions = [self .region ],
369+ hazard_types = [self .hazard_type1 , self .hazard_type2 ],
370+ )
371+ self .authenticate (self .user1 )
372+ url = f"/api/v2/alert-subscription/{ self .alert_subscription .id } /"
373+ response = self .client .delete (url )
374+ self .assert_204 (response )
0 commit comments