@@ -56,7 +56,7 @@ def test_create_one(
5656    assert  data ["etypes" ] ==  []
5757
5858
59- def  test_update_one (client , trace_id_with_assets ):
59+ def  test_update_one (client , client_admin ,  trace_id_with_assets ):
6060    new_name  =  "my_new_name" 
6161    new_description  =  "my_new_description" 
6262
@@ -92,8 +92,64 @@ def test_update_one(client, trace_id_with_assets):
9292    ).json ()
9393    assert  data ["temperature" ] is  None 
9494
95+     # only admin client can hit admin endpoint 
96+     data  =  assert_request (
97+         client .patch ,
98+         url = f"{ ADMIN_ROUTE } { trace_id_with_assets }  ,
99+         json = {
100+             "name" : new_name ,
101+             "description" : new_description ,
102+         },
103+         expected_status_code = 403 ,
104+     ).json ()
105+     assert  data ["error_code" ] ==  "NOT_AUTHORIZED" 
106+     assert  data ["message" ] ==  "Service admin role required" 
107+ 
108+     data  =  assert_request (
109+         client_admin .patch ,
110+         url = f"{ ADMIN_ROUTE } { trace_id_with_assets }  ,
111+         json = {
112+             "name" : new_name ,
113+             "description" : new_description ,
114+         },
115+     ).json ()
95116
96- def  test_update_one__public (client , electrical_cell_recording_json_data ):
117+     assert  data ["name" ] ==  new_name 
118+     assert  data ["description" ] ==  new_description 
119+ 
120+     # set temperature 
121+     data  =  assert_request (
122+         client_admin .patch ,
123+         url = f"{ ADMIN_ROUTE } { trace_id_with_assets }  ,
124+         json = {
125+             "temperature" : 10.0 ,
126+         },
127+     ).json ()
128+     assert  data ["temperature" ] ==  10.0 
129+ 
130+     # unset temperature 
131+     data  =  assert_request (
132+         client_admin .patch ,
133+         url = f"{ ADMIN_ROUTE } { trace_id_with_assets }  ,
134+         json = {
135+             "temperature" : None ,
136+         },
137+     ).json ()
138+     assert  data ["temperature" ] is  None 
139+ 
140+     # admin is treated as regular user for regular route (no authorized project ids) 
141+     data  =  assert_request (
142+         client_admin .patch ,
143+         url = f"{ ROUTE } { trace_id_with_assets }  ,
144+         json = {
145+             "temperature" : None ,
146+         },
147+         expected_status_code = 404 ,
148+     ).json ()
149+     assert  data ["error_code" ] ==  "ENTITY_NOT_FOUND" 
150+ 
151+ 
152+ def  test_user_update_one__public (client , client_admin , electrical_cell_recording_json_data ):
97153    # make private entity public 
98154    data  =  assert_request (
99155        client .post ,
@@ -104,15 +160,29 @@ def test_update_one__public(client, electrical_cell_recording_json_data):
104160        },
105161    ).json ()
106162
163+     entity_id  =  data ["id" ]
164+ 
107165    # should not be allowed to update it once public 
108166    data  =  assert_request (
109167        client .patch ,
110-         url = f"{ ROUTE } { data [ 'id' ] }  ,
168+         url = f"{ ROUTE } { entity_id }  ,
111169        json = {"name" : "foo" },
112170        expected_status_code = 404 ,
113171    ).json ()
114172    assert  data ["error_code" ] ==  "ENTITY_NOT_FOUND" 
115173
174+     # admin has no such restrictions 
175+     data  =  assert_request (
176+         client_admin .patch ,
177+         url = f"{ ADMIN_ROUTE } { entity_id }  ,
178+         json = {
179+             "authorized_public" : False ,
180+             "name" : "foo" ,
181+         },
182+     ).json ()
183+     assert  data ["authorized_public" ] is  False 
184+     assert  data ["name" ] ==  "foo" 
185+ 
116186
117187def  test_read_one (client , subject_id , license_id , brain_region_id , trace_id_with_assets ):
118188    data  =  assert_request (
0 commit comments