1+ import itertools as it
12from unittest .mock import ANY
23
34import pytest
@@ -54,7 +55,7 @@ def test_brain_atlas(db, client, species_id):
5455 hierarchy_name = utils .create_hiearchy_name (db , "test_hierarchy" )
5556 regions = utils .add_brain_region_hierarchy (db , HIERARCHY , hierarchy_name .id )
5657
57- brain_atlas = utils .add_db (
58+ brain_atlas0 = utils .add_db (
5859 db ,
5960 BrainAtlas (
6061 name = "test brain atlas" ,
@@ -65,10 +66,21 @@ def test_brain_atlas(db, client, species_id):
6566 authorized_public = True ,
6667 ),
6768 )
69+ brain_atlas1 = utils .add_db (
70+ db ,
71+ BrainAtlas (
72+ name = "test brain atlas 1" ,
73+ description = "test brain atlas description 1" ,
74+ species_id = species_id ,
75+ hierarchy_id = hierarchy_name .id ,
76+ authorized_project_id = utils .PROJECT_ID ,
77+ authorized_public = True ,
78+ ),
79+ )
6880 expected = {
6981 "creation_date" : ANY ,
7082 "hierarchy_id" : str (hierarchy_name .id ),
71- "id" : str (brain_atlas .id ),
83+ "id" : str (brain_atlas0 .id ),
7284 "name" : "test brain atlas" ,
7385 "species" : {
7486 "creation_date" : ANY ,
@@ -83,19 +95,23 @@ def test_brain_atlas(db, client, species_id):
8395 response = client .get (ROUTE )
8496 assert response .status_code == 200
8597 response = response .json ()
86- assert len (response ["data" ]) == 1
87- assert response ["data" ] == [
88- expected ,
89- ]
98+ assert len (response ["data" ]) == 2
99+ assert response ["data" ][0 ] == expected
90100
91- response = client .get (f"{ ROUTE } /{ brain_atlas .id } " )
101+ response = client .get (f"{ ROUTE } /{ brain_atlas0 .id } " )
92102 assert response .status_code == 200
93103 response = response .json ()
94104 assert response == expected
95105
96106 data = (("root" , False , - 1 ), ("blue" , False , - 1 ), ("red" , True , 15 ), ("grey" , True , 10 ))
97107 ids = {}
98- for name , leaf , volume in data :
108+ for brain_atlas , (name , leaf , volume ) in it .product (
109+ (
110+ brain_atlas0 ,
111+ brain_atlas1 ,
112+ ),
113+ data ,
114+ ):
99115 row = BrainAtlasRegion (
100116 volume = volume ,
101117 leaf_region = leaf ,
@@ -104,58 +120,58 @@ def test_brain_atlas(db, client, species_id):
104120 authorized_project_id = utils .PROJECT_ID ,
105121 authorized_public = True ,
106122 )
107- ids [name ] = utils .add_db (db , row )
123+ ids [brain_atlas . name , name ] = utils .add_db (db , row )
108124
109125 response = client .get (
110- f"{ ROUTE } /{ brain_atlas .id } /regions" , params = {"order_by" : "+creation_date" }
126+ f"{ ROUTE } /{ brain_atlas0 .id } /regions" , params = {"order_by" : "+creation_date" }
111127 )
112128 assert response .status_code == 200
113129 assert response .json ()["data" ] == [
114130 {
115- "brain_atlas_id" : str (brain_atlas .id ),
131+ "brain_atlas_id" : str (brain_atlas0 .id ),
116132 "brain_region_id" : str (regions ["root" ].id ),
117133 "creation_date" : ANY ,
118- "id" : str (ids ["root" ].id ),
134+ "id" : str (ids [brain_atlas0 . name , "root" ].id ),
119135 "leaf_region" : False ,
120136 "update_date" : ANY ,
121137 "volume" : - 1.0 ,
122138 },
123139 {
124- "brain_atlas_id" : str (brain_atlas .id ),
140+ "brain_atlas_id" : str (brain_atlas0 .id ),
125141 "brain_region_id" : str (regions ["blue" ].id ),
126142 "creation_date" : ANY ,
127- "id" : str (ids ["blue" ].id ),
143+ "id" : str (ids [brain_atlas0 . name , "blue" ].id ),
128144 "leaf_region" : False ,
129145 "update_date" : ANY ,
130146 "volume" : - 1.0 ,
131147 },
132148 {
133- "brain_atlas_id" : str (brain_atlas .id ),
149+ "brain_atlas_id" : str (brain_atlas0 .id ),
134150 "brain_region_id" : str (regions ["red" ].id ),
135151 "creation_date" : ANY ,
136- "id" : str (ids ["red" ].id ),
152+ "id" : str (ids [brain_atlas0 . name , "red" ].id ),
137153 "leaf_region" : True ,
138154 "update_date" : ANY ,
139155 "volume" : 15.0 ,
140156 },
141157 {
142- "brain_atlas_id" : str (brain_atlas .id ),
158+ "brain_atlas_id" : str (brain_atlas0 .id ),
143159 "brain_region_id" : str (regions ["grey" ].id ),
144160 "creation_date" : ANY ,
145- "id" : str (ids ["grey" ].id ),
161+ "id" : str (ids [brain_atlas0 . name , "grey" ].id ),
146162 "leaf_region" : True ,
147163 "update_date" : ANY ,
148164 "volume" : 10.0 ,
149165 },
150166 ]
151167
152- response = client .get (f"{ ROUTE } /{ brain_atlas .id } /regions/{ ids ['root' ].id } " )
168+ response = client .get (f"{ ROUTE } /{ brain_atlas0 .id } /regions/{ ids [brain_atlas0 . name , 'root' ].id } " )
153169 assert response .status_code == 200
154170 assert response .json () == {
155- "brain_atlas_id" : str (brain_atlas .id ),
171+ "brain_atlas_id" : str (brain_atlas0 .id ),
156172 "brain_region_id" : str (regions ["root" ].id ),
157173 "creation_date" : ANY ,
158- "id" : str (ids ["root" ].id ),
174+ "id" : str (ids [brain_atlas0 . name , "root" ].id ),
159175 "leaf_region" : False ,
160176 "update_date" : ANY ,
161177 "volume" : - 1.0 ,
0 commit comments