def test_to_json_attendees(self):
        e = Event('Good day',
                  start=(1 / Jul / 2020)[11:22:33],
                  timezone=TEST_TIMEZONE,
                  attendees=[
                      Attendee(email='*****@*****.**',
                               response_status=ResponseStatus.NEEDS_ACTION),
                      Attendee(email='*****@*****.**',
                               response_status=ResponseStatus.ACCEPTED),
                  ])
        event_json = {
            'summary':
            'Good day',
            'start': {
                'dateTime': '2020-07-01T11:22:33+12:00',
                'timeZone': TEST_TIMEZONE
            },
            'end': {
                'dateTime': '2020-07-01T12:22:33+12:00',
                'timeZone': TEST_TIMEZONE
            },
            'recurrence': [],
            'visibility':
            'default',
            'attendees': [
                {
                    'email': '*****@*****.**',
                    'responseStatus': ResponseStatus.NEEDS_ACTION
                },
                {
                    'email': '*****@*****.**',
                    'responseStatus': ResponseStatus.ACCEPTED
                },
            ],
            'reminders': {
                'useDefault': False
            },
            'attachments': []
        }
        self.assertDictEqual(EventSerializer.to_json(e), event_json)

        e = Event('Good day2', start=20 / Jul / 2020, default_reminders=True)
        event_json = {
            'summary': 'Good day2',
            'start': {
                'date': '2020-07-20'
            },
            'end': {
                'date': '2020-07-21'
            },
            'recurrence': [],
            'visibility': 'default',
            'attendees': [],
            'reminders': {
                'useDefault': True
            },
            'attachments': []
        }
        self.assertDictEqual(EventSerializer.to_json(e), event_json)
Beispiel #2
0
    def test_to_json(self):
        e = Event('Good day', start=(28 / Sept / 2019), timezone=TEST_TIMEZONE)
        expected_event_json = {
            'summary': 'Good day',
            'start': {
                'date': '2019-09-28'
            },
            'end': {
                'date': '2019-09-29'
            },
            'recurrence': [],
            'visibility': 'default',
            'attendees': [],
            'reminders': {
                'useDefault': False
            },
            'attachments': [],
            'guestsCanInviteOthers': True,
            'guestsCanModify': False,
            'guestsCanSeeOtherGuests': True,
        }
        self.assertDictEqual(EventSerializer.to_json(e), expected_event_json)

        e = Event('Good day',
                  start=(28 / Oct / 2019)[11:22:33],
                  timezone=TEST_TIMEZONE)
        expected_event_json = {
            'summary': 'Good day',
            'start': {
                'dateTime': '2019-10-28T11:22:33+12:00',
                'timeZone': TEST_TIMEZONE
            },
            'end': {
                'dateTime': '2019-10-28T12:22:33+12:00',
                'timeZone': TEST_TIMEZONE
            },
            'recurrence': [],
            'visibility': 'default',
            'attendees': [],
            'reminders': {
                'useDefault': False
            },
            'attachments': [],
            'guestsCanInviteOthers': True,
            'guestsCanModify': False,
            'guestsCanSeeOtherGuests': True,
        }
        self.assertDictEqual(EventSerializer.to_json(e), expected_event_json)
Beispiel #3
0
 def test_to_json_attachments(self):
     e = Event('Good day',
               start=(1 / Jan / 2019)[11:22:33],
               timezone=TEST_TIMEZONE,
               attachments=[
                   Attachment('My file1', 'https://file.url1', "application/vnd.google-apps.document"),
                   Attachment('My file2', 'https://file.url2', "application/vnd.google-apps.document")
               ])
     event_json = {
         'summary': 'Good day',
         'start': {'dateTime': '2019-01-01T11:22:33+13:00', 'timeZone': TEST_TIMEZONE},
         'end': {'dateTime': '2019-01-01T12:22:33+13:00', 'timeZone': TEST_TIMEZONE},
         'recurrence': [],
         'visibility': 'default',
         'reminders': {'useDefault': False},
         'attachments': [
             {
                 'title': 'My file1',
                 'fileUrl': 'https://file.url1',
                 'mimeType': 'application/vnd.google-apps.document'
             },
             {
                 'title': 'My file2',
                 'fileUrl': 'https://file.url2',
                 'mimeType': 'application/vnd.google-apps.document'
             }
         ]
     }
     self.assertDictEqual(EventSerializer.to_json(e), event_json)
 def test_to_json_reminders(self):
     e = Event('Good day',
               start=(1 / Jan / 2019)[11:22:33],
               timezone=TEST_TIMEZONE,
               minutes_before_popup_reminder=30,
               minutes_before_email_reminder=120)
     event_json = {
         'summary': 'Good day',
         'start': {
             'dateTime': '2019-01-01T11:22:33+13:00',
             'timeZone': TEST_TIMEZONE
         },
         'end': {
             'dateTime': '2019-01-01T12:22:33+13:00',
             'timeZone': TEST_TIMEZONE
         },
         'recurrence': [],
         'visibility': 'default',
         'attendees': [],
         'reminders': {
             'overrides': [{
                 'method': 'popup',
                 'minutes': 30
             }, {
                 'method': 'email',
                 'minutes': 120
             }],
             'useDefault':
             False
         },
         'attachments': []
     }
     self.assertDictEqual(EventSerializer.to_json(e), event_json)
Beispiel #5
0
 def test_to_json_updated(self):
     e = Event('Good day',
               start=(1 / Jul / 2020)[11:22:33],
               timezone=TEST_TIMEZONE,
               _updated=insure_localisation((25 / Nov / 2020)[11:22:33],
                                            timezone=TEST_TIMEZONE))
     expected_event_json = {
         'summary': 'Good day',
         'start': {
             'dateTime': '2020-07-01T11:22:33+12:00',
             'timeZone': TEST_TIMEZONE
         },
         'end': {
             'dateTime': '2020-07-01T12:22:33+12:00',
             'timeZone': TEST_TIMEZONE
         },
         'recurrence': [],
         'visibility': 'default',
         'attendees': [],
         'reminders': {
             'useDefault': False
         },
         'attachments': [],
         'guestsCanInviteOthers': True,
         'guestsCanModify': False,
         'guestsCanSeeOtherGuests': True,
     }
     self.assertDictEqual(EventSerializer.to_json(e), expected_event_json)
Beispiel #6
0
def query_events(calendar, end, start=MIN_DATE, drop_invalid=True):
    """Get events from one calendar"""

    data = []

    # Retrive all events between start and end
    events = calendar.get_events(start,
                                 end,
                                 order_by="updated",
                                 single_events=True)

    for event in events:

        data.append({
            # Serialize the event
            **EventSerializer.to_json(event),
            # And replace 'start' and 'end' with the easier to use values
            # Defaults from 'to_json' are dict that include timezone and we don't want that
            "start":
            event.start,
            "end":
            event.end,
        })

    # Return them as a nice pandas dataframe
    df = pd.DataFrame(data)

    if drop_invalid:
        df = df.dropna(subset=["start"])

    return df
Beispiel #7
0
 def test_to_json_recurrence(self):
     e = Event('Good day',
               start=(1 / Jan / 2019)[11:22:33],
               end=(1 / Jan / 2020)[11:22:33],
               timezone=TEST_TIMEZONE,
               recurrence=[
                   Recurrence.rule(freq=DAILY),
                   Recurrence.exclude_rule(by_week_day=MONDAY),
                   Recurrence.exclude_dates([
                       19 / Apr / 2019,
                       22 / Apr / 2019,
                       12 / May / 2019
                   ])
               ])
     event_json = {
         'summary': 'Good day',
         'start': {'dateTime': '2019-01-01T11:22:33+13:00', 'timeZone': TEST_TIMEZONE},
         'end': {'dateTime': '2020-01-01T11:22:33+13:00', 'timeZone': TEST_TIMEZONE},
         'recurrence': [
             'RRULE:FREQ=DAILY;WKST=SU',
             'EXRULE:FREQ=DAILY;BYDAY=MO;WKST=SU',
             'EXDATE;VALUE=DATE:20190419,20190422,20190512'
         ],
         'visibility': 'default',
         'reminders': {'useDefault': False},
         'attachments': []
     }
     self.assertDictEqual(EventSerializer.to_json(e), event_json)
Beispiel #8
0
 def test_to_json_conference_solution(self):
     e = Event('Good day',
               start=(1 / Jul / 2020)[11:22:33],
               timezone=TEST_TIMEZONE,
               conference_solution=ConferenceSolution(
                   entry_points=EntryPoint(EntryPoint.VIDEO,
                                           uri='https://video.com'),
                   solution_type=SolutionType.HANGOUTS_MEET,
                   name='Hangout',
                   icon_uri='https://icon.com',
                   conference_id='aaa-bbbb-ccc',
                   signature='abc4efg12345',
                   notes='important notes'))
     expected_event_json = {
         'summary': 'Good day',
         'start': {
             'dateTime': '2020-07-01T11:22:33+12:00',
             'timeZone': TEST_TIMEZONE
         },
         'end': {
             'dateTime': '2020-07-01T12:22:33+12:00',
             'timeZone': TEST_TIMEZONE
         },
         'recurrence': [],
         'visibility': 'default',
         'attendees': [],
         'reminders': {
             'useDefault': False
         },
         'attachments': [],
         'conferenceData': {
             'entryPoints': [{
                 'entryPointType': 'video',
                 'uri': 'https://video.com',
             }],
             'conferenceSolution': {
                 'key': {
                     'type': 'hangoutsMeet'
                 },
                 'name': 'Hangout',
                 'iconUri': 'https://icon.com'
             },
             'conferenceId':
             'aaa-bbbb-ccc',
             'signature':
             'abc4efg12345',
             'notes':
             'important notes'
         },
         'guestsCanInviteOthers': True,
         'guestsCanModify': False,
         'guestsCanSeeOtherGuests': True,
     }
     self.assertDictEqual(EventSerializer.to_json(e), expected_event_json)
Beispiel #9
0
    def test_to_object(self):
        event_json = {
            'summary': 'Good day',
            'description': 'Very good day indeed',
            'location': 'Prague',
            'start': {'dateTime': '2019-01-01T11:22:33', 'timeZone': TEST_TIMEZONE},
            'end': {'dateTime': '2019-01-01T12:22:33', 'timeZone': TEST_TIMEZONE},
            'recurrence': [
                'RRULE:FREQ=DAILY;WKST=SU',
                'EXRULE:FREQ=DAILY;BYDAY=MO;WKST=SU',
                'EXDATE:VALUE=DATE:20190419,20190422,20190512'
            ],
            'visibility': 'public',
            'reminders': {
                'useDefault': False,
                'overrides': [
                    {'method': 'popup', 'minutes': 30},
                    {'method': 'email', 'minutes': 120}
                ]
            },
            'attachments': [
                {
                    'title': 'My file1',
                    'fileUrl': 'https://file.url1',
                    'mimeType': 'application/vnd.google-apps.document'
                },
                {
                    'title': 'My file2',
                    'fileUrl': 'https://file.url2',
                    'mimeType': 'application/vnd.google-apps.document'
                }
            ]
        }

        event = EventSerializer.to_object(event_json)

        self.assertEqual(event.summary, 'Good day')
        self.assertEqual(event.start, insure_localisation((1 / Jan / 2019)[11:22:33], TEST_TIMEZONE))
        self.assertEqual(event.end, insure_localisation((1 / Jan / 2019)[12:22:33], TEST_TIMEZONE))
        self.assertEqual(event.description, 'Very good day indeed')
        self.assertEqual(event.location, 'Prague')
        self.assertEqual(len(event.recurrence), 3)
        self.assertEqual(event.visibility, Visibility.PUBLIC)
        self.assertIsInstance(event.reminders[0], PopupReminder)
        self.assertEqual(event.reminders[0].minutes_before_start, 30)
        self.assertIsInstance(event.reminders[1], EmailReminder)
        self.assertEqual(event.reminders[1].minutes_before_start, 120)
        self.assertEqual(len(event.attachments), 2)
        self.assertIsInstance(event.attachments[0], Attachment)
        self.assertEqual(event.attachments[0].title, 'My file1')
Beispiel #10
0
 def test_to_json_conference_solution_create_request(self):
     e = Event('Good day',
               start=(1 / Jul / 2020)[11:22:33],
               timezone=TEST_TIMEZONE,
               conference_solution=ConferenceSolutionCreateRequest(
                   solution_type=SolutionType.HANGOUTS_MEET,
                   request_id='hello1234',
                   conference_id='conference-id',
                   signature='signature',
                   notes='important notes',
                   _status='pending'))
     expected_event_json = {
         'summary': 'Good day',
         'start': {
             'dateTime': '2020-07-01T11:22:33+12:00',
             'timeZone': TEST_TIMEZONE
         },
         'end': {
             'dateTime': '2020-07-01T12:22:33+12:00',
             'timeZone': TEST_TIMEZONE
         },
         'recurrence': [],
         'visibility': 'default',
         'attendees': [],
         'reminders': {
             'useDefault': False
         },
         'attachments': [],
         'conferenceData': {
             'createRequest': {
                 'requestId': 'hello1234',
                 'conferenceSolutionKey': {
                     'type': 'hangoutsMeet'
                 },
                 'status': {
                     'statusCode': 'pending'
                 }
             },
             'conferenceId': 'conference-id',
             'signature': 'signature',
             'notes': 'important notes'
         },
         'guestsCanInviteOthers': True,
         'guestsCanModify': False,
         'guestsCanSeeOtherGuests': True,
     }
     self.assertDictEqual(EventSerializer.to_json(e), expected_event_json)
Beispiel #11
0
    async def update_event(self):
        await self.bot.wait_until_ready()

        notify_channel = self.bot.get_channel(None)

        def get_new_notify_msg():
            pass

        for event in self.gc:
            event_data = self.gc_cursor.find_one({"_id": event.id})

            if not event_data:
                continue

            event_obj = dict(EventSerializer.to_json(event))

            # etag has been modified => event has been modified
            if event_obj["etag"] != event_data["etag"]:
                # renew all info of event
                event_start_time = pend.parse(str(event.start), tz='Asia/Taipei')
                event_end_time = pend.parse(str(event.end), tz='Asia/Taipei')

                execute = {
                    "$set": {
                        "etag": event_obj["etag"],
                        "summary": event.summary,
                        "location": event.location,
                        "start": event_start_time,
                        "end": event_end_time
                    }
                }
                self.gc_cursor.update_one({"_id": event.id}, execute)

                # repost notify
                old_notify_dc_msg = notify_channel.fetch_message(event_data["msg_id"])
                await old_notify_dc_msg.delete()

                notify_msg = get_new_notify_msg()
                notify_dc_msg = await notify_channel.send(notify_msg)

                execute = {
                    "$set": {
                        "msg_id": notify_dc_msg.id
                    }
                }
                self.gc_cursor.update_one({"_id": event.id}, execute)
Beispiel #12
0
    def test_to_object_recurring_event(self):
        event_json_str = {
            "id": 'recurring_event_id_20201107T070000Z',
            "summary": "Good day",
            "description": "Very good day indeed",
            "location": "Prague",
            "start": {
                "date": "2020-07-20"
            },
            "end": {
                "date": "2020-07-22"
            },
            "recurringEventId": 'recurring_event_id'
        }

        event = EventSerializer.to_object(event_json_str)

        self.assertEqual(event.id, 'recurring_event_id_20201107T070000Z')
        self.assertTrue(event.is_recurring_instance)
        self.assertEqual(event.recurring_event_id, 'recurring_event_id')
Beispiel #13
0
    async def collect_event(self):
        await self.bot.wait_until_ready()

        for event in self.gc:
            event_data = self.gc_cursor.find_one({"_id": event.id})
            if event_data:
                continue

            event_obj = dict(EventSerializer.to_json(event))

            event_start_time = pend.parse(str(event.start), tz='Asia/Taipei').to_datetime_string()
            event_end_time = pend.parse(str(event.end), tz='Asia/Taipei').to_datetime_string()

            event_data = {
                "_id": event.id,
                "etag": event_obj["etag"],
                "summary": event.summary,
                "location": event.location,
                "start": event_start_time,
                "end": event_end_time,
                "msg_id": None,
                "notify_stage": None
            }
            self.gc_cursor.insert_one(event_data)
    def test_to_object(self):
        event_json = {
            'summary':
            'Good day',
            'description':
            'Very good day indeed',
            'location':
            'Prague',
            'start': {
                'dateTime': '2019-01-01T11:22:33',
                'timeZone': TEST_TIMEZONE
            },
            'end': {
                'dateTime': '2019-01-01T12:22:33',
                'timeZone': TEST_TIMEZONE
            },
            'recurrence': [
                'RRULE:FREQ=DAILY;WKST=SU',
                'EXRULE:FREQ=DAILY;BYDAY=MO;WKST=SU',
                'EXDATE:VALUE=DATE:20190419,20190422,20190512'
            ],
            'visibility':
            'public',
            'attendees': [
                {
                    'email': '*****@*****.**',
                    'responseStatus': ResponseStatus.NEEDS_ACTION
                },
                {
                    'email': '*****@*****.**',
                    'responseStatus': ResponseStatus.ACCEPTED
                },
            ],
            'reminders': {
                'useDefault':
                False,
                'overrides': [{
                    'method': 'popup',
                    'minutes': 30
                }, {
                    'method': 'email',
                    'minutes': 120
                }]
            },
            'attachments': [{
                'title': 'My file1',
                'fileUrl': 'https://file.url1',
                'mimeType': 'application/vnd.google-apps.document'
            }, {
                'title': 'My file2',
                'fileUrl': 'https://file.url2',
                'mimeType': 'application/vnd.google-apps.document'
            }]
        }

        serializer = EventSerializer(event_json)
        event = serializer.get_object()

        self.assertEqual(event.summary, 'Good day')
        self.assertEqual(
            event.start,
            insure_localisation((1 / Jan / 2019)[11:22:33], TEST_TIMEZONE))
        self.assertEqual(
            event.end,
            insure_localisation((1 / Jan / 2019)[12:22:33], TEST_TIMEZONE))
        self.assertEqual(event.description, 'Very good day indeed')
        self.assertEqual(event.location, 'Prague')
        self.assertEqual(len(event.recurrence), 3)
        self.assertEqual(event.visibility, Visibility.PUBLIC)
        self.assertEqual(len(event.attendees), 2)
        self.assertIsInstance(event.reminders[0], PopupReminder)
        self.assertEqual(event.reminders[0].minutes_before_start, 30)
        self.assertIsInstance(event.reminders[1], EmailReminder)
        self.assertEqual(event.reminders[1].minutes_before_start, 120)
        self.assertEqual(len(event.attachments), 2)
        self.assertIsInstance(event.attachments[0], Attachment)
        self.assertEqual(event.attachments[0].title, 'My file1')

        event_json_str = """{
            "summary": "Good day",
            "description": "Very good day indeed",
            "location": "Prague",
            "start": {"date": "2020-07-20"},
            "end": {"date": "2020-07-22"}
        }"""

        event = EventSerializer.to_object(event_json_str)

        self.assertEqual(event.summary, 'Good day')
        self.assertEqual(event.description, 'Very good day indeed')
        self.assertEqual(event.location, 'Prague')
        self.assertEqual(event.start, 20 / Jul / 2020)
        self.assertEqual(event.end, 22 / Jul / 2020)
Beispiel #15
0
 def _serialize_event(e):
     event_json = EventSerializer.to_json(e)
     event_json['updated'] = e.updated.isoformat() + 'Z'
     return event_json
Beispiel #16
0
    def test_to_object(self):
        event_json = {
            'summary':
            'Good day',
            'description':
            'Very good day indeed',
            'location':
            'Prague',
            'start': {
                'dateTime': '2019-01-01T11:22:33',
                'timeZone': TEST_TIMEZONE
            },
            'end': {
                'dateTime': '2019-01-01T12:22:33',
                'timeZone': TEST_TIMEZONE
            },
            'updated':
            '2020-11-25T14:53:46.0Z',
            'created':
            '2020-11-24T14:53:46.0Z',
            'recurrence': [
                'RRULE:FREQ=DAILY;WKST=SU',
                'EXRULE:FREQ=DAILY;BYDAY=MO;WKST=SU',
                'EXDATE:VALUE=DATE:20190419,20190422,20190512'
            ],
            'visibility':
            'public',
            'attendees': [
                {
                    'email': '*****@*****.**',
                    'responseStatus': ResponseStatus.NEEDS_ACTION
                },
                {
                    'email': '*****@*****.**',
                    'responseStatus': ResponseStatus.ACCEPTED
                },
            ],
            'reminders': {
                'useDefault':
                False,
                'overrides': [{
                    'method': 'popup',
                    'minutes': 30
                }, {
                    'method': 'email',
                    'minutes': 120
                }]
            },
            'attachments': [{
                'title': 'My file1',
                'fileUrl': 'https://file.url1',
                'mimeType': 'application/vnd.google-apps.document'
            }, {
                'title': 'My file2',
                'fileUrl': 'https://file.url2',
                'mimeType': 'application/vnd.google-apps.document'
            }],
            'conferenceData': {
                'entryPoints': [{
                    'entryPointType': 'video',
                    'uri': 'https://video.com',
                }],
                'conferenceSolution': {
                    'key': {
                        'type': 'hangoutsMeet'
                    },
                    'name': 'Hangout',
                    'iconUri': 'https://icon.com'
                },
                'conferenceId':
                'aaa-bbbb-ccc',
                'signature':
                'abc4efg12345',
                'notes':
                'important notes'
            },
            'guestsCanInviteOthers':
            False,
            'guestsCanModify':
            True,
            'guestsCanSeeOtherGuests':
            False,
        }

        serializer = EventSerializer(event_json)
        event = serializer.get_object()

        self.assertEqual(event.summary, 'Good day')
        self.assertEqual(
            event.start,
            insure_localisation((1 / Jan / 2019)[11:22:33], TEST_TIMEZONE))
        self.assertEqual(
            event.end,
            insure_localisation((1 / Jan / 2019)[12:22:33], TEST_TIMEZONE))
        self.assertEqual(
            event.updated,
            insure_localisation((25 / Nov / 2020)[14:53:46], 'UTC'))
        self.assertEqual(
            event.created,
            insure_localisation((24 / Nov / 2020)[14:53:46], 'UTC'))
        self.assertEqual(event.description, 'Very good day indeed')
        self.assertEqual(event.location, 'Prague')
        self.assertEqual(len(event.recurrence), 3)
        self.assertEqual(event.visibility, Visibility.PUBLIC)
        self.assertEqual(len(event.attendees), 2)
        self.assertIsInstance(event.reminders[0], PopupReminder)
        self.assertEqual(event.reminders[0].minutes_before_start, 30)
        self.assertIsInstance(event.reminders[1], EmailReminder)
        self.assertEqual(event.reminders[1].minutes_before_start, 120)
        self.assertEqual(len(event.attachments), 2)
        self.assertIsInstance(event.attachments[0], Attachment)
        self.assertEqual(event.attachments[0].title, 'My file1')
        self.assertIsInstance(event.conference_solution, ConferenceSolution)
        self.assertEqual(event.conference_solution.solution_type,
                         'hangoutsMeet')
        self.assertEqual(event.conference_solution.entry_points[0].uri,
                         'https://video.com')
        self.assertFalse(event.guests_can_invite_others)
        self.assertTrue(event.guests_can_modify)
        self.assertFalse(event.guests_can_see_other_guests)

        event_json = {
            'summary': 'Good day',
            'description': 'Very good day indeed',
            'location': 'Prague',
            'start': {
                'dateTime': '2019-01-01T11:22:33',
                'timeZone': TEST_TIMEZONE
            },
            'end': {
                'dateTime': '2019-01-01T12:22:33',
                'timeZone': TEST_TIMEZONE
            },
            'conferenceData': {
                'createRequest': {
                    'requestId': 'hello1234',
                    'conferenceSolutionKey': {
                        'type': 'hangoutsMeet'
                    },
                    'status': {
                        'statusCode': 'pending'
                    }
                },
                'conferenceId': 'conference-id',
                'signature': 'signature',
                'notes': 'important notes'
            }
        }

        event = EventSerializer.to_object(event_json)
        self.assertIsInstance(event.conference_solution,
                              ConferenceSolutionCreateRequest)
        self.assertEqual(event.conference_solution.solution_type,
                         'hangoutsMeet')

        # with successful conference create request
        event_json = {
            'summary': 'Good day',
            'description': 'Very good day indeed',
            'location': 'Prague',
            'start': {
                'dateTime': '2019-01-01T11:22:33',
                'timeZone': TEST_TIMEZONE
            },
            'end': {
                'dateTime': '2019-01-01T12:22:33',
                'timeZone': TEST_TIMEZONE
            },
            'conferenceData': {
                'entryPoints': [{
                    'entryPointType': 'video',
                    'uri': 'https://video.com',
                }],
                'conferenceSolution': {
                    'key': {
                        'type': 'hangoutsMeet'
                    },
                    'name': 'Hangout',
                    'iconUri': 'https://icon.com'
                },
                'createRequest': {
                    'requestId': 'hello1234',
                    'conferenceSolutionKey': {
                        'type': 'hangoutsMeet'
                    },
                    'status': {
                        'statusCode': 'success'
                    }
                },
                'conferenceId':
                'conference-id',
                'signature':
                'signature',
                'notes':
                'important notes'
            }
        }

        event = EventSerializer.to_object(event_json)
        self.assertIsInstance(event.conference_solution, ConferenceSolution)
        self.assertEqual(event.conference_solution.solution_type,
                         'hangoutsMeet')
        self.assertEqual(event.conference_solution.entry_points[0].uri,
                         'https://video.com')

        event_json_str = """{
            "summary": "Good day",
            "description": "Very good day indeed",
            "location": "Prague",
            "start": {"date": "2020-07-20"},
            "end": {"date": "2020-07-22"}
        }"""

        event = EventSerializer.to_object(event_json_str)

        self.assertEqual(event.summary, 'Good day')
        self.assertEqual(event.description, 'Very good day indeed')
        self.assertEqual(event.location, 'Prague')
        self.assertEqual(event.start, 20 / Jul / 2020)
        self.assertEqual(event.end, 22 / Jul / 2020)

        event_json_str = {
            "id": 'recurring_event_id_20201107T070000Z',
            "summary": "Good day",
            "description": "Very good day indeed",
            "location": "Prague",
            "start": {
                "date": "2020-07-20"
            },
            "end": {
                "date": "2020-07-22"
            },
            "recurringEventId": 'recurring_event_id'
        }

        event = EventSerializer.to_object(event_json_str)

        self.assertEqual(event.id, 'recurring_event_id_20201107T070000Z')
        self.assertTrue(event.is_recurring_instance)
        self.assertEqual(event.recurring_event_id, 'recurring_event_id')
Beispiel #17
0
    def test_to_object_conference_data(self):
        event_json = {
            'summary': 'Good day',
            'description': 'Very good day indeed',
            'location': 'Prague',
            'start': {
                'dateTime': '2019-01-01T11:22:33',
                'timeZone': TEST_TIMEZONE
            },
            'end': {
                'dateTime': '2019-01-01T12:22:33',
                'timeZone': TEST_TIMEZONE
            },
            'conferenceData': {
                'createRequest': {
                    'requestId': 'hello1234',
                    'conferenceSolutionKey': {
                        'type': 'hangoutsMeet'
                    },
                    'status': {
                        'statusCode': 'pending'
                    }
                },
                'conferenceId': 'conference-id',
                'signature': 'signature',
                'notes': 'important notes'
            }
        }

        event = EventSerializer.to_object(event_json)
        self.assertIsInstance(event.conference_solution,
                              ConferenceSolutionCreateRequest)
        self.assertEqual(event.conference_solution.solution_type,
                         'hangoutsMeet')

        # with successful conference create request
        event_json = {
            'summary': 'Good day',
            'description': 'Very good day indeed',
            'location': 'Prague',
            'start': {
                'dateTime': '2019-01-01T11:22:33',
                'timeZone': TEST_TIMEZONE
            },
            'end': {
                'dateTime': '2019-01-01T12:22:33',
                'timeZone': TEST_TIMEZONE
            },
            'conferenceData': {
                'entryPoints': [{
                    'entryPointType': 'video',
                    'uri': 'https://video.com',
                }],
                'conferenceSolution': {
                    'key': {
                        'type': 'hangoutsMeet'
                    },
                    'name': 'Hangout',
                    'iconUri': 'https://icon.com'
                },
                'createRequest': {
                    'requestId': 'hello1234',
                    'conferenceSolutionKey': {
                        'type': 'hangoutsMeet'
                    },
                    'status': {
                        'statusCode': 'success'
                    }
                },
                'conferenceId':
                'conference-id',
                'signature':
                'signature',
                'notes':
                'important notes'
            }
        }

        event = EventSerializer.to_object(event_json)
        self.assertIsInstance(event.conference_solution, ConferenceSolution)
        self.assertEqual(event.conference_solution.solution_type,
                         'hangoutsMeet')
        self.assertEqual(event.conference_solution.entry_points[0].uri,
                         'https://video.com')