Skip to content

Commit 29d1afb

Browse files
authored
Unify unique names (#368)
* Unify unique names As a step for reusing the same cassettes, unify unique generation from BDD scenario names. * Reduce datetime precision * Reduce precision * Make it work in v2, handle recording mode * Unique regexp * Re-record, fix alnum
1 parent adb3191 commit 29d1afb

File tree

137 files changed

+3524
-4629
lines changed

Some content is hidden

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

137 files changed

+3524
-4629
lines changed

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ where=src
7070
[tool:pytest]
7171
markers =
7272
dd_tag: add custom tags to span
73-
addopts = --cov=datadog_api_client --cov-config .coveragerc --cov-report=term-missing
73+
addopts = --cov=datadog_api_client --cov-config .coveragerc --cov-report=
7474
# addopts = --black --cov=datadog_api_client --cov-config .coveragerc --cov-report=term-missing
7575

7676
[flake8]

tests/conftest.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -137,28 +137,29 @@ def glom(value, path):
137137
return g(value, re.sub(r"\[([0-9]*)\]", r".\1", path))
138138

139139

140-
@pytest.fixture
141-
def unique(request, freezer):
140+
def _get_prefix(request):
142141
test_class = request.cls
143142
if test_class:
144-
prefix = "{}.{}".format(test_class.__name__, request.node.name)
143+
main = "{}.{}".format(test_class.__name__, request.node.name)
145144
else:
146-
prefix = request.node.name
145+
base_name = request.node.__scenario_report__.scenario.name
146+
main = re.sub(r"[^A-Za-z0-9]+", "_", base_name)[:100]
147+
prefix = "Test-Python" if _disable_recording() else "Test"
148+
return f"{prefix}-{main}"
149+
147150

151+
@pytest.fixture
152+
def unique(request, freezer):
153+
prefix = _get_prefix(request)
148154
with freezer:
149-
return f"datadog-api-client-python-{prefix}-{datetime.now().timestamp()}"
155+
return f"{prefix}-{datetime.now().timestamp():.0f}"
150156

151157

152158
@pytest.fixture
153159
def unique_lower(request, freezer):
154-
test_class = request.cls
155-
if test_class:
156-
prefix = "{}.{}".format(test_class.__name__, request.node.name)
157-
else:
158-
prefix = request.node.name
159-
160+
prefix = _get_prefix(request).lower()
160161
with freezer:
161-
return f"datadog-api-client-python-{prefix}-{datetime.now().timestamp()}".lower()
162+
return f"{prefix}-{datetime.now().timestamp():.0f}"
162163

163164

164165
@pytest.fixture
@@ -207,7 +208,7 @@ def context(vcr, unique, unique_lower, now_ts, now_iso, hour_later_ts, hour_late
207208
"unique": unique,
208209
"unique_lower": unique_lower,
209210
"unique_alnum": re.sub(r"[^A-Za-z0-9]+", "", unique),
210-
"unique_lower_alnum": re.sub(r"[^a-z0-9]+", "", unique),
211+
"unique_lower_alnum": re.sub(r"[^A-Za-z0-9]+", "", unique).lower(),
211212
"now_ts": now_ts,
212213
"now_iso": now_iso,
213214
"hour_later_ts": hour_later_ts,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2021-02-15T13:22:49.949769+01:00
1+
2021-04-09T22:22:15.472687+02:00

tests/v1/cassettes/test_scenarios/test_create_a_new_dashboard_with_a_profile_metric_query.yaml

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
interactions:
22
- request:
3-
body: '{"layout_type": "ordered", "title": "datadog-api-client-python-test_create_a_new_dashboard_with_a_profile_metric_query-1613391769.949769
3+
body: '{"layout_type": "ordered", "title": "Test-Create_a_new_dashboard_with_a_profile_metric_query-1617999735
44
with Profile Metrics Query", "widgets": [{"definition": {"type": "timeseries",
55
"requests": [{"profile_metrics_query": {"compute": {"aggregation": "sum", "facet":
66
"@prof_core_cpu_cores"}, "search": {"query": "runtime:jvm"}, "group_by": [{"facet":
@@ -14,42 +14,38 @@ interactions:
1414
Dd-Operation-Id:
1515
- CreateDashboard
1616
User-Agent:
17-
- datadog-api-client-python/1.0.0b6.dev47+dirty (python 3.9.0; os Darwin; arch
18-
x86_64)
17+
- datadog-api-client-python/1.0.0b8.dev29 (python 3.8.8; os Darwin; arch x86_64)
1918
method: POST
2019
uri: https://api.datadoghq.com/api/v1/dashboard
2120
response:
2221
body:
23-
string: '{"notify_list":null,"description":null,"author_name":null,"template_variables":null,"is_read_only":false,"id":"5cv-nzz-3h5","title":"datadog-api-client-python-test_create_a_new_dashboard_with_a_profile_metric_query-1613391769.949769
24-
with Profile Metrics Query","url":"/dashboard/5cv-nzz-3h5/datadog-api-client-python-testcreateanewdashboardwithaprofilemetricquery-1613391","created_at":"2021-02-15T12:22:50.516001+00:00","modified_at":"2021-02-15T12:22:50.516001+00:00","author_handle":"[email protected]","widgets":[{"definition":{"requests":[{"profile_metrics_query":{"search":{"query":"runtime:jvm"},"group_by":[{"facet":"service","sort":{"facet":"@prof_core_cpu_cores","aggregation":"sum","order":"desc"},"limit":10}],"compute":{"facet":"@prof_core_cpu_cores","aggregation":"sum"}}}],"type":"timeseries"},"id":83318320383855}],"layout_type":"ordered"}'
22+
string: '{"notify_list":null,"description":null,"author_name":null,"template_variables":null,"is_read_only":false,"id":"wkx-vhy-96m","title":"Test-Create_a_new_dashboard_with_a_profile_metric_query-1617999735
23+
with Profile Metrics Query","url":"/dashboard/wkx-vhy-96m/test-createanewdashboardwithaprofilemetricquery-1617999735-with-profile-metrics","created_at":"2021-04-09T20:22:16.068974+00:00","modified_at":"2021-04-09T20:22:16.068974+00:00","author_handle":"[email protected]","widgets":[{"definition":{"requests":[{"profile_metrics_query":{"search":{"query":"runtime:jvm"},"group_by":[{"facet":"service","sort":{"facet":"@prof_core_cpu_cores","aggregation":"sum","order":"desc"},"limit":10}],"compute":{"facet":"@prof_core_cpu_cores","aggregation":"sum"}}}],"type":"timeseries"},"id":3620343832605725}],"layout_type":"ordered"}'
2524
headers:
2625
Connection:
2726
- keep-alive
2827
Content-Length:
29-
- '856'
28+
- '824'
3029
Content-Type:
3130
- application/json
3231
Date:
33-
- Mon, 15 Feb 2021 12:22:50 GMT
32+
- Fri, 09 Apr 2021 20:22:16 GMT
3433
cache-control:
3534
- no-cache
3635
content-security-policy:
3736
- frame-ancestors 'self'; report-uri https://api.datadoghq.com/csp-report
3837
pragma:
3938
- no-cache
40-
set-cookie:
41-
- DD-PSHARD=233; Max-Age=604800; Path=/; expires=Mon, 22-Feb-2021 12:22:50 GMT;
42-
secure; HttpOnly
4339
strict-transport-security:
4440
- max-age=15724800;
4541
vary:
4642
- Accept-Encoding
4743
x-content-type-options:
4844
- nosniff
4945
x-dd-debug:
50-
- fIO2C4qGDheGHy4YbS+r3a3CXbh4cbRo7roILOimQyiHGjQdOat0cIpWCkupM1uX
46+
- 2328yjLSqI4XmR1pVqrPRR/SFcQsbafjEpPmZx7/3PfxUK1nJQQsX+wrMelyVyj+
5147
x-dd-version:
52-
- '35.3909333'
48+
- '35.4280781'
5349
x-frame-options:
5450
- SAMEORIGIN
5551
status:
@@ -65,13 +61,12 @@ interactions:
6561
Dd-Operation-Id:
6662
- DeleteDashboard
6763
User-Agent:
68-
- datadog-api-client-python/1.0.0b6.dev47+dirty (python 3.9.0; os Darwin; arch
69-
x86_64)
64+
- datadog-api-client-python/1.0.0b8.dev29 (python 3.8.8; os Darwin; arch x86_64)
7065
method: DELETE
71-
uri: https://api.datadoghq.com/api/v1/dashboard/5cv-nzz-3h5
66+
uri: https://api.datadoghq.com/api/v1/dashboard/wkx-vhy-96m
7267
response:
7368
body:
74-
string: '{"deleted_dashboard_id":"5cv-nzz-3h5"}'
69+
string: '{"deleted_dashboard_id":"wkx-vhy-96m"}'
7570
headers:
7671
Connection:
7772
- keep-alive
@@ -80,26 +75,23 @@ interactions:
8075
Content-Type:
8176
- application/json
8277
Date:
83-
- Mon, 15 Feb 2021 12:22:50 GMT
78+
- Fri, 09 Apr 2021 20:22:16 GMT
8479
cache-control:
8580
- no-cache
8681
content-security-policy:
8782
- frame-ancestors 'self'; report-uri https://api.datadoghq.com/csp-report
8883
pragma:
8984
- no-cache
90-
set-cookie:
91-
- DD-PSHARD=233; Max-Age=604800; Path=/; expires=Mon, 22-Feb-2021 12:22:50 GMT;
92-
secure; HttpOnly
9385
strict-transport-security:
9486
- max-age=15724800;
9587
vary:
9688
- Accept-Encoding
9789
x-content-type-options:
9890
- nosniff
9991
x-dd-debug:
100-
- S1wfaMZOKGT/IoMw6fqAwAwGWo2vQ44sjF3YzuETnQfxZO2T5eJbs0aX3UKb9Dwu
92+
- l4HFlaRP3QwYSqoGKhzbYfv7zgkK63HIRR7YkyVYZspq0lGjjTBwoK8V/alf+XYt
10193
x-dd-version:
102-
- '35.3909333'
94+
- '35.4280781'
10395
x-frame-options:
10496
- SAMEORIGIN
10597
status:
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2021-03-31T12:30:35.623828+00:00
1+
2021-04-09T22:22:14.553384+02:00

tests/v1/cassettes/test_scenarios/test_create_a_new_dashboard_with_timeseries_widget_containing_style_attributes.yaml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
interactions:
22
- request:
3-
body: '{"layout_type": "ordered", "title": "datadog-api-client-python-test_create_a_new_dashboard_with_timeseries_widget_containing_style_attributes-1617193835.623828
3+
body: '{"layout_type": "ordered", "title": "Test-Create_a_new_dashboard_with_timeseries_widget_containing_style_attributes-1617999735
44
with timeseries widget", "widgets": [{"definition": {"type": "timeseries", "requests":
55
[{"q": "sum:trace.test.errors{env:prod,service:datadog-api-spec} by {resource_name}.as_count()",
66
"on_right_yaxis": false, "style": {"palette": "warm", "line_type": "solid",
@@ -13,23 +13,23 @@ interactions:
1313
Dd-Operation-Id:
1414
- CreateDashboard
1515
User-Agent:
16-
- datadog-api-client-python/0.1.dev287 (python 3.9.2; os Linux; arch x86_64)
16+
- datadog-api-client-python/1.0.0b8.dev29 (python 3.8.8; os Darwin; arch x86_64)
1717
method: POST
1818
uri: https://api.datadoghq.com/api/v1/dashboard
1919
response:
2020
body:
21-
string: '{"notify_list":null,"description":null,"author_name":"CI Account","template_variables":null,"is_read_only":false,"id":"trw-iyd-udn","title":"datadog-api-client-python-test_create_a_new_dashboard_with_timeseries_widget_containing_style_attributes-1617193835.623828
22-
with timeseries widget","url":"/dashboard/trw-iyd-udn/datadog-api-client-python-testcreateanewdashboardwithtimeserieswidgetcontainings","created_at":"2021-03-31T12:30:35.953532+00:00","modified_at":"2021-03-31T12:30:35.953532+00:00","author_handle":"9919ec9b-ebc7-49ee-8dc8-03626e717cca","widgets":[{"definition":{"requests":[{"q":"sum:trace.test.errors{env:prod,service:datadog-api-spec}
23-
by {resource_name}.as_count()","on_right_yaxis":false,"style":{"line_width":"normal","palette":"warm","line_type":"solid"},"display_type":"bars"}],"type":"timeseries"},"id":2527848781153118}],"layout_type":"ordered"}'
21+
string: '{"notify_list":null,"description":null,"author_name":null,"template_variables":null,"is_read_only":false,"id":"3qq-2ni-bq8","title":"Test-Create_a_new_dashboard_with_timeseries_widget_containing_style_attributes-1617999735
22+
with timeseries widget","url":"/dashboard/3qq-2ni-bq8/test-createanewdashboardwithtimeserieswidgetcontainingstyleattributes-1617999735","created_at":"2021-04-09T20:22:15.139084+00:00","modified_at":"2021-04-09T20:22:15.139084+00:00","author_handle":"[email protected]","widgets":[{"definition":{"requests":[{"q":"sum:trace.test.errors{env:prod,service:datadog-api-spec}
23+
by {resource_name}.as_count()","on_right_yaxis":false,"style":{"line_width":"normal","palette":"warm","line_type":"solid"},"display_type":"bars"}],"type":"timeseries"},"id":497246117413773}],"layout_type":"ordered"}'
2424
headers:
2525
Connection:
2626
- keep-alive
2727
Content-Length:
28-
- '869'
28+
- '809'
2929
Content-Type:
3030
- application/json
3131
Date:
32-
- Wed, 31 Mar 2021 12:30:35 GMT
32+
- Fri, 09 Apr 2021 20:22:15 GMT
3333
cache-control:
3434
- no-cache
3535
content-security-policy:
@@ -43,9 +43,9 @@ interactions:
4343
x-content-type-options:
4444
- nosniff
4545
x-dd-debug:
46-
- nLnnBNvlCFDECRnZvzDb0z4sAO35G+IMidcAs8vrCKyjvsKWE8Yd9S3n6OjZ1qRN
46+
- tpRCH6w417YjBovRJ8VmtuXmNONVYiRp2c8d2AxjPdGBn8PCtgG4vAztrx3qUZAN
4747
x-dd-version:
48-
- '35.4208184'
48+
- '35.4280781'
4949
x-frame-options:
5050
- SAMEORIGIN
5151
status:
@@ -61,12 +61,12 @@ interactions:
6161
Dd-Operation-Id:
6262
- DeleteDashboard
6363
User-Agent:
64-
- datadog-api-client-python/0.1.dev287 (python 3.9.2; os Linux; arch x86_64)
64+
- datadog-api-client-python/1.0.0b8.dev29 (python 3.8.8; os Darwin; arch x86_64)
6565
method: DELETE
66-
uri: https://api.datadoghq.com/api/v1/dashboard/trw-iyd-udn
66+
uri: https://api.datadoghq.com/api/v1/dashboard/3qq-2ni-bq8
6767
response:
6868
body:
69-
string: '{"deleted_dashboard_id":"trw-iyd-udn"}'
69+
string: '{"deleted_dashboard_id":"3qq-2ni-bq8"}'
7070
headers:
7171
Connection:
7272
- keep-alive
@@ -75,7 +75,7 @@ interactions:
7575
Content-Type:
7676
- application/json
7777
Date:
78-
- Wed, 31 Mar 2021 12:30:36 GMT
78+
- Fri, 09 Apr 2021 20:22:15 GMT
7979
cache-control:
8080
- no-cache
8181
content-security-policy:
@@ -91,7 +91,7 @@ interactions:
9191
x-dd-debug:
9292
- HbtaOKlJ6OCrx9tMXO6ivMTrEM+g0c93HDp08trmOmgdHozC5J+vn10F0H4WPjCU
9393
x-dd-version:
94-
- '35.4208184'
94+
- '35.4280781'
9595
x-frame-options:
9696
- SAMEORIGIN
9797
status:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2021-04-09T16:17:02.955456+02:00
1+
2021-04-12T17:31:12.619158+02:00

tests/v1/cassettes/test_scenarios/test_delete_an_slo_returns_not_found_response.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@ interactions:
99
Dd-Operation-Id:
1010
- DeleteSlo
1111
User-Agent:
12-
- datadog-api-client-python/1.0.0b8.dev35+dirty (python 3.7.9; os Darwin; arch
12+
- datadog-api-client-python/1.0.0b8.dev35+dirty (python 3.8.8; os Darwin; arch
1313
x86_64)
1414
method: DELETE
15-
uri: https://api.datadoghq.com/api/v1/slo/datadogapiclientpythontestdeleteansloreturnsnotfoundresponse1617977822955456
15+
uri: https://api.datadoghq.com/api/v1/slo/testdeleteansloreturnsnotfoundresponse1618241473
1616
response:
1717
body:
18-
string: '{"errors": ["SLO not found: datadogapiclientpythontestdeleteansloreturnsnotfoundresponse1617977822955456
18+
string: '{"errors": ["SLO not found: testdeleteansloreturnsnotfoundresponse1618241473
1919
not found"]}'
2020
headers:
2121
Connection:
2222
- keep-alive
2323
Content-Length:
24-
- '117'
24+
- '89'
2525
Content-Type:
2626
- application/json
2727
Date:
28-
- Fri, 09 Apr 2021 14:17:03 GMT
28+
- Mon, 12 Apr 2021 15:31:13 GMT
2929
cache-control:
3030
- no-cache
3131
content-security-policy:
@@ -39,7 +39,7 @@ interactions:
3939
x-content-type-options:
4040
- nosniff
4141
x-dd-version:
42-
- '35.4276613'
42+
- '35.4290400'
4343
x-frame-options:
4444
- SAMEORIGIN
4545
x-ratelimit-limit:
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2021-01-11T12:02:02.232318-05:00
1+
2021-04-09T22:22:10.426550+02:00

tests/v1/cassettes/test_scenarios/test_get_a_monitors_details_returns_monitor_not_found_error_response.yaml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,21 @@ interactions:
99
Dd-Operation-Id:
1010
- GetMonitor
1111
User-Agent:
12-
- datadog-api-client-python/1.0.0b5.dev24+dirty (python 3.7.9; os Darwin; arch
13-
x86_64)
12+
- datadog-api-client-python/1.0.0b8.dev29 (python 3.8.8; os Darwin; arch x86_64)
1413
method: GET
1514
uri: https://api.datadoghq.com/api/v1/monitor/12345
1615
response:
1716
body:
18-
string: '{"errors":["Monitor not found"]}'
17+
string: '{"errors": ["Monitor not found"]}'
1918
headers:
2019
Connection:
2120
- keep-alive
2221
Content-Length:
23-
- '32'
22+
- '33'
2423
Content-Type:
2524
- application/json
2625
Date:
27-
- Mon, 11 Jan 2021 17:06:26 GMT
26+
- Fri, 09 Apr 2021 20:22:11 GMT
2827
cache-control:
2928
- no-cache
3029
content-security-policy:
@@ -38,7 +37,7 @@ interactions:
3837
x-content-type-options:
3938
- nosniff
4039
x-dd-version:
41-
- '35.3679038'
40+
- '35.4280781'
4241
x-frame-options:
4342
- SAMEORIGIN
4443
x-ratelimit-limit:
@@ -48,7 +47,7 @@ interactions:
4847
x-ratelimit-remaining:
4948
- '2999'
5049
x-ratelimit-reset:
51-
- '4'
50+
- '10'
5251
status:
5352
code: 404
5453
message: Not Found

0 commit comments

Comments
 (0)