Skip to content

Commit 7e4fa88

Browse files
committed
Update attachment actions tests
Move the attachment actions card out to a json file. Create a pytest fixture that reads and parses the card.
1 parent 1ea0749 commit 7e4fa88

File tree

2 files changed

+73
-58
lines changed

2 files changed

+73
-58
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"contentType": "application/vnd.microsoft.card.adaptive",
3+
"content": {
4+
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
5+
"type": "AdaptiveCard",
6+
"version": "1.0",
7+
"body": [
8+
{
9+
"type": "ColumnSet",
10+
"columns": [
11+
{
12+
"type": "Column",
13+
"width": 2,
14+
"items": [
15+
{
16+
"type": "TextBlock",
17+
"text": "Tell us about your problem",
18+
"weight": "bolder",
19+
"size": "medium"
20+
},
21+
{
22+
"type": "TextBlock",
23+
"text": "Your name",
24+
"wrap": true
25+
},
26+
{
27+
"type": "Input.Text",
28+
"id": "Name",
29+
"placeholder": "John Andersen"
30+
},
31+
{
32+
"type": "TextBlock",
33+
"text": "Your email",
34+
"wrap": true
35+
},
36+
{
37+
"type": "Input.Text",
38+
"id": "Email",
39+
"placeholder": "john.andersen@example.com",
40+
"style": "email"
41+
}
42+
]
43+
}
44+
]
45+
}
46+
],
47+
"actions": [
48+
{
49+
"type": "Action.Submit",
50+
"title": "Submit"
51+
}
52+
]
53+
}
54+
}

tests/api/test_attachment_actions.py

Lines changed: 19 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -22,93 +22,54 @@
2222
SOFTWARE.
2323
"""
2424

25-
import itertools
25+
import json
26+
import os
2627

2728
import pytest
2829

2930
import webexteamssdk
30-
from tests.environment import WEBEX_TEAMS_TEST_FILE_URL
3131
from tests.utils import create_string
3232

3333

34-
# Helper Functions
34+
# Module Variables
35+
attachment_actions_card_path = os.path.abspath(
36+
os.path.join(__file__, os.pardir, "attachment_actions_card.json")
37+
)
38+
3539

40+
# Helper Functions
3641
def is_valid_attachment_action(obj):
3742
return isinstance(obj, webexteamssdk.AttachmentAction) \
3843
and obj.id is not None
3944

4045

4146
# Fixtures
47+
@pytest.fixture(scope="session")
48+
def attachment_actions_card():
49+
with open(attachment_actions_card_path) as file:
50+
card = json.load(file)
51+
return card
52+
4253

4354
@pytest.fixture(scope="session")
44-
def attachment_action_create(api, test_people):
55+
def attachment_action_create(api, test_people, attachment_actions_card):
4556
person = test_people["member_added_by_email"]
4657
message = api.messages.create(
4758
toPersonEmail=person.emails[0],
4859
text=create_string("Message"),
49-
attachments=[{
50-
"contentType": "application/vnd.microsoft.card.adaptive",
51-
"content": {
52-
"$schema": ("http://adaptivecards.io/schemas/"
53-
"adaptive-card.json"),
54-
"type": "AdaptiveCard",
55-
"version": "1.0",
56-
"body": [{
57-
"type": "ColumnSet",
58-
"columns": [{
59-
"type": "Column",
60-
"width": 2,
61-
"items": [
62-
{
63-
"type": "TextBlock",
64-
"text": "Tell us about your problem",
65-
"weight": "bolder",
66-
"size": "medium"
67-
},
68-
{
69-
"type": "TextBlock",
70-
"text": "Your name",
71-
"wrap": True
72-
},
73-
{
74-
"type": "Input.Text",
75-
"id": "Name",
76-
"placeholder": "John Andersen"
77-
},
78-
{
79-
"type": "TextBlock",
80-
"text": "Your email",
81-
"wrap": True
82-
},
83-
{
84-
"type": "Input.Text",
85-
"id": "Email",
86-
"placeholder": "john.andersen@example.com",
87-
"style": "email"
88-
},
89-
]
90-
}]
91-
}],
92-
"actions": [
93-
{
94-
"type": "Action.Submit",
95-
"title": "Submit"
96-
}
97-
]
98-
}
99-
}]
60+
attachments=[attachment_actions_card],
10061
)
10162
attachment_action = api.attachment_actions.create(
10263
type="submit", messageId=message.id,
103-
inputs={"Name": "test_name", "Email": "test_email"}
64+
inputs={"Name": person.displayName, "Email": person.emails[0]}
10465
)
66+
10567
yield attachment_action
10668

10769
api.messages.delete(message.id)
10870

109-
# Tests
110-
11171

72+
# Tests
11273
def test_attachment_actions_create(attachment_action_create):
11374
assert is_valid_attachment_action(attachment_action_create)
11475

0 commit comments

Comments
 (0)