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 #2
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')