Skip to content

Commit

Permalink
Fix errors for the second linter.
Browse files Browse the repository at this point in the history
  • Loading branch information
hhellyer committed Oct 28, 2024
1 parent ff727bf commit c284ff5
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 41 deletions.
53 changes: 30 additions & 23 deletions examples/alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,40 @@

# create a new zone, get a Zone object back
# to use in a new alert
zone = api.createZone("example-secondary.com", secondary={
"enabled": True,
"primary_ip": "198.51.100.12",
"primary_port": 53,
"tsig": {
"enabled": False,
}
})
print("Created zone: %s" % zone['name'])
zone = api.createZone(
"example-secondary.com",
secondary={
"enabled": True,
"primary_ip": "198.51.100.12",
"primary_port": 53,
"tsig": {
"enabled": False,
},
},
)
print("Created zone: %s" % zone["name"])

# Create a notifier list.
nl = api.notifylists().create(body={
"name": "example",
"notify_list": [{
"type": "email",
"config": {
"email": "user@example.com"
}
}
]
})
print("Created notifier list with id: %s" % nl['id'])
nl_id = nl['id']
nl = api.notifylists().create(
body={
"name": "example",
"notify_list": [
{"type": "email", "config": {"email": "user@example.com"}}
],
}
)
print("Created notifier list with id: %s" % nl["id"])
nl_id = nl["id"]

# Create an alert
newAlert = api.alerts().create(name="example_alert", type="zone", subtype="transfer_failed", zone_names=["example-secondary.com"], notifier_list_ids=[nl_id])
alert_id = newAlert['id']
newAlert = api.alerts().create(
name="example_alert",
type="zone",
subtype="transfer_failed",
zone_names=["example-secondary.com"],
notifier_list_ids=[nl_id],
)
alert_id = newAlert["id"]
print("Created alert with id: %s" % alert_id)

# List alerts.
Expand Down
8 changes: 6 additions & 2 deletions ns1/rest/alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ def _buildBody(self, alid, **kwargs):

def list(self, callback=None, errback=None):
data = self._make_request(
"GET", "%s" % (self.ROOT), callback=callback,
"GET",
"%s" % (self.ROOT),
callback=callback,
errback=errback,
pagination_handler=alert_list_pagination,
)
Expand All @@ -41,7 +43,9 @@ def update(self, alid, callback=None, errback=None, **kwargs):
errback=errback,
)

def create(self, name, type, subtype, callback=None, errback=None, **kwargs):
def create(
self, name, type, subtype, callback=None, errback=None, **kwargs
):
body = {
"name": name,
"type": type,
Expand Down
66 changes: 50 additions & 16 deletions tests/unit/test_alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,15 @@ def alerts_config(config):
return config


@pytest.mark.parametrize("alert_id, url", [("9d51efb4-a012-43b0-bcd9-6fad45227baf", "../alerting/v1beta1/alerts/9d51efb4-a012-43b0-bcd9-6fad45227baf")])
@pytest.mark.parametrize(
"alert_id, url",
[
(
"9d51efb4-a012-43b0-bcd9-6fad45227baf",
"../alerting/v1beta1/alerts/9d51efb4-a012-43b0-bcd9-6fad45227baf",
)
],
)
def test_rest_alert_retrieve(alerts_config, alert_id, url):
a = ns1.rest.alerts.Alerts(alerts_config)
a._make_request = mock.MagicMock()
Expand Down Expand Up @@ -63,19 +71,21 @@ def test_rest_alert_list(alerts_config):
"../alerting/v1beta1/alerts",
{
"zone_names": ["example-secondary.com"],
"notifier_list_ids": ["6707da567cd4f300012cd7e4"]
}
"notifier_list_ids": ["6707da567cd4f300012cd7e4"],
},
)
],
)
def test_rest_alert_create(alerts_config, name, type, subtype, url, alert_params):
def test_rest_alert_create(
alerts_config, name, type, subtype, url, alert_params
):
a = ns1.rest.alerts.Alerts(alerts_config)
a._make_request = mock.MagicMock()
a.create(name=name, type=type, subtype=subtype, **alert_params)
body = alert_params
body['name'] = name
body['type'] = type
body['subtype'] = subtype
body["name"] = name
body["type"] = type
body["subtype"] = subtype
a._make_request.assert_called_once_with(
"POST",
url,
Expand All @@ -87,16 +97,18 @@ def test_rest_alert_create(alerts_config, name, type, subtype, url, alert_params

@pytest.mark.parametrize(
"alert_id, url",
[("9d51efb4-a012-43b0-bcd9-6fad45227baf", "../alerting/v1beta1/alerts/9d51efb4-a012-43b0-bcd9-6fad45227baf")],
[
(
"9d51efb4-a012-43b0-bcd9-6fad45227baf",
"../alerting/v1beta1/alerts/9d51efb4-a012-43b0-bcd9-6fad45227baf",
)
],
)
def test_rest_alert_update(alerts_config, alert_id, url):
a = ns1.rest.alerts.Alerts(alerts_config)
a._make_request = mock.MagicMock()
a.update(alert_id, name="newName")
expectedBody = {
"id": alert_id,
"name": "newName"
}
expectedBody = {"id": alert_id, "name": "newName"}
a._make_request.assert_called_once_with(
"PATCH",
url,
Expand All @@ -106,7 +118,15 @@ def test_rest_alert_update(alerts_config, alert_id, url):
)


@pytest.mark.parametrize("alert_id, url", [("9d51efb4-a012-43b0-bcd9-6fad45227baf", "../alerting/v1beta1/alerts/9d51efb4-a012-43b0-bcd9-6fad45227baf")])
@pytest.mark.parametrize(
"alert_id, url",
[
(
"9d51efb4-a012-43b0-bcd9-6fad45227baf",
"../alerting/v1beta1/alerts/9d51efb4-a012-43b0-bcd9-6fad45227baf",
)
],
)
def test_rest_alert_delete(alerts_config, alert_id, url):
a = ns1.rest.alerts.Alerts(alerts_config)
a._make_request = mock.MagicMock()
Expand All @@ -117,7 +137,15 @@ def test_rest_alert_delete(alerts_config, alert_id, url):


# Alerts have a alerts/<id>/test endpoint to verify the attached notifiers work
@pytest.mark.parametrize("alert_id, url", [("9d51efb4-a012-43b0-bcd9-6fad45227baf", "../alerting/v1beta1/alerts/9d51efb4-a012-43b0-bcd9-6fad45227baf/test")])
@pytest.mark.parametrize(
"alert_id, url",
[
(
"9d51efb4-a012-43b0-bcd9-6fad45227baf",
"../alerting/v1beta1/alerts/9d51efb4-a012-43b0-bcd9-6fad45227baf/test",
)
],
)
def test_rest_alert_do_test(alerts_config, alert_id, url):
a = ns1.rest.alerts.Alerts(alerts_config)
a._make_request = mock.MagicMock()
Expand All @@ -133,15 +161,21 @@ def test_rest_alerts_buildbody(alerts_config):
kwargs = {
"data": {"max": 80, "min": 20},
"name": "newName",
"notifier_list_ids": ["6707da567cd4f300012cd7e4", "6707da567cd4f300012cd7e6"],
"notifier_list_ids": [
"6707da567cd4f300012cd7e4",
"6707da567cd4f300012cd7e6",
],
"record_ids": ["6707da567cd4f300012cd7d4", "6707da567cd4f300012cd7d9"],
"zone_names": ["www.example.com", "mail.example.com"],
}
expectedBody = {
"id": alert_id,
"name": "newName",
"data": {"max": 80, "min": 20},
"notifier_list_ids": ["6707da567cd4f300012cd7e4", "6707da567cd4f300012cd7e6"],
"notifier_list_ids": [
"6707da567cd4f300012cd7e4",
"6707da567cd4f300012cd7e6",
],
"record_ids": ["6707da567cd4f300012cd7d4", "6707da567cd4f300012cd7d9"],
"zone_names": ["www.example.com", "mail.example.com"],
}
Expand Down

0 comments on commit c284ff5

Please sign in to comment.