Skip to content

Commit

Permalink
better method to wait for organism creation/deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
abretaud committed Nov 27, 2019
1 parent 6886e16 commit 8af4182
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 39 deletions.
22 changes: 21 additions & 1 deletion test/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import time
import unittest

from arrow.apollo import get_apollo_instance
Expand All @@ -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)
24 changes: 13 additions & 11 deletions test/organism_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()

Expand All @@ -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')
Expand All @@ -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')
Expand Down Expand Up @@ -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')

Expand All @@ -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...
Expand All @@ -357,14 +355,18 @@ 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')

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')
49 changes: 22 additions & 27 deletions test/remote_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()

Expand All @@ -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"}

Expand Down Expand Up @@ -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"}

Expand Down Expand Up @@ -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"}

Expand All @@ -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"}

Expand All @@ -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"}

Expand Down Expand Up @@ -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"}

Expand Down Expand Up @@ -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'

Expand All @@ -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')

0 comments on commit 8af4182

Please sign in to comment.