@@ -595,7 +595,6 @@ class PluginConfigViewSetTestCase(CustomViewSetTestCase):
595595
596596 def setUp (self ):
597597 super ().setUp ()
598- PluginConfig .objects .all ().delete ()
599598
600599 def test_plugin_config (self ):
601600 org = Organization .create ("test_org" , self .user )
@@ -818,7 +817,7 @@ def test_plugin_config_list(self):
818817 if obj ["attribute" ] == pc0 .attribute :
819818 needle = obj
820819 # the owner cannot see configs of other orgs (pc1)
821- if "organization" in obj .keys ():
820+ if "organization" in obj .keys () and obj [ "organization" ] is not None :
822821 self .assertEqual (obj ["organization" ], "testorg0" )
823822 self .assertIsNotNone (needle )
824823 self .assertIn ("type" , needle )
@@ -845,7 +844,7 @@ def test_plugin_config_list(self):
845844 if obj ["attribute" ] == pc0 .attribute :
846845 needle = obj
847846 # an admin cannot see configs of other orgs (pc1)
848- if "organization" in obj .keys ():
847+ if "organization" in obj .keys () and obj [ "organization" ] is not None :
849848 self .assertEqual (obj ["organization" ], "testorg0" )
850849 self .assertIsNotNone (needle )
851850 self .assertIn ("type" , needle )
@@ -872,7 +871,7 @@ def test_plugin_config_list(self):
872871 if obj ["attribute" ] == pc1 .attribute :
873872 needle = obj
874873 # a user cannot see configs of other orgs (pc0)
875- if "organization" in obj .keys ():
874+ if "organization" in obj .keys () and obj [ "organization" ] is not None :
876875 self .assertEqual (obj ["organization" ], "testorg1" )
877876 self .assertIsNotNone (needle )
878877 self .assertIn ("type" , needle )
@@ -1242,11 +1241,11 @@ def test_delete(self):
12421241 user = self .user , organization = org , is_owner = False , is_admin = False
12431242 )
12441243 ac = AnalyzerConfig .objects .get (name = "AbuseIPDB" )
1245- uri = "/api/plugin-config/1 "
1244+ uri = "/api/plugin-config"
12461245
12471246 # logged out
12481247 self .client .logout ()
1249- response = self .client .delete (uri , {}, format = "json" )
1248+ response = self .client .delete (f" { uri } /1" , {}, format = "json" )
12501249 self .assertEqual (response .status_code , 401 )
12511250
12521251 param = Parameter .objects .create (
@@ -1256,60 +1255,51 @@ def test_delete(self):
12561255 required = True ,
12571256 type = "str" ,
12581257 )
1259- pc = PluginConfig (
1258+ pc , _ = PluginConfig . objects . get_or_create (
12601259 value = "supersecret" ,
12611260 for_organization = True ,
12621261 owner = self .superuser ,
12631262 parameter = param ,
12641263 analyzer_config = ac ,
1265- id = 1 ,
12661264 )
1267- pc .full_clean ()
1268- pc .save ()
12691265 self .assertEqual (pc .owner , org .owner )
12701266
12711267 # user can not delete org secret
12721268 self .client .force_authenticate (user = self .user )
1273- response = self .client .delete (uri , {}, format = "json" )
1269+ response = self .client .delete (f" { uri } / { pc . id } " , {}, format = "json" )
12741270 self .assertEqual (response .status_code , 403 )
12751271
12761272 # owner can delete org secret
12771273 self .client .force_authenticate (user = self .superuser )
1278- response = self .client .delete (uri , format = "json" )
1274+ response = self .client .delete (f" { uri } / { pc . id } " , format = "json" )
12791275 self .assertEqual (response .status_code , 204 )
12801276
1281- pc = PluginConfig (
1277+ pc , _ = PluginConfig . objects . get_or_create (
12821278 value = "supersecret" ,
12831279 for_organization = True ,
12841280 owner = self .superuser ,
12851281 parameter = param ,
12861282 analyzer_config = ac ,
1287- id = 1 ,
12881283 )
1289- pc .full_clean ()
1290- pc .save ()
12911284 self .assertEqual (pc .owner , org .owner )
12921285
12931286 # admin can delete org secret
12941287 self .client .force_authenticate (user = self .admin )
1295- response = self .client .delete (uri , {}, format = "json" )
1288+ response = self .client .delete (f" { uri } / { pc . id } " , {}, format = "json" )
12961289 self .assertEqual (response .status_code , 204 )
12971290
1298- pc = PluginConfig (
1291+ pc , _ = PluginConfig . objects . get_or_create (
12991292 value = "supersecret" ,
13001293 for_organization = False ,
13011294 owner = self .user ,
13021295 parameter = param ,
13031296 analyzer_config = ac ,
1304- id = 1 ,
13051297 )
1306- pc .full_clean ()
1307- pc .save ()
13081298 self .assertEqual (pc .owner , self .user )
13091299
13101300 # user can delete own personal secret
13111301 self .client .force_authenticate (user = self .user )
1312- response = self .client .delete (uri , {}, format = "json" )
1302+ response = self .client .delete (f" { uri } / { pc . id } " , {}, format = "json" )
13131303 self .assertEqual (response .status_code , 204 )
13141304
13151305 def test_get_403 (self ):
0 commit comments