Skip to content

Commit

Permalink
feat: OBS-442 - tests: add integration test for device with tags
Browse files Browse the repository at this point in the history
Signed-off-by: Michal Fiedorowicz <mfiedorowicz@netboxlabs.com>
  • Loading branch information
mfiedorowicz committed May 22, 2024
1 parent 6555bda commit cf01181
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/features/ingestion_device_objects.feature
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,15 @@ Scenario: Ingestion of existing device (site provided) with different device typ
Then the device is found
And device type is "ISR4321"
And role is "WAN Router"

@smoke
@ingestion.device
Scenario: Ingestion of a new device with tags
Given device "router01" with site not provided
And tags "tag1,tag2,tag3" are provided
And device "router01" with site "undefined" does not exist
When the device with site, device type, role and tags is ingested
Then the device is found
And device type is "undefined"
And role is "undefined"
And tags "tag1,tag2,tag3" are present
34 changes: 34 additions & 0 deletions tests/features/steps/ingestion_device_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ def set_device_without_site(context, device_name):
context.device_role_name = "undefined"


@given('tags "{tags}" are provided')
def set_tags(context, tags):
context.device_tags = tags.split(",")


@given('device "{device_name}" with site "{site_name}" does not exist')
def ensure_device_does_not_exists(context, device_name, site_name):
"""Ensure that the device does not exist."""
Expand Down Expand Up @@ -88,6 +93,14 @@ def assert_device_role(context, device_role_name):
assert context.existing_device.get("device_role").get("name") == device_role_name


@then('tags "{tags}" are present')
def assert_tags(context, tags):
"""Assert that the device role is correct."""
assert context.existing_device is not None
device_tags = [tag.get("name") for tag in context.existing_device.get("tags")]
assert set(device_tags) == set(tags.split(","))


@given('device "{device_name}" with site "{site_name}" exists')
def assert_device_exists_with_site(context, device_name, site_name):
"""Assert that the device exists."""
Expand Down Expand Up @@ -160,3 +173,24 @@ def ingest_device_with_site_device_type_and_role(context):
assert context.response.errors == []

return context.response


@when("the device with site, device type, role and tags is ingested")
def ingest_device_with_site_device_type_role_and_tags(context):
"""Ingest the device using the Diode SDK"""
entities = [
Entity(
device=Device(
name=context.device_name,
site=context.site_name,
device_type=context.device_type_model,
role=context.device_role_name,
tags=context.device_tags,
),
),
]

context.response = ingester(entities)
assert context.response.errors == []

return context.response

0 comments on commit cf01181

Please sign in to comment.