Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for options on delete #513

Merged
merged 8 commits into from
Jan 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 30 additions & 11 deletions tests/integration/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def teardown_class(cls):
for uuid in cls.cleanup_role_uuids:
dog.Roles.delete(uuid)


def test_tags(self):
hostname = "test.tags.host" + str(time.time())
# post a metric to make sure the test host context exists
Expand Down Expand Up @@ -529,16 +528,11 @@ def test_monitor_can_delete(self):

# Check if you can delete the monitor.
monitor_ids = [monitor["id"]]
assert dog.Monitor.can_delete(monitor_ids=monitor_ids) == {
"data": {"ok": []},
"errors": {
str(monitor["id"]): [
MONITOR_REFERENCED_IN_SLO_MESSAGE.format(
monitor["id"], slo["id"]
)
]
},
}
resp = dog.Monitor.can_delete(monitor_ids=monitor_ids)
assert "errors" in resp
assert str(monitor["id"]) in resp["errors"]
assert len(resp["errors"][str(monitor["id"])])
assert "is referenced in slos" in resp["errors"][str(monitor["id"])][0]

# Delete the SLO.
dog.ServiceLevelObjective.delete(slo["id"])
Expand All @@ -555,6 +549,31 @@ def test_monitor_can_delete(self):
"deleted_monitor_id": monitor["id"]
}

def test_monitor_can_delete_with_force(self):
# Create a monitor.
query = "avg(last_1h):sum:system.net.bytes_rcvd{host:host0} > 100"
options = {
"silenced": {"*": int(time.time()) + 60 * 60},
"notify_no_data": False,
}
monitor = dog.Monitor.create(type="metric alert", query=query, options=options)
monitor_ids = [monitor["id"]]

# Create a monitor-based SLO.
name = "test SLO {}".format(time.time())
thresholds = [{"timeframe": "7d", "target": 90}]
slo = dog.ServiceLevelObjective.create(
type="monitor",
monitor_ids=monitor_ids,
dabcoder marked this conversation as resolved.
Show resolved Hide resolved
thresholds=thresholds,
name=name,
)["data"][0]

# Check if you can delete the monitor with force option
assert dog.Monitor.delete(monitor["id"], force=True) == {
"deleted_monitor_id": monitor["id"]
}

def test_service_level_objective_crud(self):
numerator = "sum:my.custom.metric{type:good}.as_count()"
denominator = "sum:my.custom.metric{*}.as_count()"
Expand Down