From 6393f7a4c77497ca013395d625d181183959109b Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Mon, 11 May 2020 22:50:12 +0200 Subject: [PATCH] fix formatting and tests --- corenetworks/client.py | 9 ++++++++- corenetworks/test/fixtures/callback.py | 6 +++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/corenetworks/client.py b/corenetworks/client.py index 5bc702f..2f809f3 100644 --- a/corenetworks/client.py +++ b/corenetworks/client.py @@ -211,13 +211,20 @@ class CoreNetworks(): records = self.records(zone, params={"name": params["name"]}) for r in records: - if params["type"] == "CNAME" or r["type"] == "CNAME": + if params["type"] == "CNAME" and r["type"] != "CNAME": raise CorenetworksError( "A record with the same name already exist ({name}). " "CNAME records cannot use the same name with other records.".format( name=r["name"] ) ) + if params["type"] != "CNAME" and r["type"] == "CNAME": + raise CorenetworksError( + "A CNAME record with the same name already exist ({name}). " + "CNAME records cannot use the same name with other records.".format( + name=r["name"] + ) + ) curr = copy.deepcopy(params) curr.pop("ttl") diff --git a/corenetworks/test/fixtures/callback.py b/corenetworks/test/fixtures/callback.py index 6279394..8677a5c 100644 --- a/corenetworks/test/fixtures/callback.py +++ b/corenetworks/test/fixtures/callback.py @@ -31,7 +31,11 @@ def records_get_callback(request, context): if query_raw: query = dict((k.replace("[]", ""), v) for k, v in query_raw.items()) - res = [d for d in records if d["type"].lower() in query["type"]] + if query.get("type"): + res = [d for d in records if d["type"].lower() in query["type"]] + else: + res = [] + return "{}".format(json.dumps(res)) else: return "{}".format(json.dumps(records))