Skip to content

Commit 7c4cdb4

Browse files
api-clients-generation-pipeline[bot]jirikuncarci.datadog-api-spec
authored
Migrate manual tests to BDD scenarios (#608)
* fix undo from different version and camelCase access * fix cassette names * use correct version * Regenerate client from commit 5bae09b of spec repo Co-authored-by: Jiri Kuncar <[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 5d0245e commit 7c4cdb4

File tree

72 files changed

+3292
-147
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+3292
-147
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.5.1.dev2",
7-
"regenerated": "2021-10-14 09:42:22.698222",
8-
"spec_repo_commit": "52f8e03"
7+
"regenerated": "2021-10-14 17:39:58.149064",
8+
"spec_repo_commit": "5bae09b"
99
},
1010
"v2": {
1111
"apigentools_version": "1.5.1.dev2",
12-
"regenerated": "2021-10-14 09:43:03.256268",
13-
"spec_repo_commit": "52f8e03"
12+
"regenerated": "2021-10-14 17:40:37.330324",
13+
"spec_repo_commit": "5bae09b"
1414
}
1515
}
1616
}

src/datadog_api_client/v1/api/monitors_api.py

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/datadog_api_client/v1/openapi.yaml

Lines changed: 36 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/conftest.py

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,10 @@ def glom(value, path):
146146
from glom import glom as g
147147

148148
# replace foo[index].bar by foo.index.bar
149-
return g(value, re.sub(r"\[([0-9]*)\]", r".\1", path))
149+
path = re.sub(r"\[([0-9]*)\]", r".\1", path)
150+
# replace camelCase to snake_case
151+
path = ".".join(snake_case(p) for p in path.split("."))
152+
return g(value, path)
150153

151154

152155
def _get_prefix(request):
@@ -266,6 +269,11 @@ def vcr_config():
266269
return config
267270

268271

272+
@pytest.fixture
273+
def default_cassette_name(default_cassette_name):
274+
return re.sub("__+", "_", default_cassette_name)
275+
276+
269277
@pytest.fixture
270278
def freezer(default_cassette_name, record_mode, vcr):
271279
from freezegun import freeze_time
@@ -327,23 +335,29 @@ def a_valid_application_key(configuration):
327335
configuration.api_key["appKeyAuth"] = os.getenv("DD_TEST_CLIENT_APP_KEY", "fake")
328336

329337

338+
@pytest.fixture(scope="module")
339+
def package_name(api_version):
340+
return "datadog_api_client." + api_version
341+
342+
330343
@pytest.fixture
331344
def _package(package_name):
332345
return importlib.import_module(package_name)
333346

334347

335348
@pytest.fixture(scope="module")
336-
def undo_operations(package_name):
337-
version = package_name.split(".")[-1]
338-
with open(
339-
os.path.join(os.path.dirname(__file__), version, "features", "undo.json")
340-
) as fp:
341-
data = json.load(fp)
349+
def undo_operations():
350+
result = {}
351+
for f in pathlib.Path(os.path.dirname(__file__)).rglob("undo.json"):
352+
version = f.parent.parent.name
353+
with f.open() as fp:
354+
data = json.load(fp)
355+
result[version] = {
356+
snake_case(operation_id): settings.get("undo")
357+
for operation_id, settings in data.items()
358+
}
342359

343-
return {
344-
snake_case(operation_id): settings.get("undo")
345-
for operation_id, settings in data.items()
346-
}
360+
return result
347361

348362

349363
def build_configuration(package):
@@ -485,7 +499,7 @@ def build_param(p):
485499

486500
# register undo method
487501
context["undo_operations"].append(
488-
lambda: undo(api, operation_name, result, client=client)
502+
lambda: undo(api, version, operation_name, result, client=client)
489503
)
490504

491505
# optional re-shaping
@@ -513,13 +527,13 @@ def undo(package_name, undo_operations, client):
513527
"""Clean after operation."""
514528
exceptions = importlib.import_module(package_name + ".exceptions")
515529

516-
def cleanup(api, operation_id, response, client=client):
517-
if operation_id not in undo_operations:
518-
raise NotImplementedError(operation_id)
530+
def cleanup(api, version, operation_id, response, client=client):
531+
operation = undo_operations.get(version, {}).get(operation_id)
532+
if operation_id is None:
533+
raise NotImplementedError((version, operation_id))
519534

520-
operation = undo_operations[operation_id]
521535
if operation["type"] is None:
522-
raise NotImplementedError(operation_id)
536+
raise NotImplementedError((version, operation_id))
523537

524538
if operation["type"] != "unsafe":
525539
return
@@ -552,7 +566,7 @@ def cleanup(api, operation_id, response, client=client):
552566

553567

554568
@when("the request is sent")
555-
def execute_request(undo, context, client, _package):
569+
def execute_request(undo, context, client, api_version, _package):
556570
"""Execute the prepared request."""
557571
api_request = context["api_request"]
558572
exceptions = importlib.import_module(context["api"]["package"] + ".exceptions")
@@ -576,7 +590,7 @@ def execute_request(undo, context, client, _package):
576590
operation_id = api_request["request"].__name__
577591
response = api_request["response"][0]
578592

579-
context["undo_operations"].append(lambda: undo(api, operation_id, response))
593+
context["undo_operations"].append(lambda: undo(api, api_version, operation_id, response))
580594

581595

582596
@then(parsers.parse('I should get an instance of "{name}"'))
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2021-10-01T08:28:32.161Z
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
interactions:
2+
- request:
3+
body: null
4+
headers:
5+
accept:
6+
- application/json, */*;q=0.8
7+
connection:
8+
- close
9+
host:
10+
- api.datadoghq.com
11+
user-agent:
12+
- datadog-api-client-typescript/1.0.0-beta.5 (node 14.18.0; os Linux; arch x64)
13+
x-datadog-parent-id:
14+
- '1445885062133744428'
15+
x-datadog-trace-id:
16+
- '1844874165778158805'
17+
method: DELETE
18+
uri: https://api.datadoghq.com/api/v1/downtime/0
19+
response:
20+
body:
21+
string: '{"errors": ["Downtime 0 not found"]}'
22+
headers:
23+
cache-control:
24+
- no-cache
25+
connection:
26+
- close
27+
content-length:
28+
- '36'
29+
content-security-policy:
30+
- frame-ancestors 'self'; report-uri https://api.datadoghq.com/csp-report
31+
content-type:
32+
- application/json
33+
date:
34+
- Fri, 01 Oct 2021 08:28:32 GMT
35+
pragma:
36+
- no-cache
37+
strict-transport-security:
38+
- max-age=15724800;
39+
vary:
40+
- Accept-Encoding
41+
x-content-type-options:
42+
- nosniff
43+
x-frame-options:
44+
- SAMEORIGIN
45+
status:
46+
code: 404
47+
message: Not Found
48+
version: 1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2021-10-01T08:28:32.231Z

0 commit comments

Comments
 (0)