Skip to content

Commit

Permalink
Test improvements for Alert Channels/Integrations
Browse files Browse the repository at this point in the history
- Individual test runs now create unique information to prevent conflicts if parallel tests are running.
  • Loading branch information
Alan Nix committed Dec 22, 2020
1 parent 24d20f7 commit 57731ce
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 53 deletions.
33 changes: 18 additions & 15 deletions tests/api/test_alert_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
"""

import random
import string

from laceworksdk.api.alert_channels import AlertChannelsAPI

INTEGRATION_GUID = None
RANDOM_TEXT = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(8))


# Tests
Expand Down Expand Up @@ -50,11 +52,11 @@ def test_alert_channels_api_get_by_guid(api):

def test_alert_channels_api_create(api):
response = api.alert_channels.create(
name="Slack Test",
name=f"Slack Test {RANDOM_TEXT}",
type="SlackChannel",
enabled=1,
data={
"slackUrl": "https://hooks.slack.com/services/TEST/WEBHOOK"
"slackUrl": f"https://hooks.slack.com/services/TEST/WEBHOOK/{RANDOM_TEXT}"
}
)

Expand All @@ -81,21 +83,22 @@ def test_alert_channels_api_search(api):


def test_alert_channels_api_update(api):
new_name = "Slack Test Updated"
new_enabled = False
if INTEGRATION_GUID:
new_name = f"Slack Test {RANDOM_TEXT} Updated"
new_enabled = False

response = api.alert_channels.update(
INTEGRATION_GUID,
name=new_name,
enabled=new_enabled
)
response = api.alert_channels.update(
INTEGRATION_GUID,
name=new_name,
enabled=new_enabled
)

assert 'data' in response.keys()
assert response["data"][0]["name"] == new_name
assert response["data"][0]["enabled"] == int(new_enabled)
assert 'data' in response.keys()
assert response["data"][0]["name"] == new_name
assert response["data"][0]["enabled"] == int(new_enabled)


def test_alert_channels_api_delete(api):
response = api.alert_channels.delete(INTEGRATION_GUID)

assert response.status_code == 204
if INTEGRATION_GUID:
response = api.alert_channels.delete(INTEGRATION_GUID)
assert response.status_code == 204
79 changes: 41 additions & 38 deletions tests/api/test_integrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
"""

import random
import string

from laceworksdk.api.integrations import IntegrationsAPI

INTEGRATION_GUID = None
RANDOM_TEXT = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(8))


# Tests
Expand Down Expand Up @@ -43,11 +45,11 @@ def test_integrations_api_get_schema(api):

def test_integrations_api_create(api):
response = api.integrations.create(
name="Slack Test",
name=f"Slack Test {RANDOM_TEXT}",
type="SLACK_CHANNEL",
enabled=True,
data={
"SLACK_URL": "https://hooks.slack.com/services/TEST/WEBHOOK"
"SLACK_URL": f"https://hooks.slack.com/services/TEST/WEBHOOK/{RANDOM_TEXT}"
}
)

Expand All @@ -58,54 +60,55 @@ def test_integrations_api_create(api):


def test_integrations_api_update(api):
new_name = "Slack Test Updated"
new_enabled = False
if INTEGRATION_GUID:
new_name = f"Slack Test {RANDOM_TEXT} Updated"
new_enabled = False

response = api.integrations.update(
INTEGRATION_GUID,
name=new_name,
enabled=new_enabled
)
response = api.integrations.update(
INTEGRATION_GUID,
name=new_name,
enabled=new_enabled
)

assert 'data' in response.keys()
assert response["data"][0]["NAME"] == new_name
assert response["data"][0]["ENABLED"] == int(new_enabled)
assert 'data' in response.keys()
assert response["data"][0]["NAME"] == new_name
assert response["data"][0]["ENABLED"] == int(new_enabled)


def test_integrations_api_update_by_id(api):
new_name = "Slack Test Updated 2"
new_enabled = True
if INTEGRATION_GUID:
new_name = f"Slack Test {RANDOM_TEXT} Updated 2"
new_enabled = True

response = api.integrations.update_by_id(
INTEGRATION_GUID,
name=new_name,
type="SLACK_CHANNEL",
enabled=new_enabled,
data={
"SLACK_URL": "https://hooks.slack.com/services/TEST/WEBHOOK"
}
)
response = api.integrations.update_by_id(
INTEGRATION_GUID,
name=new_name,
type="SLACK_CHANNEL",
enabled=new_enabled,
data={
"SLACK_URL": f"https://hooks.slack.com/services/TEST/WEBHOOK/{RANDOM_TEXT}"
}
)

assert 'data' in response.keys()
assert response["data"][0]["NAME"] == new_name
assert response["data"][0]["ENABLED"] == int(new_enabled)
assert 'data' in response.keys()
assert response["data"][0]["NAME"] == new_name
assert response["data"][0]["ENABLED"] == int(new_enabled)


def test_integrations_api_update_status(api):
new_enabled = False
if INTEGRATION_GUID:
new_enabled = False

response = api.integrations.update_status(
INTEGRATION_GUID,
enabled=new_enabled
)
response = api.integrations.update_status(
INTEGRATION_GUID,
enabled=new_enabled
)

assert 'data' in response.keys()
assert response["data"][0]["ENABLED"] == int(new_enabled)
assert 'data' in response.keys()
assert response["data"][0]["ENABLED"] == int(new_enabled)


def test_integrations_api_delete(api):
response = api.integrations.delete(INTEGRATION_GUID)

print(response)

assert response["ok"]
if INTEGRATION_GUID:
response = api.integrations.delete(INTEGRATION_GUID)
assert response["ok"]

0 comments on commit 57731ce

Please sign in to comment.