Skip to content

Commit

Permalink
Make handling missing instances in test helpers more explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
matthias-bach-by committed May 8, 2018
1 parent 5885998 commit 010cf43
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions tests/test_integration/test_postgras_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,22 +126,24 @@ def docker_setup(request, tmpdir):
class PostgraasApiTestBase:
def get_postgraas_by_name(self, name, client):
headers = {'Content-Type': 'application/json'}
list = client.get('/api/v2/postgraas_instances', headers=headers)
for instance in json.loads(list.get_data(as_text=True)):
instances = client.get('/api/v2/postgraas_instances', headers=headers)
for instance in json.loads(instances.get_data(as_text=True)):
if instance["postgraas_instance_name"] == name:
return instance["id"]
return None

def delete_instance_by_name(self, db_credentials, client):
id = self.get_postgraas_by_name(db_credentials["postgraas_instance_name"], client)
db_pwd = db_credentials["db_pwd"]
headers = {'Content-Type': 'application/json'}
client.delete(
'/api/v2/postgraas_instances/' + str(id),
data=json.dumps({
'db_pwd': db_pwd
}),
headers=headers
)
instance_id = self.get_postgraas_by_name(db_credentials["postgraas_instance_name"], client)
if instance_id is not None:
db_pwd = db_credentials["db_pwd"]
headers = {'Content-Type': 'application/json'}
client.delete(
'/api/v2/postgraas_instances/' + str(instance_id),
data=json.dumps({
'db_pwd': db_pwd
}),
headers=headers
)


@pytest.mark.usefixtures('docker_setup')
Expand Down

0 comments on commit 010cf43

Please sign in to comment.