Skip to content

Commit d0f29e8

Browse files
api-clients-generation-pipeline[bot]nkzouci.datadog-api-spec
authored
Add new bdd assertions in sdk tests (#1430)
* add object array key value step definition * add array contains value assertion * specify assert for arrays * Regenerate client from commit 05a49f9c of spec repo --------- Co-authored-by: Kevin Zou <[email protected]> Co-authored-by: api-clients-generation-pipeline[bot] <54105614+api-clients-generation-pipeline[bot]@users.noreply.github.com> Co-authored-by: ci.datadog-api-spec <[email protected]>
1 parent 4ebc987 commit d0f29e8

15 files changed

+94
-10
lines changed

.apigentools-info

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
"spec_versions": {
55
"v1": {
66
"apigentools_version": "1.6.4",
7-
"regenerated": "2023-05-03 17:34:25.219045",
8-
"spec_repo_commit": "b8cbfe94"
7+
"regenerated": "2023-05-04 18:36:58.546008",
8+
"spec_repo_commit": "05a49f9c"
99
},
1010
"v2": {
1111
"apigentools_version": "1.6.4",
12-
"regenerated": "2023-05-03 17:34:25.231427",
13-
"spec_repo_commit": "b8cbfe94"
12+
"regenerated": "2023-05-04 18:36:58.558261",
13+
"spec_repo_commit": "05a49f9c"
1414
}
1515
}
1616
}

.generator/conftest.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,3 +528,12 @@ def expect_equal_response_items(context, fixture_length):
528528
@then(parsers.parse('the response "{response_path}" is false'))
529529
def expect_false(context, response_path):
530530
"""Check that a response attribute is false."""
531+
532+
533+
@then(parsers.parse('the response "{response_path}" has item with field "{key_path}" with value {value}'))
534+
def expect_array_contains_object(context, response_path, key_path, value):
535+
"""Check that a response attribute contains an object with the specified key and value."""
536+
537+
@then(parsers.parse('the response "{response_path}" array contains value {value}'))
538+
def expect_array_contains_object(context, response_path, value):
539+
"""Check that a response array contains the specified value."""

tests/conftest.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,3 +643,24 @@ def expect_equal_response_items(context, fixture_length):
643643
def expect_false(context, response_path):
644644
response_value = glom(context["api_request"]["response"][0], response_path)
645645
assert not response_value
646+
647+
648+
@then(parsers.parse('the response "{response_path}" has item with field "{key_path}" with value {value}'))
649+
def expect_array_contains_object(context, response_path, key_path, value):
650+
response_value = glom(context["api_request"]["response"][0], response_path)
651+
test_value = json.loads(Template(value).render(**context))
652+
for response_item in response_value:
653+
response_item_value = glom(response_item, key_path)
654+
if response_item_value == test_value:
655+
return
656+
raise AssertionError(f'could not find key value pair in object array: "{key_path}": "{test_value}"')
657+
658+
659+
@then(parsers.parse('the response "{response_path}" array contains value {value}'))
660+
def expect_array_contains_object(context, response_path, value):
661+
response_value = glom(context["api_request"]["response"][0], response_path)
662+
test_value = json.loads(Template(value).render(**context))
663+
for response_item in response_value:
664+
if response_item == test_value:
665+
return
666+
raise AssertionError(f"could not find value in array: {test_value}")

tests/v1/features/dashboards.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ Feature: Dashboards
554554
When the request is sent
555555
Then the response status is 200 OK
556556
And the response "title" is equal to "{{ unique }}"
557-
And the response "tags[0]" is equal to "team:foobar"
557+
And the response "tags" array contains value "team:foobar"
558558

559559
@team:DataDog/dashboards-backend
560560
Scenario: Create a new dashboard with template variable defaults and default returns "Bad Request" response

tests/v1/features/notebooks.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ Feature: Notebooks
8484
Given new "ListNotebooks" request
8585
When the request is sent
8686
Then the response status is 200 OK
87+
And the response "data" has item with field "attributes.status" with value "published"
8788

8889
@generated @skip @team:DataDog/notebooks
8990
Scenario: Update a notebook returns "Bad Request" response

tests/v1/features/synthetics.feature

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,8 @@ Feature: Synthetics
569569
And body with value {"tests": [{"public_id": "{{ synthetics_api_test.public_id }}"}]}
570570
When the request is sent
571571
Then the response status is 200 OK
572+
And the response "triggered_check_ids" array contains value "{{ synthetics_api_test.public_id }}"
573+
And the response "results" has item with field "public_id" with value "{{ synthetics_api_test.public_id }}"
572574

573575
@generated @skip @team:DataDog/synthetics-app
574576
Scenario: Trigger tests from CI/CD pipelines returns "JSON format is wrong" response
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2022-12-05T18:19:32.662Z
1+
2023-04-26T15:06:53.728Z

tests/v2/cassettes/test_scenarios/test_list_all_the_rum_applications_returns_ok_response.yaml

Lines changed: 36 additions & 2 deletions
Large diffs are not rendered by default.

tests/v2/features/monitors.feature

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,8 @@ Feature: Monitors
108108
And new "ListMonitorConfigPolicies" request
109109
When the request is sent
110110
Then the response status is 200 OK
111-
And the response "data[0].type" is equal to "monitor-config-policy"
111+
And the response "data" has item with field "type" with value "monitor-config-policy"
112+
And the response "data" has item with field "id" with value "{{ monitor_configuration_policy.data.id }}"
113+
And the response "data" has item with field "attributes.policy_type" with value "tag"
114+
And the response "data" has item with field "attributes.policy.tag_key" with value "{{ unique_lower_alnum }}"
115+
And the response "data" has item with field "attributes.policy.valid_tag_values" with value ["prod", "staging"]

tests/v2/features/roles.feature

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ Feature: Roles
199199
Given new "ListPermissions" request
200200
When the request is sent
201201
Then the response status is 200 OK
202+
And the response "data" has item with field "attributes.restricted" with value true
203+
And the response "data" has item with field "attributes.restricted" with value false
204+
And the response "data" has item with field "attributes.name" with value "admin"
202205

203206
@team:DataDog/aaa-core-access
204207
Scenario: List roles returns "OK" response

0 commit comments

Comments
 (0)