@@ -1283,11 +1283,11 @@ def test_create_entity_with_webhook_is_verified(self):
1283
1283
entity : Entity = Entity .objects .get (name = params ["name" ])
1284
1284
self .assertEqual ([x .is_verified for x in entity .webhooks .all ()], [True , False ])
1285
1285
1286
- @mock .patch ("custom_view.is_custom" , mock .Mock (return_value = True ))
1287
- @mock .patch ("custom_view.call_custom" )
1288
1286
@mock .patch (
1289
1287
"entity.tasks.create_entity_v2.delay" , mock .Mock (side_effect = tasks .create_entity_v2 )
1290
1288
)
1289
+ @mock .patch ("custom_view.is_custom" , mock .Mock (return_value = True ))
1290
+ @mock .patch ("custom_view.call_custom" )
1291
1291
def test_create_entity_with_customview (self , mock_call_custom ):
1292
1292
params = {"name" : "hoge" }
1293
1293
@@ -1296,8 +1296,8 @@ def side_effect(handler_name, entity_name, user, *args):
1296
1296
1297
1297
mock_call_custom .side_effect = side_effect
1298
1298
resp = self .client .post ("/entity/api/v2/" , json .dumps (params ), "application/json" )
1299
- self .assertEqual (resp .status_code , 400 )
1300
- self .assertEqual ( resp . json (), [{ "code" : "AE-121000" , "message" : "create error" }] )
1299
+ self .assertEqual (resp .status_code , status . HTTP_202_ACCEPTED )
1300
+ self .assertTrue ( mock_call_custom . called )
1301
1301
1302
1302
def side_effect (handler_name , entity_name , user , * args ):
1303
1303
# Check specified parameters are expected
@@ -1351,6 +1351,7 @@ def test_create_entity_with_webhook_is_disabled(self):
1351
1351
finally :
1352
1352
settings .AIRONE_FLAGS = {"WEBHOOK" : True }
1353
1353
1354
+ @mock .patch ("entity.tasks.edit_entity_v2.delay" , mock .Mock (side_effect = tasks .edit_entity_v2 ))
1354
1355
def test_update_entity (self ):
1355
1356
entity : Entity = self .create_entity (
1356
1357
** {
@@ -1403,15 +1404,8 @@ def test_update_entity(self):
1403
1404
resp = self .client .put (
1404
1405
"/entity/api/v2/%d/" % entity .id , json .dumps (params ), "application/json"
1405
1406
)
1406
- self .assertEqual (resp .status_code , 200 )
1407
+ self .assertEqual (resp .status_code , status . HTTP_202_ACCEPTED )
1407
1408
1408
- self .assertEqual (
1409
- resp .json (),
1410
- {
1411
- "id" : entity .id ,
1412
- "name" : "change-entity1" ,
1413
- },
1414
- )
1415
1409
entity .refresh_from_db ()
1416
1410
self .assertEqual (entity .name , "change-entity1" )
1417
1411
self .assertEqual (entity .note , "change-hoge" )
@@ -1567,6 +1561,7 @@ def test_update_entity_with_invalid_param(self):
1567
1561
{"is_toplevel" : [{"code" : "AE-121000" , "message" : "Must be a valid boolean." }]},
1568
1562
)
1569
1563
1564
+ @mock .patch ("entity.tasks.edit_entity_v2.delay" , mock .Mock (side_effect = tasks .edit_entity_v2 ))
1570
1565
def test_update_entity_with_invalid_param_attrs (self ):
1571
1566
params = {
1572
1567
"attrs" : "hoge" ,
@@ -2088,7 +2083,7 @@ def test_update_entity_with_invalid_param_attrs(self):
2088
2083
resp = self .client .put (
2089
2084
"/entity/api/v2/%d/" % self .entity .id , json .dumps (params ), "application/json"
2090
2085
)
2091
- self .assertEqual (resp .status_code , 200 )
2086
+ self .assertEqual (resp .status_code , status . HTTP_202_ACCEPTED )
2092
2087
self .assertTrue (
2093
2088
all (["hoge" not in x .name for x in self .entity .attrs .filter (is_active = True )])
2094
2089
)
@@ -2133,7 +2128,7 @@ def test_update_entity_with_invalid_param_attrs(self):
2133
2128
resp = self .client .put (
2134
2129
"/entity/api/v2/%d/" % self .entity .id , json .dumps (params ), "application/json"
2135
2130
)
2136
- self .assertEqual (resp .status_code , 200 )
2131
+ self .assertEqual (resp .status_code , status . HTTP_202_ACCEPTED )
2137
2132
2138
2133
def test_update_entity_with_invalid_param_webhooks (self ):
2139
2134
params = {
@@ -2429,6 +2424,7 @@ def test_update_entity_with_invalid_param_webhooks(self):
2429
2424
},
2430
2425
)
2431
2426
2427
+ @mock .patch ("entity.tasks.edit_entity_v2.delay" , mock .Mock (side_effect = tasks .edit_entity_v2 ))
2432
2428
def test_update_entity_with_attrs_referral (self ):
2433
2429
self .entity .attrs .all ().delete ()
2434
2430
params = {
@@ -2446,14 +2442,15 @@ def test_update_entity_with_attrs_referral(self):
2446
2442
resp = self .client .put (
2447
2443
"/entity/api/v2/%d/" % self .entity .id , json .dumps (params ), "application/json"
2448
2444
)
2449
- self .assertEqual (resp .status_code , 200 )
2445
+ self .assertEqual (resp .status_code , status . HTTP_202_ACCEPTED )
2450
2446
2451
2447
for entity_attr in self .entity .attrs .all ():
2452
2448
if entity_attr .type & AttrTypeValue ["object" ]:
2453
2449
self .assertEqual ([x .id for x in entity_attr .referral .all ()], [self .ref_entity .id ])
2454
2450
else :
2455
2451
self .assertEqual ([x .id for x in entity_attr .referral .all ()], [])
2456
2452
2453
+ @mock .patch ("entity.tasks.edit_entity_v2.delay" , mock .Mock (side_effect = tasks .edit_entity_v2 ))
2457
2454
def test_update_entity_with_webhook_is_verified (self ):
2458
2455
self .entity .webhooks .all ().delete ()
2459
2456
params = {
@@ -2463,10 +2460,11 @@ def test_update_entity_with_webhook_is_verified(self):
2463
2460
resp = self .client .put (
2464
2461
"/entity/api/v2/%d/" % self .entity .id , json .dumps (params ), "application/json"
2465
2462
)
2466
- self .assertEqual (resp .status_code , 200 )
2463
+ self .assertEqual (resp .status_code , status . HTTP_202_ACCEPTED )
2467
2464
2468
2465
self .assertEqual ([x .is_verified for x in self .entity .webhooks .all ()], [True , False ])
2469
2466
2467
+ @mock .patch ("entity.tasks.edit_entity_v2.delay" , mock .Mock (side_effect = tasks .edit_entity_v2 ))
2470
2468
@mock .patch ("custom_view.is_custom" , mock .Mock (return_value = True ))
2471
2469
@mock .patch ("custom_view.call_custom" )
2472
2470
def test_update_entity_with_customview (self , mock_call_custom ):
@@ -2479,8 +2477,8 @@ def side_effect(handler_name, entity_name, user, *args):
2479
2477
resp = self .client .put (
2480
2478
"/entity/api/v2/%d/" % self .entity .id , json .dumps (params ), "application/json"
2481
2479
)
2482
- self .assertEqual (resp .status_code , 400 )
2483
- self .assertEqual ( resp . json (), [{ "code" : "AE-121000" , "message" : "update error" }] )
2480
+ self .assertEqual (resp .status_code , status . HTTP_202_ACCEPTED )
2481
+ self .assertTrue ( mock_call_custom . called )
2484
2482
2485
2483
def side_effect (handler_name , entity_name , user , * args ):
2486
2484
# Check specified parameters are expected
@@ -2506,9 +2504,10 @@ def side_effect(handler_name, entity_name, user, *args):
2506
2504
resp = self .client .put (
2507
2505
"/entity/api/v2/%d/" % self .entity .id , json .dumps (params ), "application/json"
2508
2506
)
2509
- self .assertEqual (resp .status_code , 200 )
2507
+ self .assertEqual (resp .status_code , status . HTTP_202_ACCEPTED )
2510
2508
self .assertTrue (mock_call_custom .called )
2511
2509
2510
+ @mock .patch ("entity.tasks.edit_entity_v2.delay" , mock .Mock (side_effect = tasks .edit_entity_v2 ))
2512
2511
def test_update_entry_with_specified_only_param (self ):
2513
2512
self .entity .note = "hoge"
2514
2513
self .entity .status = Entity .STATUS_TOP_LEVEL
@@ -2525,7 +2524,7 @@ def test_update_entry_with_specified_only_param(self):
2525
2524
resp = self .client .put (
2526
2525
"/entity/api/v2/%d/" % self .entity .id , json .dumps (params ), "application/json"
2527
2526
)
2528
- self .assertEqual (resp .status_code , 200 )
2527
+ self .assertEqual (resp .status_code , status . HTTP_202_ACCEPTED )
2529
2528
2530
2529
self .entity .refresh_from_db ()
2531
2530
changed_attr_count = self .entity .attrs .filter (is_active = True ).count ()
@@ -2536,6 +2535,7 @@ def test_update_entry_with_specified_only_param(self):
2536
2535
self .assertEqual (attr_count , changed_attr_count )
2537
2536
self .assertEqual (webhook_count , changed_webhook_count )
2538
2537
2538
+ @mock .patch ("entity.tasks.edit_entity_v2.delay" , mock .Mock (side_effect = tasks .edit_entity_v2 ))
2539
2539
def test_update_entity_without_permission (self ):
2540
2540
self .role .users .add (self .user )
2541
2541
@@ -2574,7 +2574,7 @@ def test_update_entity_without_permission(self):
2574
2574
resp = self .client .put (
2575
2575
"/entity/api/v2/%d/" % self .entity .id , json .dumps (paramas ), "application/json"
2576
2576
)
2577
- self .assertEqual (resp .status_code , 200 )
2577
+ self .assertEqual (resp .status_code , status . HTTP_202_ACCEPTED )
2578
2578
2579
2579
# permission nothing EntityAttr update
2580
2580
self .entity .is_public = True
@@ -2608,7 +2608,7 @@ def test_update_entity_without_permission(self):
2608
2608
resp = self .client .put (
2609
2609
"/entity/api/v2/%d/" % self .entity .id , json .dumps (params ), "application/json"
2610
2610
)
2611
- self .assertEqual (resp .status_code , 200 )
2611
+ self .assertEqual (resp .status_code , status . HTTP_202_ACCEPTED )
2612
2612
2613
2613
# permission writable EntityAttr delete
2614
2614
params = {"attrs" : [{"id" : entity_attr .id , "is_deleted" : True }]}
@@ -2626,7 +2626,7 @@ def test_update_entity_without_permission(self):
2626
2626
resp = self .client .put (
2627
2627
"/entity/api/v2/%d/" % self .entity .id , json .dumps (params ), "application/json"
2628
2628
)
2629
- self .assertEqual (resp .status_code , 200 )
2629
+ self .assertEqual (resp .status_code , status . HTTP_202_ACCEPTED )
2630
2630
2631
2631
def test_update_entity_with_webhook_is_disabled (self ):
2632
2632
entity : Entity = self .create_entity (
0 commit comments