Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
5 changes: 5 additions & 0 deletions tests/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import webexteamssdk
from tests.environment import WEBEX_TEAMS_ACCESS_TOKEN
from webexteamssdk.api.access_tokens import AccessTokensAPI
from webexteamssdk.api.attachment_actions import AttachmentActionsAPI
from webexteamssdk.api.events import EventsAPI
from webexteamssdk.api.licenses import LicensesAPI
from webexteamssdk.api.memberships import MembershipsAPI
Expand Down Expand Up @@ -133,6 +134,10 @@ def test_access_tokens_api_object_creation(api):
assert isinstance(api.access_tokens, AccessTokensAPI)


def test_attachment_actions_api_object_creation(api):
assert isinstance(api.attachment_actions, AttachmentActionsAPI)


def test_events_api_object_creation(api):
assert isinstance(api.events, EventsAPI)

Expand Down
118 changes: 118 additions & 0 deletions tests/api/test_attachment_actions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# -*- coding: utf-8 -*-
"""WebexTeamsAPI Messages API fixtures and tests.

Copyright (c) 2016-2019 Cisco and/or its affiliates.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""

import itertools

import pytest

import webexteamssdk
from tests.environment import WEBEX_TEAMS_TEST_FILE_URL
from tests.utils import create_string


# Helper Functions

def is_valid_attachment_action(obj):
return isinstance(obj, webexteamssdk.AttachmentAction) \
and obj.id is not None


# Fixtures

@pytest.fixture(scope="session")
def attachment_action_create(api, test_people):
person = test_people["member_added_by_email"]
message = api.messages.create(
toPersonEmail=person.emails[0],
text=create_string("Message"),
attachments=[{
"contentType": "application/vnd.microsoft.card.adaptive",
"content": {
"$schema": ("http://adaptivecards.io/schemas/"
"adaptive-card.json"),
"type": "AdaptiveCard",
"version": "1.0",
"body": [{
"type": "ColumnSet",
"columns": [{
"type": "Column",
"width": 2,
"items": [
{
"type": "TextBlock",
"text": "Tell us about your problem",
"weight": "bolder",
"size": "medium"
},
{
"type": "TextBlock",
"text": "Your name",
"wrap": True
},
{
"type": "Input.Text",
"id": "Name",
"placeholder": "John Andersen"
},
{
"type": "TextBlock",
"text": "Your email",
"wrap": True
},
{
"type": "Input.Text",
"id": "Email",
"placeholder": "john.andersen@example.com",
"style": "email"
},
]
}]
}],
"actions": [
{
"type": "Action.Submit",
"title": "Submit"
}
]
}
}]
)
attachment_action = api.attachment_actions.create(
type="submit", messageId=message.id,
inputs={"Name": "test_name", "Email": "test_email"}
)
yield attachment_action

api.messages.delete(message.id)

# Tests


def test_attachment_actions_create(attachment_action_create):
assert is_valid_attachment_action(attachment_action_create)


def test_attachment_actions_get(api, attachment_action_create):
attachment_action = api.attachment_actions.get(attachment_action_create.id)
assert is_valid_attachment_action(attachment_action)
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
pytest_plugins = [
'tests.test_webexteamssdk',
'tests.api',
'tests.api.test_attachment_actions',
'tests.api.test_licenses',
'tests.api.test_memberships',
'tests.api.test_messages',
Expand Down
1 change: 1 addition & 0 deletions tests/test_webexteamssdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def test_package_contents(self):
# Data Models
assert hasattr(webexteamssdk, "dict_data_factory")
assert hasattr(webexteamssdk, "AccessToken")
assert hasattr(webexteamssdk, "AttachmentAction")
assert hasattr(webexteamssdk, "Event")
assert hasattr(webexteamssdk, "License")
assert hasattr(webexteamssdk, "Membership")
Expand Down
6 changes: 3 additions & 3 deletions webexteamssdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
)
from .models.dictionary import dict_data_factory
from .models.immutable import (
AccessToken, Event, License, Membership, Message, Organization, Person,
Role, Room, Team, TeamMembership, Webhook, WebhookEvent,
immutable_data_factory,
AccessToken, AttachmentAction, Event, License, Membership, Message,
Organization, Person, Role, Room, Team, TeamMembership, Webhook,
WebhookEvent, immutable_data_factory,
)
from .models.simple import SimpleDataModel, simple_data_factory
from .utils import WebexTeamsDateTime
Expand Down
4 changes: 4 additions & 0 deletions webexteamssdk/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from webexteamssdk.restsession import RestSession
from webexteamssdk.utils import check_type
from .access_tokens import AccessTokensAPI
from .attachment_actions import AttachmentActionsAPI
from .events import EventsAPI
from .guest_issuer import GuestIssuerAPI
from .licenses import LicensesAPI
Expand Down Expand Up @@ -179,6 +180,9 @@ def __init__(self, access_token=None, base_url=DEFAULT_BASE_URL,
self.team_memberships = TeamMembershipsAPI(
self._session, object_factory
)
self.attachment_actions = AttachmentActionsAPI(
self._session, object_factory
)
self.webhooks = WebhooksAPI(self._session, object_factory)
self.organizations = OrganizationsAPI(self._session, object_factory)
self.licenses = LicensesAPI(self._session, object_factory)
Expand Down
137 changes: 137 additions & 0 deletions webexteamssdk/api/attachment_actions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# -*- coding: utf-8 -*-
"""Webex Teams Messages API wrapper.

Copyright (c) 2016-2019 Cisco and/or its affiliates.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""


from __future__ import (
absolute_import,
division,
print_function,
unicode_literals,
)

from builtins import *

from past.builtins import basestring
from requests_toolbelt import MultipartEncoder

from ..generator_containers import generator_container
from ..restsession import RestSession
from ..utils import (
check_type, dict_from_items_with_values, is_local_file, is_web_url,
open_local_file,
)


API_ENDPOINT = 'attachment/actions'
OBJECT_TYPE = 'attachment_action'


class AttachmentActionsAPI(object):
"""Webex Teams Attachment Actions API.

Wraps the Webex Teams Attachment Actions API and exposes the API as
native Python methods that return native Python objects.

"""

def __init__(self, session, object_factory):
"""Init a new AttachmentActionsAPI object with the provided RestSession.

Args:
session(RestSession): The RESTful session object to be used for
API calls to the Webex Teams service.

Raises:
TypeError: If the parameter types are incorrect.

"""
check_type(session, RestSession, may_be_none=False)
super(AttachmentActionsAPI, self).__init__()
self._session = session
self._object_factory = object_factory

def create(self, type=None, messageId=None, inputs=None,
**request_parameters):
"""Create an attachment action.

Args:
type(attachment action enum): The type of attachment action.
messageId(basestring): The ID of parent message the attachment
action is to be performed on.
inputs(dict): inputs to attachment fields
**request_parameters: Additional request parameters (provides
support for parameters that may be added in the future).

Returns:
Attachment action: A attachment action object with the details
of the created attachment action.

Raises:
TypeError: If the parameter types are incorrect.
ApiError: If the Webex Teams cloud returns an error.
ValueError: If the files parameter is a list of length > 1, or if
the string in the list (the only element in the list) does not
contain a valid URL or path to a local file.

"""

check_type(type, basestring, may_be_none=False)
check_type(messageId, basestring, may_be_none=False)
check_type(inputs, dict, may_be_none=False)

post_data = dict_from_items_with_values(
request_parameters,
type=type,
messageId=messageId,
inputs=inputs
)

json_data = self._session.post(API_ENDPOINT, json=post_data)

# Return a attachment action object created from the response JSON data
return self._object_factory(OBJECT_TYPE, json_data)

def get(self, attachmentId):
"""Get the details of a attachment action, by ID.

Args:
attachmentId(basestring): The ID of the attachment action to be
retrieved.

Returns:
AttachmentAction: A Attachment Action object with the details of
the requested attachment action.

Raises:
TypeError: If the parameter types are incorrect.
ApiError: If the Webex Teams cloud returns an error.

"""
check_type(attachmentId, basestring, may_be_none=False)

# API request
json_data = self._session.get(API_ENDPOINT + '/' + attachmentId)

# Return a message object created from the response JSON data
return self._object_factory(OBJECT_TYPE, json_data)
6 changes: 6 additions & 0 deletions webexteamssdk/models/immutable.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

from webexteamssdk.utils import json_dict
from .mixins.access_token import AccessTokenBasicPropertiesMixin
from .mixins.attachment_action import AttachmentActionBasicPropertiesMixin
from .mixins.event import EventBasicPropertiesMixin
from .mixins.license import LicenseBasicPropertiesMixin
from .mixins.membership import MembershipBasicPropertiesMixin
Expand Down Expand Up @@ -230,6 +231,10 @@ class Webhook(ImmutableData, WebhookBasicPropertiesMixin):
"""Webex Teams Webhook data model."""


class AttachmentAction(ImmutableData, AttachmentActionBasicPropertiesMixin):
"""Webex Attachment Actions data model"""


class WebhookEvent(ImmutableData, WebhookEventBasicPropertiesMixin):
"""Webex Teams Webhook-Events data model."""

Expand All @@ -246,6 +251,7 @@ class GuestIssuerToken(ImmutableData, GuestIssuerTokenBasicPropertiesMixin):
immutable_data_models = defaultdict(
lambda: ImmutableData,
access_token=AccessToken,
attachment_action=AttachmentAction,
event=Event,
license=License,
membership=Membership,
Expand Down
Loading