From 010cf43be7708cc5e33a60f302686d4b8908cc16 Mon Sep 17 00:00:00 2001 From: Matthias Bach Date: Fri, 2 Feb 2018 14:36:07 +0100 Subject: [PATCH] Make handling missing instances in test helpers more explicit --- tests/test_integration/test_postgras_api.py | 26 +++++++++++---------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/tests/test_integration/test_postgras_api.py b/tests/test_integration/test_postgras_api.py index b60d297..ca29730 100644 --- a/tests/test_integration/test_postgras_api.py +++ b/tests/test_integration/test_postgras_api.py @@ -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')