6
6
import yaml
7
7
from django .conf import settings
8
8
from django .urls import reverse
9
+ from rest_framework import status
9
10
from rest_framework .exceptions import ValidationError
10
11
11
12
from acl .models import ACLBase
@@ -465,6 +466,9 @@ def test_list_entity_without_permission(self):
465
466
self .assertEqual (resp .status_code , 200 )
466
467
self .assertEqual (resp .json ()["count" ], 2 )
467
468
469
+ @mock .patch (
470
+ "entity.tasks.create_entity_v2.delay" , mock .Mock (side_effect = tasks .create_entity_v2 )
471
+ )
468
472
def test_create_entity (self ):
469
473
params = {
470
474
"name" : "entity1" ,
@@ -493,16 +497,9 @@ def test_create_entity(self):
493
497
}
494
498
495
499
resp = self .client .post ("/entity/api/v2/" , json .dumps (params ), "application/json" )
496
- self .assertEqual (resp .status_code , 201 )
500
+ self .assertEqual (resp .status_code , status . HTTP_202_ACCEPTED )
497
501
498
- entity : Entity = Entity .objects .get (id = resp .json ()["id" ])
499
- self .assertEqual (
500
- resp .json (),
501
- {
502
- "id" : entity .id ,
503
- "name" : "entity1" ,
504
- },
505
- )
502
+ entity : Entity = Entity .objects .get (name = params ["name" ])
506
503
self .assertEqual (entity .name , "entity1" )
507
504
self .assertEqual (entity .note , "hoge" )
508
505
self .assertEqual (entity .status , Entity .STATUS_TOP_LEVEL )
@@ -1246,6 +1243,9 @@ def test_create_entity_with_invalid_param_webhooks(self):
1246
1243
},
1247
1244
)
1248
1245
1246
+ @mock .patch (
1247
+ "entity.tasks.create_entity_v2.delay" , mock .Mock (side_effect = tasks .create_entity_v2 )
1248
+ )
1249
1249
def test_create_entity_with_attrs_referral (self ):
1250
1250
params = {
1251
1251
"name" : "entity1" ,
@@ -1261,25 +1261,33 @@ def test_create_entity_with_attrs_referral(self):
1261
1261
}
1262
1262
1263
1263
resp = self .client .post ("/entity/api/v2/" , json .dumps (params ), "application/json" )
1264
+ self .assertEqual (resp .status_code , status .HTTP_202_ACCEPTED )
1264
1265
1265
- entity : Entity = Entity .objects .get (id = resp . json ()[ "id " ])
1266
+ entity : Entity = Entity .objects .get (name = params [ "name " ])
1266
1267
for entity_attr in entity .attrs .all ():
1267
1268
if entity_attr .type & AttrTypeValue ["object" ]:
1268
1269
self .assertEqual ([x .id for x in entity_attr .referral .all ()], [self .ref_entity .id ])
1269
1270
else :
1270
1271
self .assertEqual ([x .id for x in entity_attr .referral .all ()], [])
1271
1272
1273
+ @mock .patch (
1274
+ "entity.tasks.create_entity_v2.delay" , mock .Mock (side_effect = tasks .create_entity_v2 )
1275
+ )
1272
1276
def test_create_entity_with_webhook_is_verified (self ):
1273
1277
params = {
1274
1278
"name" : "entity1" ,
1275
1279
"webhooks" : [{"url" : "http://example.net/" }, {"url" : "http://hoge.hoge/" }],
1276
1280
}
1277
1281
resp = self .client .post ("/entity/api/v2/" , json .dumps (params ), "application/json" )
1278
- entity : Entity = Entity .objects .get (id = resp .json ()["id" ])
1282
+ self .assertEqual (resp .status_code , status .HTTP_202_ACCEPTED )
1283
+ entity : Entity = Entity .objects .get (name = params ["name" ])
1279
1284
self .assertEqual ([x .is_verified for x in entity .webhooks .all ()], [True , False ])
1280
1285
1281
1286
@mock .patch ("custom_view.is_custom" , mock .Mock (return_value = True ))
1282
1287
@mock .patch ("custom_view.call_custom" )
1288
+ @mock .patch (
1289
+ "entity.tasks.create_entity_v2.delay" , mock .Mock (side_effect = tasks .create_entity_v2 )
1290
+ )
1283
1291
def test_create_entity_with_customview (self , mock_call_custom ):
1284
1292
params = {"name" : "hoge" }
1285
1293
@@ -1297,7 +1305,7 @@ def side_effect(handler_name, entity_name, user, *args):
1297
1305
self .assertEqual (user , self .user )
1298
1306
1299
1307
if handler_name == "before_create_entity_v2" :
1300
- self .assertEqual (
1308
+ self .assertDictEqual (
1301
1309
args [0 ],
1302
1310
{
1303
1311
"name" : "hoge" ,
@@ -1315,7 +1323,7 @@ def side_effect(handler_name, entity_name, user, *args):
1315
1323
1316
1324
mock_call_custom .side_effect = side_effect
1317
1325
resp = self .client .post ("/entity/api/v2/" , json .dumps (params ), "application/json" )
1318
- self .assertEqual (resp .status_code , 201 )
1326
+ self .assertEqual (resp .status_code , status . HTTP_202_ACCEPTED )
1319
1327
self .assertTrue (mock_call_custom .called )
1320
1328
1321
1329
def test_create_entity_with_webhook_is_disabled (self ):
0 commit comments