Skip to content

Commit

Permalink
Merge branch 'cancel-smart-invites'
Browse files Browse the repository at this point in the history
  • Loading branch information
gshutler committed Aug 6, 2020
2 parents e112d87 + fc746ad commit 59765fe
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 2 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Dan Pozmanter
Garry Shutler <[email protected]>
Stephen Binns <[email protected]>
Chris Nevett <[email protected]>
2 changes: 1 addition & 1 deletion PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 1.0
Name: pycronofy
Version: 1.7.2
Version: 1.7.3
Summary: Python wrapper for Cronofy
Home-page: https://github.com/cronofy/pycronofy
Author: VenueBook
Expand Down
2 changes: 1 addition & 1 deletion pycronofy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pycronofy.client import Client # noqa: F401
from pycronofy import settings
__version__ = '1.7.2'
__version__ = '1.7.3'
__name__ = 'PyCronofy'

"""
Expand Down
22 changes: 22 additions & 0 deletions pycronofy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,28 @@ def get_smart_invite(self, smart_invite_id, recipient_email):

return self.request_handler.get('smart_invites', params=params, use_api_key=True).json()

def cancel_smart_invite(self, smart_invite_id, recipient):
"""Cancel a smart invite.
:param string smart_invite_id - A String uniquely identifying the event for your
application (note: this is NOT an ID generated
by Cronofy).
:param dict recipient - A Dict containing the intended recipient of the invite
:email - A String for the email address you are
going to send the Smart Invite to.
"""
body = {
'smart_invite_id': smart_invite_id,
'method': 'cancel'
}

if type(recipient) == dict:
body['recipient'] = recipient
elif type(recipient) == list:
body['recipients'] = recipient

return self.request_handler.post('smart_invites', data=body, use_api_key=True).json()

def get_authorization_from_code(self, code, redirect_uri=''):
"""Updates the authorization tokens from the user provided code.
Expand Down
129 changes: 129 additions & 0 deletions pycronofy/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,135 @@ def request_callback(request):
assert result['attachments']['icalendar'] == "BEGIN:VCALENDAR\nVERSION:2.0..."


@responses.activate
def test_cancel_smart_invite(client):
smart_invite_id = "qTtZdczOccgaPncGJaCiLg"
recipient = {
'email': "[email protected]"
}

def request_callback(request):
assert request.url == 'https://api.cronofy.com/v1/smart_invites'

payload = json.loads(request.body)
assert payload['method'] == 'cancel'
assert payload['recipient'] == recipient
assert payload['smart_invite_id'] == smart_invite_id

response = {
"recipient": {
"email": "[email protected]",
"status": "pending"
},
"smart_invite_id": "qTtZdczOccgaPncGJaCiLg",
"callback_url": "https://example.yourapp.com/cronofy/smart_invite/notifications",
"event": {
"summary": "Board meeting",
"description": "Discuss plans for the next quarter.",
"start": "2017-10-05T09:30:00Z",
"end": "2017-10-05T10:00:00Z",
"tzid": "Europe/London",
"location": {
"description": "Board room"
}
},
"attachments": {
"icalendar": "BEGIN:VCALENDAR\nVERSION:2.0..."
}
}

return (202, {}, json.dumps(response))

responses.add_callback(
responses.POST,
'%s/v1/smart_invites' % settings.API_BASE_URL,
callback=request_callback,
content_type='application/json',
)

result = client.cancel_smart_invite(smart_invite_id, recipient)

assert result['attachments']['icalendar'] == "BEGIN:VCALENDAR\nVERSION:2.0..."


@responses.activate
def test_cancel_smart_invite_with_multiple_recipients(client):
smart_invite_id = "qTtZdczOccgaPncGJaCiLg"
recipients = [
{
'email': "[email protected]"
},
{
'email': "[email protected]"
},
]

def request_callback(request):
assert request.url == 'https://api.cronofy.com/v1/smart_invites'

payload = json.loads(request.body)
assert payload['method'] == 'cancel'
assert payload['recipients'] == recipients
assert payload['smart_invite_id'] == smart_invite_id

response = {
"recipients": [
{
"email": "[email protected]",
"status": "tentative",
"comment": "example comment",
"proposal": {
"start": {
"time": "2014-09-13T23:00:00+02:00",
"tzid": "Europe/Paris"
},
"end": {
"time": "2014-09-13T23:00:00+02:00",
"tzid": "Europe/Paris"
}
}
},
{
"email": "[email protected]",
"status": "pending"
}
],
"smart_invite_id": "qTtZdczOccgaPncGJaCiLg",
"callback_url": "https://example.yourapp.com/cronofy/smart_invite/notifications",
"event": {
"summary": "Board meeting",
"description": "Discuss plans for the next quarter.",
"start": {
"time": "2020-08-07T09:30:00Z",
"tzid": "Europe/London"
},
"end": {
"time": "2020-08-07T10:00:00Z",
"tzid": "Europe/London"
},
"location": {
"description": "Board room"
}
},
"attachments": {
"icalendar": "BEGIN:VCALENDAR\nVERSION:2.0..."
}
}

return (202, {}, json.dumps(response))

responses.add_callback(
responses.POST,
'%s/v1/smart_invites' % settings.API_BASE_URL,
callback=request_callback,
content_type='application/json',
)

result = client.cancel_smart_invite(smart_invite_id, recipients)

assert result['attachments']['icalendar'] == "BEGIN:VCALENDAR\nVERSION:2.0..."


@responses.activate
def test_user_auth_link(client):
"""Test user auth link returns a properly formatted user auth url.
Expand Down

0 comments on commit 59765fe

Please sign in to comment.