@@ -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
@@ -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 ):
@@ -2480,7 +2478,6 @@ def side_effect(handler_name, entity_name, user, *args):
2480
2478
"/entity/api/v2/%d/" % self .entity .id , json .dumps (params ), "application/json"
2481
2479
)
2482
2480
self .assertEqual (resp .status_code , 400 )
2483
- self .assertEqual (resp .json (), [{"code" : "AE-121000" , "message" : "update error" }])
2484
2481
2485
2482
def side_effect (handler_name , entity_name , user , * args ):
2486
2483
# Check specified parameters are expected
@@ -2506,9 +2503,10 @@ def side_effect(handler_name, entity_name, user, *args):
2506
2503
resp = self .client .put (
2507
2504
"/entity/api/v2/%d/" % self .entity .id , json .dumps (params ), "application/json"
2508
2505
)
2509
- self .assertEqual (resp .status_code , 200 )
2506
+ self .assertEqual (resp .status_code , status . HTTP_202_ACCEPTED )
2510
2507
self .assertTrue (mock_call_custom .called )
2511
2508
2509
+ @mock .patch ("entity.tasks.edit_entity_v2.delay" , mock .Mock (side_effect = tasks .edit_entity_v2 ))
2512
2510
def test_update_entry_with_specified_only_param (self ):
2513
2511
self .entity .note = "hoge"
2514
2512
self .entity .status = Entity .STATUS_TOP_LEVEL
@@ -2525,7 +2523,7 @@ def test_update_entry_with_specified_only_param(self):
2525
2523
resp = self .client .put (
2526
2524
"/entity/api/v2/%d/" % self .entity .id , json .dumps (params ), "application/json"
2527
2525
)
2528
- self .assertEqual (resp .status_code , 200 )
2526
+ self .assertEqual (resp .status_code , status . HTTP_202_ACCEPTED )
2529
2527
2530
2528
self .entity .refresh_from_db ()
2531
2529
changed_attr_count = self .entity .attrs .filter (is_active = True ).count ()
@@ -2536,6 +2534,7 @@ def test_update_entry_with_specified_only_param(self):
2536
2534
self .assertEqual (attr_count , changed_attr_count )
2537
2535
self .assertEqual (webhook_count , changed_webhook_count )
2538
2536
2537
+ @mock .patch ("entity.tasks.edit_entity_v2.delay" , mock .Mock (side_effect = tasks .edit_entity_v2 ))
2539
2538
def test_update_entity_without_permission (self ):
2540
2539
self .role .users .add (self .user )
2541
2540
@@ -2574,7 +2573,7 @@ def test_update_entity_without_permission(self):
2574
2573
resp = self .client .put (
2575
2574
"/entity/api/v2/%d/" % self .entity .id , json .dumps (paramas ), "application/json"
2576
2575
)
2577
- self .assertEqual (resp .status_code , 200 )
2576
+ self .assertEqual (resp .status_code , status . HTTP_202_ACCEPTED )
2578
2577
2579
2578
# permission nothing EntityAttr update
2580
2579
self .entity .is_public = True
@@ -2608,7 +2607,7 @@ def test_update_entity_without_permission(self):
2608
2607
resp = self .client .put (
2609
2608
"/entity/api/v2/%d/" % self .entity .id , json .dumps (params ), "application/json"
2610
2609
)
2611
- self .assertEqual (resp .status_code , 200 )
2610
+ self .assertEqual (resp .status_code , status . HTTP_202_ACCEPTED )
2612
2611
2613
2612
# permission writable EntityAttr delete
2614
2613
params = {"attrs" : [{"id" : entity_attr .id , "is_deleted" : True }]}
@@ -2626,7 +2625,7 @@ def test_update_entity_without_permission(self):
2626
2625
resp = self .client .put (
2627
2626
"/entity/api/v2/%d/" % self .entity .id , json .dumps (params ), "application/json"
2628
2627
)
2629
- self .assertEqual (resp .status_code , 200 )
2628
+ self .assertEqual (resp .status_code , status . HTTP_202_ACCEPTED )
2630
2629
2631
2630
def test_update_entity_with_webhook_is_disabled (self ):
2632
2631
entity : Entity = self .create_entity (
0 commit comments