Skip to content

Commit

Permalink
Fix linter errors, improve docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
hhellyer committed Jun 21, 2024
1 parent 8688bcb commit 753ef66
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
5 changes: 5 additions & 0 deletions ns1/rest/zones.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ class Zones(resource.BaseResource):
]
BOOL_FIELDS = ["dnssec"]

ZONEFILE_FIELDS = [
"networks",
"views",
]

def _buildBody(self, zone, **kwargs):
body = {}
body["zone"] = zone
Expand Down
11 changes: 8 additions & 3 deletions ns1/zones.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
12 changes: 7 additions & 5 deletions tests/unit/test_zone.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")]
)
Expand Down

0 comments on commit 753ef66

Please sign in to comment.