Skip to content

Commit

Permalink
test: Address pytest warnings; remove duplicate test helper (#463)
Browse files Browse the repository at this point in the history
* address pytest warnings, duplicate test helper

* update description

* update description

* remove pytest.ini file; add pytest markers to toml

* fix event test

* add e2e firewall to test instance

* add e2e firewall to test instance
  • Loading branch information
ykim-akamai authored Oct 8, 2024
1 parent 46d6d18 commit 9d63e07
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ dev = [
"sphinxcontrib-fulltoc>=1.2.0",
"build>=0.10.0",
"twine>=4.0.2",
"pytest-rerunfailures",
]

doc = [
Expand Down Expand Up @@ -88,3 +89,9 @@ in-place = true
recursive = true
remove-all-unused-imports = true
remove-duplicate-keys = false

[tool.pytest.ini_options]
markers = [
"smoke: mark a test as a smoke test",
"flaky: mark a test as a flaky test for rerun"
]
6 changes: 0 additions & 6 deletions test/integration/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ def get_test_label():
return label


def get_rand_nanosec_test_label():
unique_timestamp = str(time.time_ns())[:-3]
label = "test_" + unique_timestamp
return label


def delete_instance_with_test_kw(paginated_list: PaginatedList):
for i in paginated_list:
try:
Expand Down
16 changes: 12 additions & 4 deletions test/integration/models/account/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,32 @@ def test_get_account_settings(test_linode_client):


@pytest.mark.smoke
def test_latest_get_event(test_linode_client):
def test_latest_get_event(test_linode_client, e2e_test_firewall):
client = test_linode_client

available_regions = client.regions()
chosen_region = available_regions[4]
label = get_test_label()

linode, password = client.linode.instance_create(
"g6-nanode-1", chosen_region, image="linode/debian10", label=label
"g6-nanode-1",
chosen_region,
image="linode/debian10",
label=label,
firewall=e2e_test_firewall,
)

events = client.load(Event, "")

latest_event = events._raw_json.get("data")[0]
latest_events = events._raw_json.get("data")

linode.delete()

assert label in latest_event["entity"]["label"]
for event in latest_events[:15]:
if label == event["entity"]["label"]:
break
else:
assert False, f"Linode '{label}' not found in the last 15 events"


def test_get_user(test_linode_client):
Expand Down
5 changes: 3 additions & 2 deletions test/integration/models/firewall/test_firewall.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import time
from test.integration.helpers import get_test_label

import pytest

Expand All @@ -10,7 +11,7 @@ def linode_fw(test_linode_client):
client = test_linode_client
available_regions = client.regions()
chosen_region = available_regions[4]
label = "linode_instance_fw_device"
label = get_test_label()

linode_instance, password = client.linode.instance_create(
"g6-nanode-1", chosen_region, image="linode/debian10", label=label
Expand Down Expand Up @@ -79,6 +80,6 @@ def test_get_device(test_linode_client, test_firewall, linode_fw):
FirewallDevice, firewall.devices.first().id, firewall.id
)

assert firewall_device.entity.label == "linode_instance_fw_device"
assert "test_" in firewall_device.entity.label
assert firewall_device.entity.type == "linode"
assert "/v4/linode/instances/" in firewall_device.entity.url
4 changes: 2 additions & 2 deletions test/integration/models/networking/test_networking.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from test.integration.helpers import get_rand_nanosec_test_label
from test.integration.helpers import get_test_label

import pytest

Expand All @@ -22,7 +22,7 @@ def create_linode(test_linode_client):
client = test_linode_client
available_regions = client.regions()
chosen_region = available_regions[4]
label = get_rand_nanosec_test_label()
label = get_test_label()

linode_instance, _ = client.linode.instance_create(
"g6-nanode-1",
Expand Down

0 comments on commit 9d63e07

Please sign in to comment.