2828 check_entity_update_one ,
2929 create_cell_morphology_id ,
3030)
31+ from tests .utils .api_create import create_cell_morphology_protocol_id
32+ from tests .utils .check import check_auth_triggers
3133
3234ROUTE = "/cell-morphology"
3335ADMIN_ROUTE = "/admin/cell-morphology"
3436
3537
3638@pytest .fixture
37- def json_data (subject_id , license_id , brain_region_id , cell_morphology_protocol ):
39+ def common_json_data (subject_id , license_id , brain_region_id ):
3840 return {
3941 "brain_region_id" : str (brain_region_id ),
4042 "subject_id" : str (subject_id ),
@@ -43,12 +45,25 @@ def json_data(subject_id, license_id, brain_region_id, cell_morphology_protocol)
4345 "location" : {"x" : 10 , "y" : 20 , "z" : 30 },
4446 "legacy_id" : ["Test Legacy ID" ],
4547 "license_id" : str (license_id ),
46- "cell_morphology_protocol_id" : str (cell_morphology_protocol .id ),
4748 "contact_email" : "test@example.com" ,
4849 "experiment_date" : "2025-01-01T00:00:00" ,
4950 }
5051
5152
53+ @pytest .fixture
54+ def json_data (common_json_data , cell_morphology_protocol ):
55+ return common_json_data | {
56+ "cell_morphology_protocol_id" : str (cell_morphology_protocol .id ),
57+ }
58+
59+
60+ @pytest .fixture
61+ def public_json_data (common_json_data , public_cell_morphology_protocol ):
62+ return common_json_data | {
63+ "cell_morphology_protocol_id" : str (public_cell_morphology_protocol .id ),
64+ }
65+
66+
5267def test_create_one (
5368 client ,
5469 brain_region_id ,
@@ -92,13 +107,13 @@ def test_create_one(
92107 assert data [0 ]["cell_morphology_protocol" ] == expected_cell_morphology_protocol_json_data
93108
94109
95- def test_delete_one (db , clients , json_data ):
110+ def test_delete_one (db , clients , public_json_data ):
96111 check_entity_delete_one (
97112 db = db ,
98113 clients = clients ,
99114 route = ROUTE ,
100115 admin_route = ADMIN_ROUTE ,
101- json_data = json_data ,
116+ json_data = public_json_data ,
102117 expected_counts_before = {CellMorphology : 1 , CellMorphologyProtocol : 1 },
103118 expected_counts_after = {
104119 CellMorphology : 0 ,
@@ -107,12 +122,12 @@ def test_delete_one(db, clients, json_data):
107122 )
108123
109124
110- def test_update_one (clients , json_data ):
125+ def test_update_one (clients , public_json_data ):
111126 check_entity_update_one (
112127 route = ROUTE ,
113128 admin_route = ADMIN_ROUTE ,
114129 clients = clients ,
115- json_data = json_data ,
130+ json_data = public_json_data ,
116131 patch_payload = {
117132 "name" : "name" ,
118133 "description" : "description" ,
@@ -478,24 +493,35 @@ def test_query_cell_morphology_species_join(db, client, brain_region_id, subject
478493 }
479494
480495
481- def test_authorization (
496+ def test_authorization (client_user_1 , client_user_2 , client_no_project , public_json_data ):
497+ check_authorization (ROUTE , client_user_1 , client_user_2 , client_no_project , public_json_data )
498+
499+
500+ def test_auth_triggers (
482501 client_user_1 ,
483502 client_user_2 ,
484- client_no_project ,
485- subject_id ,
486- license_id ,
487- brain_region_id ,
503+ public_json_data ,
504+ cell_morphology_protocol ,
505+ public_cell_morphology_protocol ,
488506):
489- json_data = {
490- "location" : {"x" : 10 , "y" : 20 , "z" : 30 },
491- "brain_region_id" : str (brain_region_id ),
492- "description" : "morph description" ,
493- "legacy_id" : ["Test Legacy ID" ],
494- "license_id" : license_id ,
495- "name" : "Test Morphology Name" ,
496- "subject_id" : str (subject_id ),
497- }
498- check_authorization (ROUTE , client_user_1 , client_user_2 , client_no_project , json_data )
507+ linked_private_u2 = create_cell_morphology_protocol_id (
508+ client_user_2 ,
509+ authorized_public = False ,
510+ )
511+ linked_public_u2 = create_cell_morphology_protocol_id (
512+ client_user_2 ,
513+ authorized_public = True ,
514+ )
515+ check_auth_triggers (
516+ ROUTE ,
517+ client_user_1 = client_user_1 ,
518+ json_data = public_json_data ,
519+ link_key = "cell_morphology_protocol_id" ,
520+ linked_private_u1_id = str (cell_morphology_protocol .id ),
521+ linked_public_u1_id = str (public_cell_morphology_protocol .id ),
522+ linked_private_u2_id = linked_private_u2 ,
523+ linked_public_u2_id = linked_public_u2 ,
524+ )
499525
500526
501527def test_pagination (db , client , brain_region_id , person_id ):
0 commit comments