diff --git a/test/__init__.py b/test/__init__.py index 5e2e3a44..c69ed61f 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -1,3 +1,4 @@ +import time import unittest from arrow.apollo import get_apollo_instance @@ -9,4 +10,23 @@ def setup_package(): class ApolloTestCase(unittest.TestCase): - pass + + def waitOrgDeleted(self, org_id): + """ + Wait for an organism to be really deleted from Apollo + """ + + org_info = wa.organisms.show_organism(org_id) + if 'directory' in org_info: + time.sleep(1) + org_info = wa.organisms.show_organism(org_id) + + def waitOrgCreated(self, org_id): + """ + Wait for an organism to be really created from Apollo + """ + + org_info = wa.organisms.show_organism(org_id) + if 'directory' in org_info: + time.sleep(1) + org_info = wa.organisms.show_organism(org_id) diff --git a/test/organism_test.py b/test/organism_test.py index 2e2d9257..035ecb31 100644 --- a/test/organism_test.py +++ b/test/organism_test.py @@ -94,13 +94,11 @@ def test_update_metadata(self): def test_delete_organism(self): - time.sleep(3) - org_info = wa.organisms.show_organism('temp_org') wa.organisms.delete_organism(org_info['id']) - time.sleep(3) + self.waitOrgDeleted('temp_org') orgs = wa.organisms.get_organisms() @@ -109,11 +107,9 @@ def test_delete_organism(self): def test_delete_organism_cn(self): - time.sleep(3) - wa.organisms.delete_organism('temp_org') - time.sleep(3) + self.waitOrgDeleted('temp_org') orgs = wa.organisms.get_organisms() @@ -122,8 +118,6 @@ def test_delete_organism_cn(self): def test_delete_features(self): - time.sleep(3) - wa.annotations.load_gff3('temp_org', 'test-data/merlin.gff') org_info = wa.organisms.show_organism('temp_org') @@ -142,8 +136,6 @@ def test_delete_features(self): def test_delete_features_cn(self): - time.sleep(3) - wa.annotations.load_gff3('temp_org', 'test-data/merlin.gff') org_info = wa.organisms.show_organism('temp_org') @@ -335,7 +327,7 @@ def test_add_organism(self): meta_back = json.loads(res['metadata']) assert 'bla' in meta_back and meta_back['bla'] == 'bli' - time.sleep(3) + self.waitOrgCreated('some_new_org') org_info = wa.organisms.show_organism('some_new_org') @@ -349,6 +341,12 @@ def test_add_organism(self): assert 'bla' in meta_back and meta_back['bla'] == 'bli' def setUp(self): + # Make sure the organism is not already there + temp_org_info = wa.organisms.show_organism('temp_org') + if 'directory' in temp_org_info: + wa.organisms.delete_organism(temp_org_info['id']) + self.waitOrgDeleted('temp_org') + org_info = wa.organisms.show_organism('alt_org') if 'directory' not in org_info: # Should not happen, but let's be tolerant... @@ -357,6 +355,7 @@ def setUp(self): org_info = wa.organisms.show_organism('alt_org') wa.organisms.add_organism('temp_org', org_info['directory']) + self.waitOrgCreated('temp_org') def tearDown(self): org_info = wa.organisms.show_organism('temp_org') @@ -364,7 +363,10 @@ def tearDown(self): if org_info and 'id' in org_info: wa.organisms.delete_organism(org_info['id']) + self.waitOrgDeleted('temp_org') + org_info = wa.organisms.show_organism('some_new_org') if org_info and 'id' in org_info: wa.organisms.delete_organism(org_info['id']) + self.waitOrgDeleted('some_new_org') diff --git a/test/remote_test.py b/test/remote_test.py index d480281b..5b531238 100644 --- a/test/remote_test.py +++ b/test/remote_test.py @@ -11,13 +11,11 @@ class RemoteTest(ApolloTestCase): def test_delete_organism(self): - time.sleep(3) - org_info = wa.organisms.show_organism('temp_org') wa.remote.delete_organism(org_info['id']) - time.sleep(3) + self.waitOrgDeleted('temp_org') orgs = wa.organisms.get_organisms() @@ -26,11 +24,9 @@ def test_delete_organism(self): def test_delete_organism_cn(self): - time.sleep(3) - wa.remote.delete_organism('temp_org') - time.sleep(3) + self.waitOrgDeleted('temp_org') orgs = wa.organisms.get_organisms() @@ -39,9 +35,8 @@ def test_delete_organism_cn(self): def test_update_organism(self): - time.sleep(3) - org_info = wa.organisms.show_organism('temp_org') + assert org_info['sequences'] == 1 meta = {"bla": "bli"} @@ -71,9 +66,8 @@ def test_update_organism(self): def test_update_organism_noreload(self): - time.sleep(3) - org_info = wa.organisms.show_organism('temp_org') + assert org_info['sequences'] == 1 meta = {"bla": "bli"} @@ -103,9 +97,8 @@ def test_update_organism_noreload(self): def test_update_organism_newseq(self): - time.sleep(3) - org_info = wa.organisms.show_organism('temp_org') + assert org_info['sequences'] == 1 meta = {"bla": "bli"} @@ -130,18 +123,17 @@ def test_update_organism_newseq(self): assert len(seqs) == 2 seq = seqs[0] - assert seq['name'] == 'Merlin' - assert seq['length'] == 172788 - - seq = seqs[1] assert seq['name'] == 'Anotherseq' assert seq['length'] == 4730 - def test_update_organism_changedseq(self): + seq = seqs[1] + assert seq['name'] == 'Merlin' + assert seq['length'] == 172788 - time.sleep(3) + def test_update_organism_changedseq(self): org_info = wa.organisms.show_organism('temp_org') + assert org_info['sequences'] == 1 meta = {"bla": "bli"} @@ -166,18 +158,17 @@ def test_update_organism_changedseq(self): assert len(seqs) == 2 seq = seqs[0] - assert seq['name'] == 'Merlin' - assert seq['length'] == 172188 - - seq = seqs[1] assert seq['name'] == 'Anotherseq' assert seq['length'] == 4730 - def test_update_organism_newseq_noreload(self): + seq = seqs[1] + assert seq['name'] == 'Merlin' + assert seq['length'] == 172188 - time.sleep(3) + def test_update_organism_newseq_noreload(self): org_info = wa.organisms.show_organism('temp_org') + assert org_info['sequences'] == 1 meta = {"bla": "bli"} @@ -207,9 +198,8 @@ def test_update_organism_newseq_noreload(self): def test_update_organism_changedseq_noreload(self): - time.sleep(3) - org_info = wa.organisms.show_organism('temp_org') + assert org_info['sequences'] == 1 meta = {"bla": "bli"} @@ -254,14 +244,16 @@ def test_add_organism(self): meta_back = json.loads(res['metadata']) assert 'bla' in meta_back and meta_back['bla'] == 'bli' - time.sleep(3) + self.waitOrgCreated('some_new_org_remote') org_info = wa.organisms.show_organism('some_new_org_remote') wa.remote.delete_organism(org_info['id']) + self.waitOrgDeleted('some_new_org_remote') assert org_info['species'] == 'newspecies' assert org_info['genus'] == 'newgenus' + assert org_info['sequences'] == 1 meta_back = json.loads(org_info['metadata']) assert 'bla' in meta_back and meta_back['bla'] == 'bli' @@ -281,7 +273,10 @@ def tearDown(self): if org_info and 'id' in org_info: wa.organisms.delete_organism(org_info['id']) + self.waitOrgDeleted('temp_org') + org_info = wa.organisms.show_organism('some_new_org_remote') if org_info and 'id' in org_info: wa.organisms.delete_organism(org_info['id']) + self.waitOrgDeleted('some_new_org_remote')