From 753ef664ca543ef1c12ea3926d2d2326695ae9fb Mon Sep 17 00:00:00 2001 From: Howard Hellyer Date: Fri, 21 Jun 2024 16:32:29 +0100 Subject: [PATCH] Fix linter errors, improve docs. --- ns1/rest/zones.py | 5 +++++ ns1/zones.py | 11 ++++++++--- tests/unit/test_zone.py | 12 +++++++----- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/ns1/rest/zones.py b/ns1/rest/zones.py index fd39800..d61e8c4 100644 --- a/ns1/rest/zones.py +++ b/ns1/rest/zones.py @@ -25,6 +25,11 @@ class Zones(resource.BaseResource): ] BOOL_FIELDS = ["dnssec"] + ZONEFILE_FIELDS = [ + "networks", + "views", + ] + def _buildBody(self, zone, **kwargs): body = {} body["zone"] = zone diff --git a/ns1/zones.py b/ns1/zones.py index 16c1aca..524e1ee 100644 --- a/ns1/zones.py +++ b/ns1/zones.py @@ -94,10 +94,15 @@ def create(self, name=None, zoneFile=None, callback=None, errback=None, **kwargs """ Create a new zone. Pass a list of keywords and their values to configure. For the list of keywords available for zone configuration, - see :attr:`ns1.rest.zones.Zones.INT_FIELDS` and + see :attr:`ns1.rest.zones.Zones.INT_FIELDS`, + :attr:`ns1.rest.zones.Zones.BOOL_FIELDS` and :attr:`ns1.rest.zones.Zones.PASSTHRU_FIELDS` - If zoneFile is passed, it should be a zone text file on the local disk - that will be used to populate the created zone file. + Use `name` to pass a unique name for the zone otherwise this will + default to the zone FQDN. + If zoneFile is passed, it should be a zone text file on the local + disk that will be used to populate the created zone file. When a + zoneFile is passed only `name` and + :attr:`ns1.rest.zones.Zones.ZONEFILE_FIELDS` are supported. """ if self.data: raise ZoneException("zone already loaded") diff --git a/tests/unit/test_zone.py b/tests/unit/test_zone.py index f58df03..8f7df49 100644 --- a/tests/unit/test_zone.py +++ b/tests/unit/test_zone.py @@ -74,23 +74,24 @@ def test_rest_zone_create(zones_config, zone, name, url): z._make_request = mock.MagicMock() z.create(zone, name=name) z._make_request.assert_called_once_with( - "PUT", url, body={"zone":zone}, callback=None, errback=None + "PUT", url, body={"zone": zone}, callback=None, errback=None ) + @pytest.mark.parametrize( - "zone, name, url, networks, views",[ + "zone, name, url, networks, views", [ ("test.zone", None, "import/zonefile/test.zone", None, None), ("test.zone", "test.name", "import/zonefile/test.zone", None, None), - ("test.zone", "test.name", "import/zonefile/test.zone", [1,2,99], None), + ("test.zone", "test.name", "import/zonefile/test.zone", [1, 2, 99], None), ("test.zone", "test.name", "import/zonefile/test.zone", None, ["view1", "view2"]), - ("test.zone", "test.name", "import/zonefile/test.zone", [3,4,99], ["viewA", "viewB"]), + ("test.zone", "test.name", "import/zonefile/test.zone", [3, 4, 99], ["viewA", "viewB"]), ] ) def test_rest_zone_import_file(zones_config, zone, name, url, networks, views): z = ns1.rest.zones.Zones(zones_config) z._make_request = mock.MagicMock() params = {} - networksStrs=None + networksStrs = None if networks is not None: networksStrs = map(str, networks) params['networks'] = ",".join(networksStrs) @@ -106,6 +107,7 @@ def test_rest_zone_import_file(zones_config, zone, name, url, networks, views): "PUT", url, files=mock.ANY, params=params, callback=None, errback=None ) + @pytest.mark.parametrize( "zone, url", [("test.zone", "zones/test.zone/versions?force=false")] )