Skip to content

Commit 0dcb5e9

Browse files
committed
Merge remote-tracking branch 'github/main' into feat/hide-code-references-querying-under-flag
2 parents 5c513dd + aafc84b commit 0dcb5e9

File tree

250 files changed

+3305
-2502
lines changed

Some content is hidden

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

250 files changed

+3305
-2502
lines changed

api/tests/integration/api_keys/test_viewset.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
from organisations.models import Organisation
66

77

8-
def test_create_master_api_key_returns_key_in_response(admin_client, organisation): # type: ignore[no-untyped-def] # noqa: FT003
8+
def test_create_master_api_key__valid_data__returns_key_in_response( # type: ignore[no-untyped-def]
9+
admin_client, organisation
10+
):
911
# Given
1012
url = reverse(
1113
"api-v1:organisations:organisation-master-api-keys-list",
@@ -22,7 +24,7 @@ def test_create_master_api_key_returns_key_in_response(admin_client, organisatio
2224
assert response.json()["is_admin"] is True
2325

2426

25-
def test_creating_non_admin_master_api_key_without_rbac_returns_400( # type: ignore[no-untyped-def] # noqa: FT003
27+
def test_create_master_api_key__non_admin_without_rbac__returns_400( # type: ignore[no-untyped-def]
2628
admin_client, organisation, settings
2729
):
2830
# Given
@@ -44,7 +46,9 @@ def test_creating_non_admin_master_api_key_without_rbac_returns_400( # type: ig
4446
]
4547

4648

47-
def test_delete_master_api_key(admin_client, organisation, admin_master_api_key_prefix): # type: ignore[no-untyped-def] # noqa: E501,FT003
49+
def test_delete_master_api_key__existing_key__returns_204( # type: ignore[no-untyped-def]
50+
admin_client, organisation, admin_master_api_key_prefix
51+
): # noqa: E501
4852
# Given
4953
url = reverse(
5054
"api-v1:organisations:organisation-master-api-keys-detail",
@@ -58,7 +62,7 @@ def test_delete_master_api_key(admin_client, organisation, admin_master_api_key_
5862
assert response.status_code == status.HTTP_204_NO_CONTENT
5963

6064

61-
def test_list_master_api_keys( # noqa: FT003
65+
def test_list_master_api_keys__active_key_exists__returns_key(
6266
admin_client: APIClient,
6367
organisation: int,
6468
admin_master_api_key_prefix: str,
@@ -79,7 +83,7 @@ def test_list_master_api_keys( # noqa: FT003
7983
assert response.json()["results"][0]["has_expired"] is False
8084

8185

82-
def test_list_master_api_keys__when_expired( # noqa: FT003
86+
def test_list_master_api_keys__when_expired__returns_has_expired_true(
8387
admin_client: APIClient,
8488
organisation: Organisation,
8589
expired_api_key_prefix: str,
@@ -100,7 +104,7 @@ def test_list_master_api_keys__when_expired( # noqa: FT003
100104
assert response.json()["results"][0]["has_expired"] is True
101105

102106

103-
def test_retrieve_master_api_key( # type: ignore[no-untyped-def] # noqa: FT003
107+
def test_retrieve_master_api_key__existing_key__returns_key_details( # type: ignore[no-untyped-def]
104108
admin_client, organisation, admin_master_api_key_prefix
105109
):
106110
# Given
@@ -117,7 +121,7 @@ def test_retrieve_master_api_key( # type: ignore[no-untyped-def] # noqa: FT003
117121
assert response.json()["prefix"] == admin_master_api_key_prefix
118122

119123

120-
def test_update_master_api_key( # type: ignore[no-untyped-def] # noqa: FT003
124+
def test_update_master_api_key__rbac_installed__updates_fields( # type: ignore[no-untyped-def]
121125
admin_client, organisation, admin_master_api_key_prefix, settings
122126
):
123127
# Given
@@ -147,7 +151,7 @@ def test_update_master_api_key( # type: ignore[no-untyped-def] # noqa: FT003
147151
assert response.json()["is_admin"] is False
148152

149153

150-
def test_update_master_api_key_is_admin_returns_400_if_rbac_is_not_installed( # type: ignore[no-untyped-def] # noqa: FT003
154+
def test_update_master_api_key__rbac_not_installed__returns_400( # type: ignore[no-untyped-def]
151155
admin_client, organisation, admin_master_api_key_prefix, settings
152156
):
153157
# Given
@@ -175,7 +179,9 @@ def test_update_master_api_key_is_admin_returns_400_if_rbac_is_not_installed( #
175179
]
176180

177181

178-
def test_api_returns_403_if_user_is_not_the_org_admin(non_admin_client, organisation): # type: ignore[no-untyped-def] # noqa: FT003
182+
def test_list_master_api_keys__non_admin_user__returns_403( # type: ignore[no-untyped-def]
183+
non_admin_client, organisation
184+
):
179185
# Given
180186
url = reverse(
181187
"api-v1:organisations:organisation-master-api-keys-list",
@@ -188,7 +194,9 @@ def test_api_returns_403_if_user_is_not_the_org_admin(non_admin_client, organisa
188194
assert response.status_code == status.HTTP_403_FORBIDDEN
189195

190196

191-
def test_create_master_api_key_ignores_organisation_in_body(admin_client, organisation): # type: ignore[no-untyped-def] # noqa: E501,FT003
197+
def test_create_master_api_key__wrong_org_in_body__uses_url_org( # type: ignore[no-untyped-def]
198+
admin_client, organisation
199+
):
192200
# Given
193201
list_create_url = reverse(
194202
"api-v1:organisations:organisation-master-api-keys-list",
@@ -216,7 +224,7 @@ def test_create_master_api_key_ignores_organisation_in_body(admin_client, organi
216224
assert key.startswith(list_response_json["results"][0]["prefix"])
217225

218226

219-
def test_deleted_api_key_is_not_returned_in_list_and_cannot_be_used( # noqa: FT003
227+
def test_delete_master_api_key__after_deletion__not_listed_and_unusable(
220228
admin_client: APIClient,
221229
organisation: int,
222230
admin_master_api_key_client: APIClient,

api/tests/integration/app_analytics/test_influx_query_throttle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from rest_framework.test import APIClient
55

66

7-
def test_influx_data_endpoint_is_throttled( # noqa: FT003
7+
def test_influx_data_endpoint__rate_limit_exceeded__returns_throttled(
88
admin_client: APIClient,
99
organisation: int,
1010
mocker: MockerFixture,

api/tests/integration/audit/test_audit_logs.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,27 @@ def _subscription_metadata(mocker: MockerFixture) -> None:
2929
)
3030

3131

32-
def test_get_audit_logs_makes_expected_queries( # type: ignore[no-untyped-def] # noqa: FT003,FT004
32+
def test_list_audit_logs__with_project_filter__makes_expected_queries( # type: ignore[no-untyped-def]
3333
admin_client,
3434
project,
3535
environment,
3636
feature,
3737
feature_state,
3838
django_assert_num_queries,
3939
):
40+
# Given
4041
url = reverse("api-v1:audit-list")
4142

43+
# When
4244
with django_assert_num_queries(3):
4345
res = admin_client.get(url, {"project": project})
4446

47+
# Then
4548
assert res.status_code == status.HTTP_200_OK
4649
assert res.json()["count"] == 3
4750

4851

49-
def test_retrieve_audit_log_for_environment_change( # noqa: FT003,FT004
52+
def test_retrieve_audit_log__environment_change__includes_change_details(
5053
admin_client: APIClient,
5154
project: int,
5255
environment_api_key: str,
@@ -81,14 +84,16 @@ def test_retrieve_audit_log_for_environment_change( # noqa: FT003,FT004
8184
"api-v1:audit-detail", args=[environment_update_result["id"]]
8285
)
8386
retrieve_response = admin_client.get(retrieve_audit_log_url)
87+
88+
# Then
8489
retrieve_response_json = retrieve_response.json()
8590
assert len(retrieve_response_json["change_details"]) == 1
8691
assert retrieve_response_json["change_details"][0]["field"] == "name"
8792
assert retrieve_response_json["change_details"][0]["new"] == new_name
8893
assert retrieve_response_json["change_details"][0]["old"] == environment_name
8994

9095

91-
def test_retrieve_audit_log_for_feature_state_enabled_change( # noqa: FT003
96+
def test_retrieve_audit_log__feature_state_enabled_change__includes_change_details(
9297
admin_client: APIClient,
9398
environment_api_key: str,
9499
environment: int,
@@ -132,7 +137,7 @@ def test_retrieve_audit_log_for_feature_state_enabled_change( # noqa: FT003
132137
assert retrieve_response_json["change_details"][0]["old"] is False
133138

134139

135-
def test_creates_audit_log_for_feature_state_update( # noqa: FT003
140+
def test_create_audit_log_from_historical_record__feature_state_update__creates_correct_log(
136141
admin_client: APIClient,
137142
admin_user: FFAdminUser,
138143
environment_api_key: str,
@@ -170,7 +175,7 @@ def test_creates_audit_log_for_feature_state_update( # noqa: FT003
170175
("Asia/Tokyo", "Y年n月j日 H:i (T)", "2199年4月15日 21:30 (JST)"),
171176
],
172177
)
173-
def test_creates_audit_log_for_scheduled_feature_state_update( # noqa: FT003
178+
def test_create_audit_log_from_historical_record__scheduled_feature_state__includes_schedule_time(
174179
admin_client: APIClient,
175180
admin_user: FFAdminUser,
176181
django_datetime_format: str,
@@ -216,7 +221,7 @@ def test_creates_audit_log_for_scheduled_feature_state_update( # noqa: FT003
216221
)
217222

218223

219-
def test_retrieve_audit_log_for_feature_state_value_change( # noqa: FT003
224+
def test_retrieve_audit_log__feature_state_value_change__includes_change_details(
220225
admin_client: APIClient,
221226
environment_api_key: str,
222227
environment: int,
@@ -262,7 +267,7 @@ def test_retrieve_audit_log_for_feature_state_value_change( # noqa: FT003
262267
assert retrieve_response_json["change_details"][0]["old"] == default_feature_value
263268

264269

265-
def test_retrieve_audit_log_does_not_include_change_details_for_non_update( # noqa: FT003
270+
def test_retrieve_audit_log__non_update_record__returns_empty_change_details(
266271
admin_client: APIClient, project: int, environment: str
267272
) -> None:
268273
# Given
@@ -288,15 +293,15 @@ def test_retrieve_audit_log_does_not_include_change_details_for_non_update( # n
288293
assert retrieve_response.json()["change_details"] == []
289294

290295

291-
def test_retrieve_audit_log_includes_changes_when_segment_override_created_and_deleted_for_enabled_state( # noqa: FT003,FT004
296+
def test_retrieve_audit_log__segment_override_created_and_deleted__includes_change_details(
292297
admin_client: APIClient,
293298
project: int,
294299
feature: int,
295300
environment_api_key: str,
296301
environment: int,
297302
segment: int,
298303
) -> None:
299-
# First, let's create a segment override
304+
# Given - create a segment override
300305
data = {
301306
"feature_segment": {"segment": segment},
302307
"enabled": True,
@@ -316,7 +321,7 @@ def test_retrieve_audit_log_includes_changes_when_segment_override_created_and_d
316321
"feature_segment"
317322
]["id"]
318323

319-
# Now, that should have created an audit log, let's check
324+
# When - retrieve the audit log for the creation
320325
get_audit_logs_url = "%s?environment=%s" % (
321326
reverse("api-v1:audit-list"),
322327
environment,
@@ -340,7 +345,7 @@ def test_retrieve_audit_log_includes_changes_when_segment_override_created_and_d
340345
get_create_override_audit_log_detail_response.json()
341346
)
342347

343-
# now let's check that we have some information about the change
348+
# Then - the creation audit log has the expected change details
344349
assert create_override_audit_log_details["change_type"] == "CREATE"
345350
assert create_override_audit_log_details["change_details"] == [
346351
{"field": "enabled", "old": None, "new": True},
@@ -380,7 +385,7 @@ def test_retrieve_audit_log_includes_changes_when_segment_override_created_and_d
380385
assert delete_override_audit_log_details["change_details"] == []
381386

382387

383-
def test_retrieve_audit_log_includes_changes_when_segment_override_created_for_feature_value( # noqa: FT003,FT004
388+
def test_retrieve_audit_log__segment_override_created_for_feature_value__includes_change_details(
384389
admin_client: APIClient,
385390
project: int,
386391
feature: int,
@@ -389,7 +394,7 @@ def test_retrieve_audit_log_includes_changes_when_segment_override_created_for_f
389394
environment: int,
390395
segment: int,
391396
) -> None:
392-
# First, let's create a segment override
397+
# Given - create a segment override with a feature value
393398
data = {
394399
"feature_segment": {"segment": segment},
395400
"feature_state_value": {"value_type": "unicode", "string_value": "foo"},
@@ -405,7 +410,7 @@ def test_retrieve_audit_log_includes_changes_when_segment_override_created_for_f
405410
)
406411
assert create_segment_override_response.status_code == status.HTTP_201_CREATED
407412

408-
# Now, that should have created an audit log, let's check
413+
# When - retrieve the audit log detail
409414
get_audit_logs_url = "%s?environment=%s" % (
410415
reverse("api-v1:audit-list"),
411416
environment,
@@ -427,7 +432,7 @@ def test_retrieve_audit_log_includes_changes_when_segment_override_created_for_f
427432
assert get_audit_log_detail_response.status_code == status.HTTP_200_OK
428433
audit_log_details = get_audit_log_detail_response.json()
429434

430-
# now let's check that we have some information about the change
435+
# Then - the audit log contains the expected change details
431436
# This is treated as an update since the FeatureStateValue is created
432437
# automatically when the FeatureState is created, and then updated
433438
# with the value in the request.

api/tests/integration/core/test_commands.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def test_bootstrap__empty_instance__creates_expected(
9797
)
9898

9999

100-
def test_bootstrap__empty_instance__cli_overrides__creates_expected( # noqa: FT003
100+
def test_bootstrap__cli_overrides_provided__creates_expected_entities(
101101
settings: SettingsWrapper,
102102
capsys: pytest.CaptureFixture, # type: ignore[type-arg]
103103
) -> None:
@@ -156,9 +156,12 @@ def test_bootstrap__used_instance__skip_expected(
156156
[*Project.objects.all()] == expected_projects
157157

158158

159-
def test_bootstrap__allow_admin_initiation_via_cli__false_by_default__skip_expected( # noqa: FT003,FT004
159+
def test_bootstrap__cli_initiation_disabled__skips_creation(
160160
settings: SettingsWrapper,
161161
) -> None:
162+
# Given
163+
# settings.ALLOW_ADMIN_INITIATION_VIA_CLI is False by default
164+
162165
# When
163166
call_command("bootstrap")
164167

api/tests/integration/core/test_user_rate_throttle.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,23 @@
1212
"client",
1313
[(lazy_fixture("admin_master_api_key_client")), (lazy_fixture("admin_client"))],
1414
)
15-
def test_user_throttle_can_throttle_admin_endpoints( # noqa: FT003,FT004
15+
def test_user_throttle__admin_endpoint_exceeds_rate_limit__returns_too_many_requests(
1616
client: APIClient, project: int, mocker: MockerFixture, reset_cache: None
1717
) -> None:
1818
# Given
1919
mocker.patch("core.throttling.UserRateThrottle.get_rate", return_value="1/minute")
20-
2120
url = reverse("api-v1:projects:project-list")
2221

23-
# Then - first request should be successful
22+
# When - first request should be successful
2423
response = client.get(url, content_type="application/json")
2524
assert response.status_code == status.HTTP_200_OK
2625

27-
# Second request should be throttled
26+
# Then - second request should be throttled
2827
response = client.get(url, content_type="application/json")
2928
assert response.status_code == status.HTTP_429_TOO_MANY_REQUESTS
3029

3130

32-
def test_get_flags_is_not_throttled_by_user_throttle( # noqa: FT003
31+
def test_get_flags__user_throttle_enabled__is_not_throttled(
3332
sdk_client: APIClient,
3433
environment: int,
3534
environment_api_key: str,
@@ -48,7 +47,7 @@ def test_get_flags_is_not_throttled_by_user_throttle( # noqa: FT003
4847
assert response.status_code == status.HTTP_200_OK
4948

5049

51-
def test_get_environment_document_is_not_throttled_by_user_throttle( # type: ignore[no-untyped-def] # noqa: FT003
50+
def test_get_environment_document__user_throttle_enabled__is_not_throttled( # type: ignore[no-untyped-def]
5251
server_side_sdk_client: APIClient,
5352
environment: int,
5453
environment_api_key: str,
@@ -67,7 +66,7 @@ def test_get_environment_document_is_not_throttled_by_user_throttle( # type: ig
6766
assert response.status_code == status.HTTP_200_OK
6867

6968

70-
def test_get_identities_is_not_throttled_by_user_throttle( # type: ignore[no-untyped-def] # noqa: FT003
69+
def test_get_identities__user_throttle_enabled__is_not_throttled( # type: ignore[no-untyped-def]
7170
environment: int,
7271
sdk_client: APIClient,
7372
mocker: MockerFixture,
@@ -88,7 +87,7 @@ def test_get_identities_is_not_throttled_by_user_throttle( # type: ignore[no-un
8887
assert response.status_code == status.HTTP_200_OK
8988

9089

91-
def test_set_trait_for_an_identity_is_not_throttled_by_user_throttle( # type: ignore[no-untyped-def] # noqa: FT003
90+
def test_set_trait__user_throttle_enabled__is_not_throttled( # type: ignore[no-untyped-def]
9291
environment: int,
9392
server_side_sdk_client: APIClient,
9493
identity: int,
@@ -114,7 +113,7 @@ def test_set_trait_for_an_identity_is_not_throttled_by_user_throttle( # type: i
114113
assert res.status_code == status.HTTP_200_OK
115114

116115

117-
def test_sdk_analytics_is_not_throttled_by_user_throttle( # type: ignore[no-untyped-def] # noqa: FT003
116+
def test_sdk_analytics__user_throttle_enabled__is_not_throttled( # type: ignore[no-untyped-def]
118117
mocker: MockerFixture, environment: int, sdk_client: APIClient
119118
):
120119
# Given
@@ -128,7 +127,7 @@ def test_sdk_analytics_is_not_throttled_by_user_throttle( # type: ignore[no-unt
128127
assert response.status_code == status.HTTP_200_OK
129128

130129

131-
def test_self_hosted_telemetry_view_is_not_throttled_by_user_throttle( # type: ignore[no-untyped-def] # noqa: FT003
130+
def test_self_hosted_telemetry__user_throttle_enabled__is_not_throttled( # type: ignore[no-untyped-def]
132131
mocker: MockerFixture,
133132
):
134133
# Given

0 commit comments

Comments
 (0)