Skip to content

Commit 7cd30eb

Browse files
committed
fix: support concurrent tests on taxonomies
1 parent d4dfc39 commit 7cd30eb

1 file changed

Lines changed: 34 additions & 13 deletions

File tree

tests/test_taxonomy.py

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,73 @@
33
from obiba_opal.system import TaxonomyService
44
from obiba_opal.file import FileService
55
from obiba_opal.core import HTTPError
6+
import shutil
7+
import os
8+
from uuid import uuid4
69

710
class TestClass(unittest.TestCase):
811

912
TEST_FILE = '/tmp/data.csv'
1013
TEST_ZIPPED_FILE = '/tmp/data.zip'
14+
TEST_TAXONOMY_FILENAME = 'OBiBa_taxonomyTest.yml'
15+
TEST_TAXONOMY_FILE = '/tmp/OBiBa_taxonomyTest.yml'
16+
LOCAL_TAXONOMY_FILE = '/tmp/OBiBa_taxonomyTest.yml'
17+
TEST_TAXONOMY_NAME = 'OBiBa_taxonomyTest'
1118

1219
@classmethod
1320
def setup_class(cls):
1421
cls.service = TaxonomyService(make_client())
22+
suffix = uuid4().hex
23+
cls.TEST_TAXONOMY_FILENAME = f'OBiBa_taxonomyTest_{suffix}.yml'
24+
cls.TEST_TAXONOMY_FILE = f'/tmp/{cls.TEST_TAXONOMY_FILENAME}'
25+
cls.LOCAL_TAXONOMY_FILE = f'/tmp/{cls.TEST_TAXONOMY_FILENAME}'
26+
cls.TEST_TAXONOMY_NAME = f'OBiBa_taxonomyTest_{suffix}'
1527

1628
def test_1_importFile(self):
1729
try:
1830
fileService = FileService(make_client())
19-
fileService.upload_file('./tests/resources/OBiBa_taxonomyTest.yml', '/tmp')
20-
response = fileService.file_info('/tmp/OBiBa_taxonomyTest.yml')
21-
if response['name'] == 'OBiBa_taxonomyTest.yml':
22-
response = self.service.importFile('/tmp/OBiBa_taxonomyTest.yml', True)
23-
fileService.delete_file('/tmp/OBiBa_taxonomyTest.yml')
24-
assert response.code == 201
25-
else:
26-
assert False
27-
31+
# Read and modify the taxonomy file to use randomized name
32+
with open('./tests/resources/OBiBa_taxonomyTest.yml', 'r') as f:
33+
content = f.read()
34+
content = content.replace('"OBiBa_taxonomyTest"', f'"{self.TEST_TAXONOMY_NAME}"')
35+
with open(self.LOCAL_TAXONOMY_FILE, 'w') as f:
36+
f.write(content)
37+
try:
38+
fileService.upload_file(self.LOCAL_TAXONOMY_FILE, '/tmp')
39+
response = fileService.file_info(self.TEST_TAXONOMY_FILE)
40+
if response['name'] == self.TEST_TAXONOMY_FILENAME:
41+
response = self.service.importFile(self.TEST_TAXONOMY_FILE, True)
42+
fileService.delete_file(self.TEST_TAXONOMY_FILE)
43+
assert response.code == 201
44+
else:
45+
assert False
46+
finally:
47+
if os.path.exists(self.LOCAL_TAXONOMY_FILE):
48+
os.remove(self.LOCAL_TAXONOMY_FILE)
2849
except Exception as e:
2950
assert False
3051

3152

3253
def test_2_downloadTaxonomy(self):
3354
try:
34-
response = self.service.download('OBiBa_taxonomyTest')
35-
assert response.code == 200 and 'OBiBa_taxonomyTest' in str(response)
55+
response = self.service.download(self.TEST_TAXONOMY_NAME)
56+
assert response.code == 200 and self.TEST_TAXONOMY_NAME in str(response)
3657

3758
except Exception as e:
3859
assert False
3960

4061

4162
def test_3_taxonomiesSummary(self):
4263
try:
43-
name = 'OBiBa_taxonomyTest'
64+
name = self.TEST_TAXONOMY_NAME
4465
response = self.service.summaries()
4566
assert response.code == 200 and len(list(filter(lambda t: t['name'] == name, response.from_json()['summaries']))) > 0
4667
except Exception as e:
4768
assert False
4869

4970
def test_4_deleteTaxonomy(self):
5071
try:
51-
name = 'OBiBa_taxonomyTest'
72+
name = self.TEST_TAXONOMY_NAME
5273
# keep around for interactive test
5374
# response = self.service.confirmAndDelete(name, lambda: self.service.delete(name))
5475
response = self.service.delete(name)

0 commit comments

Comments
 (0)