Skip to content

Commit 8c994f5

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
[OMG-1253] Add BDD test coverage for CreateTeamMembership (#3368)
Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com>
1 parent 17c7f82 commit 8c994f5

6 files changed

+257
-17
lines changed

examples/v2/teams/CreateTeamMembership.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,34 @@
22
Add a user to a team returns "Represents a user's association to a team" response
33
"""
44

5+
from os import environ
56
from datadog_api_client import ApiClient, Configuration
67
from datadog_api_client.v2.api.teams_api import TeamsApi
7-
from datadog_api_client.v2.model.relationship_to_user_team_team import RelationshipToUserTeamTeam
8-
from datadog_api_client.v2.model.relationship_to_user_team_team_data import RelationshipToUserTeamTeamData
98
from datadog_api_client.v2.model.relationship_to_user_team_user import RelationshipToUserTeamUser
109
from datadog_api_client.v2.model.relationship_to_user_team_user_data import RelationshipToUserTeamUserData
1110
from datadog_api_client.v2.model.user_team_attributes import UserTeamAttributes
1211
from datadog_api_client.v2.model.user_team_create import UserTeamCreate
1312
from datadog_api_client.v2.model.user_team_relationships import UserTeamRelationships
1413
from datadog_api_client.v2.model.user_team_request import UserTeamRequest
1514
from datadog_api_client.v2.model.user_team_role import UserTeamRole
16-
from datadog_api_client.v2.model.user_team_team_type import UserTeamTeamType
1715
from datadog_api_client.v2.model.user_team_type import UserTeamType
1816
from datadog_api_client.v2.model.user_team_user_type import UserTeamUserType
1917

18+
# there is a valid "dd_team" in the system
19+
DD_TEAM_DATA_ID = environ["DD_TEAM_DATA_ID"]
20+
21+
# there is a valid "user" in the system
22+
USER_DATA_ID = environ["USER_DATA_ID"]
23+
2024
body = UserTeamRequest(
2125
data=UserTeamCreate(
2226
attributes=UserTeamAttributes(
2327
role=UserTeamRole.ADMIN,
2428
),
2529
relationships=UserTeamRelationships(
26-
team=RelationshipToUserTeamTeam(
27-
data=RelationshipToUserTeamTeamData(
28-
id="d7e15d9d-d346-43da-81d8-3d9e71d9a5e9",
29-
type=UserTeamTeamType.TEAM,
30-
),
31-
),
3230
user=RelationshipToUserTeamUser(
3331
data=RelationshipToUserTeamUserData(
34-
id="b8626d7e-cedd-11eb-abf5-da7ad0900001",
32+
id=USER_DATA_ID,
3533
type=UserTeamUserType.USERS,
3634
),
3735
),
@@ -43,6 +41,6 @@
4341
configuration = Configuration()
4442
with ApiClient(configuration) as api_client:
4543
api_instance = TeamsApi(api_client)
46-
response = api_instance.create_team_membership(team_id="team_id", body=body)
44+
response = api_instance.create_team_membership(team_id=DD_TEAM_DATA_ID, body=body)
4745

4846
print(response)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2026-03-31T14:58:05.044Z
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
interactions:
2+
- request:
3+
body: '{"data":{"attributes":{"handle":"test-handle-22e42ce95626a92a","name":"test-name-22e42ce95626a92a"},"type":"team"}}'
4+
headers:
5+
accept:
6+
- application/json
7+
content-type:
8+
- application/json
9+
method: POST
10+
uri: https://api.datadoghq.com/api/v2/team
11+
response:
12+
body:
13+
string: '{"data":{"id":"abc7c612-d3a1-4147-bcfa-f28b4af43d33","type":"team","attributes":{"avatar":null,"banner":10,"created_at":"2026-03-31T14:58:05.503733+00:00","description":null,"handle":"test-handle-22e42ce95626a92a","hidden_modules":null,"is_managed":false,"link_count":0,"modified_at":"2026-03-31T14:58:05.503733+00:00","name":"test-name-22e42ce95626a92a","summary":null,"user_count":0,"visible_modules":null},"relationships":{"team_links":{"data":[],"links":{"related":"/api/v2/team/abc7c612-d3a1-4147-bcfa-f28b4af43d33/links"}},"user_team_permissions":{"data":null,"links":{"related":"/api/v2/team/abc7c612-d3a1-4147-bcfa-f28b4af43d33/permission-settings"}}}}}'
14+
headers:
15+
content-type:
16+
- application/vnd.api+json
17+
status:
18+
code: 201
19+
message: Created
20+
- request:
21+
body: '{"data":{"attributes":{"email":"Test-Add_a_user_to_a_team_returns_API_error_response_response-1774969085@datadoghq.com","title":"user
22+
title"},"type":"users"}}'
23+
headers:
24+
accept:
25+
- application/json
26+
content-type:
27+
- application/json
28+
method: POST
29+
uri: https://api.datadoghq.com/api/v2/users
30+
response:
31+
body:
32+
string: '{"data": {"type": "users", "id": "825c5f4c-585c-494a-aade-60f1e1aa189b",
33+
"attributes": {"name": null, "handle": "test-add_a_user_to_a_team_returns_api_error_response_response-1774969085@datadoghq.com",
34+
"created_at": "2026-03-31T14:58:06.030754+00:00", "modified_at": "2026-03-31T14:58:06.030754+00:00",
35+
"email": "test-add_a_user_to_a_team_returns_api_error_response_response-1774969085@datadoghq.com",
36+
"icon": "https://secure.gravatar.com/avatar/53ba6f826ef9a49acaeec55d1bcc1c47?s=48&d=retro",
37+
"title": "user title", "verified": false, "service_account": false, "disabled":
38+
false, "allowed_login_methods": [], "status": "Pending", "last_login_time":
39+
null}, "relationships": {"roles": {"data": []}, "org": {"data": {"type": "orgs",
40+
"id": "4dee724d-00cc-11ea-a77b-570c9d03c6c5"}}}}}'
41+
headers:
42+
content-type:
43+
- application/json
44+
status:
45+
code: 201
46+
message: Created
47+
- request:
48+
body: '{"data":{"attributes":{"role":"admin"},"relationships":{"user":{"data":{"id":"825c5f4c-585c-494a-aade-60f1e1aa189b","type":"users"}}},"type":"team_memberships"}}'
49+
headers:
50+
accept:
51+
- application/json
52+
content-type:
53+
- application/json
54+
method: POST
55+
uri: https://api.datadoghq.com/api/v2/team/abc7c612-d3a1-4147-bcfa-f28b4af43d33/memberships
56+
response:
57+
body:
58+
string: '{"data":{"id":"TeamMembership-abc7c612-d3a1-4147-bcfa-f28b4af43d33-66215044","type":"team_memberships","attributes":{"provisioned_by":null,"provisioned_by_id":"a1d5ff5a-c6dd-11f0-9cb6-06640ca27ad4","role":"admin"},"relationships":{"user":{"data":{"id":"825c5f4c-585c-494a-aade-60f1e1aa189b","type":"users"}}}},"included":[{"id":"825c5f4c-585c-494a-aade-60f1e1aa189b","type":"users","attributes":{"disabled":false,"email":"test-add_a_user_to_a_team_returns_api_error_response_response-1774969085@datadoghq.com","handle":"test-add_a_user_to_a_team_returns_api_error_response_response-1774969085@datadoghq.com","icon":"https://secure.gravatar.com/avatar/53ba6f826ef9a49acaeec55d1bcc1c47?d=retro\u0026s=48","name":null,"service_account":false,"status":"Pending"}}]}'
59+
headers:
60+
content-type:
61+
- application/vnd.api+json
62+
status:
63+
code: 200
64+
message: OK
65+
- request:
66+
body: '{"data":{"attributes":{"role":"admin"},"relationships":{"user":{"data":{"id":"825c5f4c-585c-494a-aade-60f1e1aa189b","type":"users"}}},"type":"team_memberships"}}'
67+
headers:
68+
accept:
69+
- application/json
70+
content-type:
71+
- application/json
72+
method: POST
73+
uri: https://api.datadoghq.com/api/v2/team/abc7c612-d3a1-4147-bcfa-f28b4af43d33/memberships
74+
response:
75+
body:
76+
string: '{"errors":[{"status":"409","title":"Conflict","detail":"users already
77+
present on the team [825c5f4c-585c-494a-aade-60f1e1aa189b]"}]}'
78+
headers:
79+
content-type:
80+
- application/vnd.api+json
81+
status:
82+
code: 409
83+
message: Conflict
84+
- request:
85+
body: null
86+
headers:
87+
accept:
88+
- '*/*'
89+
method: DELETE
90+
uri: https://api.datadoghq.com/api/v2/team/abc7c612-d3a1-4147-bcfa-f28b4af43d33/memberships/825c5f4c-585c-494a-aade-60f1e1aa189b
91+
response:
92+
body:
93+
string: ''
94+
headers: {}
95+
status:
96+
code: 204
97+
message: No Content
98+
- request:
99+
body: null
100+
headers:
101+
accept:
102+
- '*/*'
103+
method: DELETE
104+
uri: https://api.datadoghq.com/api/v2/users/825c5f4c-585c-494a-aade-60f1e1aa189b
105+
response:
106+
body:
107+
string: ''
108+
headers: {}
109+
status:
110+
code: 204
111+
message: No Content
112+
- request:
113+
body: null
114+
headers:
115+
accept:
116+
- '*/*'
117+
method: DELETE
118+
uri: https://api.datadoghq.com/api/v2/team/abc7c612-d3a1-4147-bcfa-f28b4af43d33
119+
response:
120+
body:
121+
string: ''
122+
headers: {}
123+
status:
124+
code: 204
125+
message: No Content
126+
version: 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2026-03-31T14:57:49.739Z
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
interactions:
2+
- request:
3+
body: '{"data":{"attributes":{"handle":"test-handle-3170c6f6f5b25b4d","name":"test-name-3170c6f6f5b25b4d"},"type":"team"}}'
4+
headers:
5+
accept:
6+
- application/json
7+
content-type:
8+
- application/json
9+
method: POST
10+
uri: https://api.datadoghq.com/api/v2/team
11+
response:
12+
body:
13+
string: '{"data":{"id":"95ac9e78-0a56-4a6a-9e5e-21580dc141cc","type":"team","attributes":{"avatar":null,"banner":9,"created_at":"2026-03-31T14:57:54.888553+00:00","description":null,"handle":"test-handle-3170c6f6f5b25b4d","hidden_modules":null,"is_managed":false,"link_count":0,"modified_at":"2026-03-31T14:57:54.888553+00:00","name":"test-name-3170c6f6f5b25b4d","summary":null,"user_count":0,"visible_modules":null},"relationships":{"team_links":{"data":[],"links":{"related":"/api/v2/team/95ac9e78-0a56-4a6a-9e5e-21580dc141cc/links"}},"user_team_permissions":{"data":null,"links":{"related":"/api/v2/team/95ac9e78-0a56-4a6a-9e5e-21580dc141cc/permission-settings"}}}}}'
14+
headers:
15+
content-type:
16+
- application/vnd.api+json
17+
status:
18+
code: 201
19+
message: Created
20+
- request:
21+
body: '{"data":{"attributes":{"email":"Test-Add_a_user_to_a_team_returns_Represents_a_user_s_association_to_a_team_response-1774969069@datadoghq.com","title":"user
22+
title"},"type":"users"}}'
23+
headers:
24+
accept:
25+
- application/json
26+
content-type:
27+
- application/json
28+
method: POST
29+
uri: https://api.datadoghq.com/api/v2/users
30+
response:
31+
body:
32+
string: '{"data": {"type": "users", "id": "ebb17d15-5e46-4440-856f-75710cbbce4b",
33+
"attributes": {"name": null, "handle": "test-add_a_user_to_a_team_returns_represents_a_user_s_association_to_a_team_response-1774969069@datadoghq.com",
34+
"created_at": "2026-03-31T14:57:55.106406+00:00", "modified_at": "2026-03-31T14:57:55.106406+00:00",
35+
"email": "test-add_a_user_to_a_team_returns_represents_a_user_s_association_to_a_team_response-1774969069@datadoghq.com",
36+
"icon": "https://secure.gravatar.com/avatar/52a30c814f85968a9d363cc103840284?s=48&d=retro",
37+
"title": "user title", "verified": false, "service_account": false, "disabled":
38+
false, "allowed_login_methods": [], "status": "Pending", "last_login_time":
39+
null}, "relationships": {"roles": {"data": []}, "org": {"data": {"type": "orgs",
40+
"id": "4dee724d-00cc-11ea-a77b-570c9d03c6c5"}}}}}'
41+
headers:
42+
content-type:
43+
- application/json
44+
status:
45+
code: 201
46+
message: Created
47+
- request:
48+
body: '{"data":{"attributes":{"role":"admin"},"relationships":{"user":{"data":{"id":"ebb17d15-5e46-4440-856f-75710cbbce4b","type":"users"}}},"type":"team_memberships"}}'
49+
headers:
50+
accept:
51+
- application/json
52+
content-type:
53+
- application/json
54+
method: POST
55+
uri: https://api.datadoghq.com/api/v2/team/95ac9e78-0a56-4a6a-9e5e-21580dc141cc/memberships
56+
response:
57+
body:
58+
string: '{"data":{"id":"TeamMembership-95ac9e78-0a56-4a6a-9e5e-21580dc141cc-66215040","type":"team_memberships","attributes":{"provisioned_by":null,"provisioned_by_id":"a1d5ff5a-c6dd-11f0-9cb6-06640ca27ad4","role":"admin"},"relationships":{"user":{"data":{"id":"ebb17d15-5e46-4440-856f-75710cbbce4b","type":"users"}}}},"included":[{"id":"ebb17d15-5e46-4440-856f-75710cbbce4b","type":"users","attributes":{"disabled":false,"email":"test-add_a_user_to_a_team_returns_represents_a_user_s_association_to_a_team_response-1774969069@datadoghq.com","handle":"test-add_a_user_to_a_team_returns_represents_a_user_s_association_to_a_team_response-1774969069@datadoghq.com","icon":"https://secure.gravatar.com/avatar/52a30c814f85968a9d363cc103840284?d=retro\u0026s=48","name":null,"service_account":false,"status":"Pending"}}]}'
59+
headers:
60+
content-type:
61+
- application/vnd.api+json
62+
status:
63+
code: 200
64+
message: OK
65+
- request:
66+
body: null
67+
headers:
68+
accept:
69+
- '*/*'
70+
method: DELETE
71+
uri: https://api.datadoghq.com/api/v2/team/95ac9e78-0a56-4a6a-9e5e-21580dc141cc/memberships/ebb17d15-5e46-4440-856f-75710cbbce4b
72+
response:
73+
body:
74+
string: ''
75+
headers: {}
76+
status:
77+
code: 204
78+
message: No Content
79+
- request:
80+
body: null
81+
headers:
82+
accept:
83+
- '*/*'
84+
method: DELETE
85+
uri: https://api.datadoghq.com/api/v2/users/ebb17d15-5e46-4440-856f-75710cbbce4b
86+
response:
87+
body:
88+
string: ''
89+
headers: {}
90+
status:
91+
code: 204
92+
message: No Content
93+
- request:
94+
body: null
95+
headers:
96+
accept:
97+
- '*/*'
98+
method: DELETE
99+
uri: https://api.datadoghq.com/api/v2/team/95ac9e78-0a56-4a6a-9e5e-21580dc141cc
100+
response:
101+
body:
102+
string: ''
103+
headers: {}
104+
status:
105+
code: 204
106+
message: No Content
107+
version: 1

tests/v2/features/teams.feature

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,28 @@ Feature: Teams
2727
When the request is sent
2828
Then the response status is 204 Added
2929

30-
@generated @skip @team:DataDog/aaa-omg
30+
@team:DataDog/aaa-omg
3131
Scenario: Add a user to a team returns "API error response." response
3232
Given new "CreateTeamMembership" request
33-
And request contains "team_id" parameter from "REPLACE.ME"
34-
And body with value {"data": {"attributes": {"role": "admin"}, "relationships": {"team": {"data": {"id": "d7e15d9d-d346-43da-81d8-3d9e71d9a5e9", "type": "team"}}, "user": {"data": {"id": "b8626d7e-cedd-11eb-abf5-da7ad0900001", "type": "users"}}}, "type": "team_memberships"}}
33+
And there is a valid "dd_team" in the system
34+
And there is a valid "user" in the system
35+
And there is a valid "team_membership" in the system
36+
And request contains "team_id" parameter from "dd_team.data.id"
37+
And body with value {"data": {"attributes": {"role": "admin"}, "relationships": {"user": {"data": {"id": "{{user.data.id}}", "type": "users"}}}, "type": "team_memberships"}}
3538
When the request is sent
3639
Then the response status is 409 API error response.
3740

38-
@generated @skip @team:DataDog/aaa-omg
41+
@team:DataDog/aaa-omg
3942
Scenario: Add a user to a team returns "Represents a user's association to a team" response
4043
Given new "CreateTeamMembership" request
41-
And request contains "team_id" parameter from "REPLACE.ME"
42-
And body with value {"data": {"attributes": {"role": "admin"}, "relationships": {"team": {"data": {"id": "d7e15d9d-d346-43da-81d8-3d9e71d9a5e9", "type": "team"}}, "user": {"data": {"id": "b8626d7e-cedd-11eb-abf5-da7ad0900001", "type": "users"}}}, "type": "team_memberships"}}
44+
And there is a valid "dd_team" in the system
45+
And there is a valid "user" in the system
46+
And request contains "team_id" parameter from "dd_team.data.id"
47+
And body with value {"data": {"attributes": {"role": "admin"}, "relationships": {"user": {"data": {"id": "{{user.data.id}}", "type": "users"}}}, "type": "team_memberships"}}
4348
When the request is sent
4449
Then the response status is 200 Represents a user's association to a team
50+
And the response "data.attributes.role" is equal to "admin"
51+
And the response "data.relationships.user.data.id" is equal to "{{ user.data.id }}"
4552

4653
@team:DataDog/aaa-omg
4754
Scenario: Create a team hierarchy link returns "Conflict" response

0 commit comments

Comments
 (0)