33from typing import Any , Optional
44
55import pytest
6+ import pytest_asyncio
67
78from synapseclient import Synapse
89from synapseclient .core .exceptions import SynapseHTTPError
@@ -20,7 +21,7 @@ def create_test_entity_name():
2021 return f"SYNPY.TEST.{ random_string } "
2122
2223
23- def org_exists (name : str , synapse_client : Optional [Synapse ] = None ) -> bool :
24+ async def org_exists (name : str , synapse_client : Optional [Synapse ] = None ) -> bool :
2425 """
2526 Checks if any organizations exists with the given name
2627
@@ -66,16 +67,17 @@ def fixture_json_schema(module_organization: SchemaOrganization) -> JSONSchema:
6667 return js
6768
6869
69- @pytest .fixture (name = "organization" , scope = "function" )
70- def fixture_organization (syn : Synapse , request ) -> SchemaOrganization :
70+ @pytest_asyncio .fixture (name = "organization" , loop_scope = "function " , scope = "function" )
71+ async def fixture_organization (syn : Synapse , request ) -> SchemaOrganization :
7172 """
7273 Returns a Synapse organization.
7374 """
7475 name = create_test_entity_name ()
7576 org = SchemaOrganization (name )
7677
77- def delete_org ():
78- if org_exists (name , syn ):
78+ async def delete_org ():
79+ exists = await org_exists (name , syn )
80+ if exists :
7981 org .delete ()
8082
8183 request .addfinalizer (delete_org )
@@ -115,23 +117,25 @@ class TestSchemaOrganization:
115117 def init (self , syn : Synapse ) -> None :
116118 self .syn = syn
117119
118- def test_create_and_get (self , organization : SchemaOrganization ) -> None :
120+ async def test_create_and_get (self , organization : SchemaOrganization ) -> None :
119121 # GIVEN an initialized organization object that hasn't been stored in Synapse
120122 # THEN it shouldn't have any metadata besides it's name
121123 assert organization .name is not None
122124 assert organization .id is None
123125 assert organization .created_by is None
124126 assert organization .created_on is None
125127 # AND it shouldn't exist in Synapse
126- assert not org_exists (organization .name , synapse_client = self .syn )
128+ exists = await org_exists (organization .name , synapse_client = self .syn )
129+ assert not exists
127130 # WHEN I store the organization the metadata will be saved
128131 organization .store (synapse_client = self .syn )
129132 assert organization .name is not None
130133 assert organization .id is not None
131134 assert organization .created_by is not None
132135 assert organization .created_on is not None
133136 # AND it should exist in Synapse
134- assert org_exists (organization .name , synapse_client = self .syn )
137+ exists = await org_exists (organization .name , synapse_client = self .syn )
138+ assert exists
135139 # AND it should be getable by future instances with the same name
136140 org2 = SchemaOrganization (organization .name )
137141 org2 .get (synapse_client = self .syn )
@@ -144,7 +148,7 @@ def test_create_and_get(self, organization: SchemaOrganization) -> None:
144148 with pytest .raises (SynapseHTTPError ):
145149 org2 .store ()
146150
147- def test_get_json_schema_list (
151+ async def test_get_json_schemas (
148152 self ,
149153 organization : SchemaOrganization ,
150154 organization_with_schema : SchemaOrganization ,
@@ -160,7 +164,9 @@ def test_get_json_schema_list(
160164 == 3
161165 )
162166
163- def test_get_acl_and_update_acl (self , organization : SchemaOrganization ) -> None :
167+ async def test_get_acl_and_update_acl (
168+ self , organization : SchemaOrganization
169+ ) -> None :
164170 # GIVEN an organization that has been initialized, but not created
165171 # THEN get_acl should raise an error
166172 with pytest .raises (
@@ -188,7 +194,7 @@ class TestJSONSchema:
188194 def init (self , syn : Synapse ) -> None :
189195 self .syn = syn
190196
191- def test_store_and_get (self , json_schema : JSONSchema ) -> None :
197+ async def test_store_and_get (self , json_schema : JSONSchema ) -> None :
192198 # GIVEN an initialized schema object that hasn't been stored in Synapse
193199 # THEN it shouldn't have any metadata besides it's name and organization name, and uri
194200 assert json_schema .name
@@ -218,7 +224,7 @@ def test_store_and_get(self, json_schema: JSONSchema) -> None:
218224 assert js2 .created_by
219225 assert js2 .created_on
220226
221- def test_get_versions (self , json_schema : JSONSchema ) -> None :
227+ async def test_get_versions (self , json_schema : JSONSchema ) -> None :
222228 # GIVEN an schema that hasn't been created
223229 # THEN get_versions should return an empty list
224230 assert len (list (json_schema .get_versions (synapse_client = self .syn ))) == 0
@@ -233,7 +239,7 @@ def test_get_versions(self, json_schema: JSONSchema) -> None:
233239 assert len (schemas ) == 1
234240 assert schemas [0 ].semantic_version == "0.0.1"
235241
236- def test_get_body (self , json_schema : JSONSchema ) -> None :
242+ async def test_get_body (self , json_schema : JSONSchema ) -> None :
237243 # GIVEN an schema that hasn't been created
238244 # WHEN creating a schema with 2 version
239245 first_body = {}
0 commit comments