Skip to content

Commit f114c09

Browse files
test: Improve Slack integration mapping test (box/box-codegen#710) (#548)
1 parent 1561988 commit f114c09

File tree

5 files changed

+71
-21
lines changed

5 files changed

+71
-21
lines changed

.codegen.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "engineHash": "0e509a3", "specHash": "f737b7b", "version": "1.13.0" }
1+
{ "engineHash": "90eaba8", "specHash": "f737b7b", "version": "1.13.0" }

.github/workflows/build.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ jobs:
4444
APP_ITEM_ASSOCIATION_FOLDER_ID: ${{ secrets.APP_ITEM_ASSOCIATION_FOLDER_ID }}
4545
WORKFLOW_FOLDER_ID: ${{ secrets.WORKFLOW_FOLDER_ID }}
4646
APP_ITEM_SHARED_LINK: ${{ secrets.APP_ITEM_SHARED_LINK }}
47+
SLACK_AUTOMATION_USER_ID: ${{ secrets.SLACK_AUTOMATION_USER_ID }}
48+
SLACK_ORG_ID: ${{ secrets.SLACK_ORG_ID }}
49+
SLACK_PARTNER_ITEM_ID: ${{ secrets.SLACK_PARTNER_ITEM_ID }}
4750
run: |
4851
tox
4952
@@ -80,3 +83,6 @@ jobs:
8083
APP_ITEM_ASSOCIATION_FILE_ID: ${{ secrets.APP_ITEM_ASSOCIATION_FILE_ID }}
8184
APP_ITEM_ASSOCIATION_FOLDER_ID: ${{ secrets.APP_ITEM_ASSOCIATION_FOLDER_ID }}
8285
APP_ITEM_SHARED_LINK: ${{ secrets.APP_ITEM_SHARED_LINK }}
86+
SLACK_AUTOMATION_USER_ID: ${{ secrets.SLACK_AUTOMATION_USER_ID }}
87+
SLACK_ORG_ID: ${{ secrets.SLACK_ORG_ID }}
88+
SLACK_PARTNER_ITEM_ID: ${{ secrets.SLACK_PARTNER_ITEM_ID }}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ Now select `Authorization` and submit application to be reviewed by account admi
117117
5. Set environment variable: `WORKFLOW_FOLDER_ID` with the ID of the Relay workflow that deletes the file that triggered the workflow. The workflow should have a manual start to be able to start it from the API.
118118
6. Set environment variable: `APP_ITEM_ASSOCIATION_FILE_ID` to the ID of the file with associated app item and `APP_ITEM_ASSOCIATION_FOLDER_ID` to the ID of the folder with associated app item.
119119
7. Set environment variable: `APP_ITEM_SHARED_LINK` to the shared link associated with app item.
120+
8. Set environment variable: `SLACK_AUTOMATION_USER_ID` to the ID of the user responsible for the Slack automation, `SLACK_ORG_ID` to the ID of the Slack organization and `SLACK_PARTNER_ITEM_ID` to the ID of the Slack partner item.
120121

121122
### Running tests
122123

docs/integration_mappings.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ See the endpoint docs at
6969

7070
```python
7171
user_client.integration_mappings.create_slack_integration_mapping(
72-
IntegrationMappingPartnerItemSlack(id=partner_item_id, slack_org_id=slack_org_id),
72+
IntegrationMappingPartnerItemSlack(
73+
id=slack_partner_item_id, slack_org_id=slack_org_id
74+
),
7375
IntegrationMappingBoxItemSlack(id=folder.id),
7476
)
7577
```
@@ -108,7 +110,7 @@ See the endpoint docs at
108110

109111
```python
110112
user_client.integration_mappings.update_slack_integration_mapping_by_id(
111-
integration_mapping_id, box_item=IntegrationMappingBoxItemSlack(id="1234567")
113+
slack_integration_mapping.id, box_item=IntegrationMappingBoxItemSlack(id=folder.id)
112114
)
113115
```
114116

@@ -145,7 +147,7 @@ See the endpoint docs at
145147

146148
```python
147149
user_client.integration_mappings.delete_slack_integration_mapping_by_id(
148-
integration_mapping_id
150+
slack_integration_mapping.id
149151
)
150152
```
151153

test/integration_mappings.py

Lines changed: 58 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from box_sdk_gen.internal.utils import to_string
2+
13
import pytest
24

35
from box_sdk_gen.client import BoxClient
@@ -6,6 +8,20 @@
68

79
from box_sdk_gen.managers.folders import CreateFolderParent
810

11+
from box_sdk_gen.managers.user_collaborations import CreateCollaborationItem
12+
13+
from box_sdk_gen.managers.user_collaborations import CreateCollaborationItemTypeField
14+
15+
from box_sdk_gen.managers.user_collaborations import CreateCollaborationAccessibleBy
16+
17+
from box_sdk_gen.managers.user_collaborations import (
18+
CreateCollaborationAccessibleByTypeField,
19+
)
20+
21+
from box_sdk_gen.managers.user_collaborations import CreateCollaborationRole
22+
23+
from box_sdk_gen.schemas.integration_mappings import IntegrationMappings
24+
925
from box_sdk_gen.schemas.integration_mapping_partner_item_slack import (
1026
IntegrationMappingPartnerItemSlack,
1127
)
@@ -14,7 +30,7 @@
1430
IntegrationMappingBoxItemSlack,
1531
)
1632

17-
from box_sdk_gen.schemas.integration_mappings import IntegrationMappings
33+
from box_sdk_gen.schemas.integration_mapping import IntegrationMapping
1834

1935
from box_sdk_gen.schemas.integration_mapping_partner_item_teams_create_request import (
2036
IntegrationMappingPartnerItemTeamsCreateRequest,
@@ -32,6 +48,8 @@
3248

3349
from box_sdk_gen.internal.utils import get_env_var
3450

51+
from box_sdk_gen.internal.utils import to_string
52+
3553
from test.commons import get_default_client
3654

3755
from test.commons import get_default_client_with_user_subject
@@ -40,35 +58,58 @@
4058

4159

4260
def testSlackIntegrationMappings():
43-
folder: FolderFull = client.folders.create_folder(
44-
get_uuid(), CreateFolderParent(id='0')
45-
)
46-
slack_org_id: str = '1'
47-
partner_item_id: str = '1'
4861
user_id: str = get_env_var('USER_ID')
62+
slack_automation_user_id: str = get_env_var('SLACK_AUTOMATION_USER_ID')
63+
slack_org_id: str = get_env_var('SLACK_ORG_ID')
64+
slack_partner_item_id: str = get_env_var('SLACK_PARTNER_ITEM_ID')
4965
user_client: BoxClient = get_default_client_with_user_subject(user_id)
50-
with pytest.raises(Exception):
66+
folder: FolderFull = user_client.folders.create_folder(
67+
get_uuid(), CreateFolderParent(id='0')
68+
)
69+
user_client.user_collaborations.create_collaboration(
70+
CreateCollaborationItem(
71+
type=CreateCollaborationItemTypeField.FOLDER, id=folder.id
72+
),
73+
CreateCollaborationAccessibleBy(
74+
type=CreateCollaborationAccessibleByTypeField.USER,
75+
id=slack_automation_user_id,
76+
),
77+
CreateCollaborationRole.CO_OWNER,
78+
)
79+
slack_integrations: IntegrationMappings = (
80+
user_client.integration_mappings.get_slack_integration_mapping()
81+
)
82+
if len(slack_integrations.entries) == 0:
5183
user_client.integration_mappings.create_slack_integration_mapping(
5284
IntegrationMappingPartnerItemSlack(
53-
id=partner_item_id, slack_org_id=slack_org_id
85+
id=slack_partner_item_id, slack_org_id=slack_org_id
5486
),
5587
IntegrationMappingBoxItemSlack(id=folder.id),
5688
)
57-
integration_mappings: IntegrationMappings = (
89+
slack_mappings: IntegrationMappings = (
5890
user_client.integration_mappings.get_slack_integration_mapping()
5991
)
60-
assert len(integration_mappings.entries) == 0
61-
integration_mapping_id: str = '123456'
62-
with pytest.raises(Exception):
92+
assert len(slack_mappings.entries) >= 1
93+
slack_integration_mapping: IntegrationMapping = slack_mappings.entries[0]
94+
assert to_string(slack_integration_mapping.integration_type) == 'slack'
95+
assert to_string(slack_integration_mapping.type) == 'integration_mapping'
96+
assert to_string(slack_integration_mapping.box_item.type) == 'folder'
97+
assert slack_integration_mapping.partner_item.id == slack_partner_item_id
98+
assert slack_integration_mapping.partner_item.slack_workspace_id == slack_org_id
99+
assert to_string(slack_integration_mapping.partner_item.type) == 'channel'
100+
updated_slack_mapping: IntegrationMapping = (
63101
user_client.integration_mappings.update_slack_integration_mapping_by_id(
64-
integration_mapping_id,
65-
box_item=IntegrationMappingBoxItemSlack(id='1234567'),
102+
slack_integration_mapping.id,
103+
box_item=IntegrationMappingBoxItemSlack(id=folder.id),
66104
)
67-
with pytest.raises(Exception):
105+
)
106+
assert to_string(updated_slack_mapping.box_item.type) == 'folder'
107+
assert updated_slack_mapping.box_item.id == folder.id
108+
if len(slack_mappings.entries) > 2:
68109
user_client.integration_mappings.delete_slack_integration_mapping_by_id(
69-
integration_mapping_id
110+
slack_integration_mapping.id
70111
)
71-
client.folders.delete_folder_by_id(folder.id)
112+
user_client.folders.delete_folder_by_id(folder.id)
72113

73114

74115
def testTeamsIntegrationMappings():

0 commit comments

Comments
 (0)