Esempio n. 1
0
def test_facebook_page_to_google_no_end():
    event = {
        'description': 'desc',
        'id': '1234567890',
        'name': 'name',
        'place': {
            'name': 'place',
        },
        'start_time': '2018-02-11T11:00:00-0500',
    }
    ret = facebook.FacebookPage(None, 'MyPage').to_google(event)
    exp = {
        'description': 'desc\n\nhttps://www.facebook.com/1234567890',
        'start': {
            'dateTime': '2018-02-11T11:00:00-05:00',
            'timeZone': 'UTC-05:00'
        },
        'extendedProperties': {
            'private': {
                'facebookPageId': 'MyPage',
                'facebookDigest': '262e76ded1c9944e4c08d84939b5ef354b2574c7',
                'facebookId': '1234567890',
            }
        },
        'end': {
            'dateTime': '2018-02-11T12:00:00-05:00',
            'timeZone': 'UTC-05:00'
        },
        'summary': 'name',
        'location': 'place'
    }
    assert ret == exp
Esempio n. 2
0
def test_facebook_page_to_google():
    event = {
        'description': 'desc',
        'end_time': '2018-02-11T16:00:00-0500',
        'id': '1234567890',
        'name': 'name',
        'place': {
            'name': 'place',
        },
        'start_time': '2018-02-11T11:00:00-0500',
    }
    ret = facebook.FacebookPage(None, 'MyPage').to_google(event)
    exp = {
        'description': 'desc\n\nhttps://www.facebook.com/1234567890',
        'start': {
            'dateTime': '2018-02-11T11:00:00-05:00',
            'timeZone': 'UTC-05:00'
        },
        'extendedProperties': {
            'private': {
                'facebookPageId': 'MyPage',
                'facebookDigest': 'ca00a6786b8bb6acd2488080d70ea861b0db84f3',
                'facebookId': '1234567890',
            }
        },
        'end': {
            'dateTime': '2018-02-11T16:00:00-05:00',
            'timeZone': 'UTC-05:00'
        },
        'summary': 'name',
        'location': 'place'
    }
    assert ret == exp
Esempio n. 3
0
def test_callback_err():
    mockapi = mock.MagicMock()
    gcal = google.GoogleCalendar(mockapi, 'MyGCal')
    page = facebook.FacebookPage(mockapi, 'MyPage')
    sync = gcal.sync(page, time_filter='upcoming')
    callback = sync.callbackgen([])
    with pytest.raises(ValueError):
        callback('id', 'response', ValueError)
Esempio n. 4
0
def test_facebook_page_iter_objects():
    mockapi = mock.MagicMock()
    results = {str(x): {'id': str(x)} for x in range(0, 100)}
    mockapi.get_objects.side_effect = [
        {k: v
         for k, v in list(results.items())[:50]},
        {k: v
         for k, v in list(results.items())[50:]},
    ]
    page = facebook.FacebookPage(mockapi, 'MyPage')
    ret = page.get_objects(list(results.keys())).execute()
    exp = list(results.values())
    assert ret == exp
Esempio n. 5
0
def test_google_page_sync_no_op():
    mockf = mock.MagicMock()
    mockg = mock.MagicMock()

    mockf.get_object.side_effect = mockf.get_objects.side_effect = [
        {
            'data': [],
        },
    ]
    gcal = google.GoogleCalendar(mockg, 'MyGCal')
    page = facebook.FacebookPage(mockf, 'MyPage')
    sync = gcal.sync(page, time_filter='upcoming')
    sync.filter(lambda x: x).execute()
    mockg.new_batch_http_request.assert_not_called()
Esempio n. 6
0
def test_callback():
    mockapi = mock.MagicMock()
    gcal = google.GoogleCalendar(mockapi, 'MyGCal')
    page = facebook.FacebookPage(mockapi, 'MyPage')
    sync = gcal.sync(page, time_filter='upcoming')
    callback = sync.callbackgen('POST')
    res = {
        'extendedProperties': {
            'private': {
                'facebookId': '1'
            },
        },
    }
    callback('id', res, None)
    assert sync.responses['POST'] == {'1': res}
Esempio n. 7
0
def test_facebook_page_iter_events():
    mockapi = mock.MagicMock()
    mockapi.get_object.side_effect = [{
        'data': [{
            'id': '1'
        }, {
            'id': '2'
        }],
        'paging': {
            'cursors': {
                'after': 'fizz'
            }
        },
    }, {
        'data': [{
            'id': '3'
        }, {
            'id': '4'
        }],
    }]
    page = facebook.FacebookPage(mockapi, 'MyPage')
    ret = page.get_events().execute()
    exp = [{'id': '1'}, {'id': '2'}, {'id': '3'}, {'id': '4'}]
    assert ret == exp
Esempio n. 8
0
def test_google_page_sync():
    mockf = mock.MagicMock()
    mockg = mock.MagicMock()

    fevents = [
        {
            'id': '1',
            'start_time': '2018-12-12T12:00:00-0500',
            'end_time': '2018-12-12T13:00:00-0500',
            'description': 'some description 1',
            'name': 'Event 1',
            'place': {
                'name': 'Boston Public Library',
                'location': {
                    'city': 'Boston',
                    'country': 'United States',
                    'state': 'MA',
                    'street': '700 Boylston St',
                    'zip': '02116',
                },
            },
        },
        {
            'id': '2',
            'start_time': '2018-12-13T12:00:00-0500',
            'end_time': '2018-12-13T13:00:00-0500',
            'description': 'some description 2',
            'name': 'Event 2',
            'place': {
                'name': 'Boston Public Library',
                'location': {
                    'city': 'Boston',
                    'country': 'United States',
                    'state': 'MA',
                    'street': '700 Boylston St',
                    'zip': '02116',
                },
            },
        },
        {
            'id': '3',
            'start_time': '2018-12-14T12:00:00-0500',
            'end_time': '2018-12-14T13:00:00-0500',
            'description': 'some description 3',
            'name': 'Event 3',
            'place': {
                'name': 'Boston Public Library',
                'location': {
                    'city': 'Boston',
                    'country': 'United States',
                    'state': 'MA',
                    'street': '700 Boylston St',
                    'zip': '02116',
                },
            },
        },
    ]
    gevents = [{
        'id': '1',
        'summary': 'Event 1',
        'extendedProperties': {
            'private': {
                'facebookId': '1',
                'facebookPageId': 'MyPage',
                'facebookDigest': 'c572922673ad8110b615238f8c48cd38ee156bdc',
            }
        }
    }, {
        'id': '2',
        'summary': 'Event 2',
        'extendedProperties': {
            'private': {
                'facebookId': '2',
                'facebookPageId': 'MyPage',
                'facebookDigest': 'OUTDATED',
            }
        }
    }, {
        'id': '4',
        'summary': 'Event 4',
        'extendedProperties': {
            'private': {
                'facebookId': '4',
                'facebookPageId': 'MyPage',
                'facebookDigest': '',
            }
        }
    }]
    mockf.get_object.side_effect = [{'data': fevents}]
    mockf.get_objects.side_effect = [{x['id']: x for x in fevents}]
    mockg.events.return_value.list.return_value.execute.side_effect = \
        [{'items': gevents}]
    gcal = google.GoogleCalendar(mockg, 'MyGCal')
    page = facebook.FacebookPage(mockf, 'MyPage')
    ret = gcal.sync(page, time_filter='upcoming').execute()
    mockg.events.return_value.insert.assert_called_once_with(
        calendarId='MyGCal',
        body={
            'summary': 'Event 3',
            'description': 'some description 3\n\nhttps://www.facebook.com/3',
            'location': 'Boston Public Library '
            '700 Boylston St '
            'Boston MA United States 02116',
            'start': {
                'dateTime': '2018-12-14T12:00:00-05:00',
                'timeZone': 'UTC-05:00',
            },
            'end': {
                'dateTime': '2018-12-14T13:00:00-05:00',
                'timeZone': 'UTC-05:00',
            },
            'extendedProperties': {
                'private': {
                    'facebookDigest':
                    '6a1960a370ba8f16031d729ebfdbccb1110b5fd7',
                    'facebookId': '3',
                    'facebookPageId': 'MyPage',
                },
            },
        },
    )
    mockg.events.return_value.update.assert_called_once_with(
        calendarId='MyGCal',
        eventId='2',
        body={
            'summary': 'Event 2',
            'description': 'some description 2\n\nhttps://www.facebook.com/2',
            'location': 'Boston Public Library '
            '700 Boylston St '
            'Boston MA United States 02116',
            'start': {
                'dateTime': '2018-12-13T12:00:00-05:00',
                'timeZone': 'UTC-05:00',
            },
            'end': {
                'dateTime': '2018-12-13T13:00:00-05:00',
                'timeZone': 'UTC-05:00',
            },
            'extendedProperties': {
                'private': {
                    'facebookDigest':
                    '505f25b09ebde5a6e2587849d364d118ad740454',
                    'facebookId': '2',
                    'facebookPageId': 'MyPage',
                },
            },
        },
    )
    mockg.events.return_value.delete.assert_called_once_with(
        calendarId='MyGCal',
        eventId='4',
    )
Esempio n. 9
0
def test_google_page_sync_multibatch(mock_digest):
    mock_digest.return_value = '<digest>'
    mockf = mock.MagicMock()
    mockg = mock.MagicMock()
    items = range(0, 99)
    mockf.get_object.side_effect = mockf.get_objects.side_effect = [
        {
            'data': [{
                'id': str(x),
                'start_time': '2018-12-12T12:00:00-0500',
                'end_time': '2018-12-12T13:00:00-0500',
                'description': f'some description {x}',
                'name': f'Event {x}',
                'place': {
                    'name': 'Boston Public Library',
                    'location': {
                        'city': 'Boston',
                        'country': 'United States',
                        'state': 'MA',
                        'street': '700 Boylston St',
                        'zip': '02116',
                    },
                },
            } for x in items],
        },
    ]
    mockg.events.return_value.list.return_value.execute.side_effect = [
        {
            'items': [],
        },
    ]
    gcal = google.GoogleCalendar(mockg, 'MyGCal')
    page = facebook.FacebookPage(mockf, 'MyPage')
    gcal.sync(page, time_filter='upcoming').execute()
    mockg.events.return_value.insert.assert_has_calls([
        mock.call(
            calendarId='MyGCal',
            body={
                'summary': f'Event {x}',
                'description':
                f'some description {x}\n\nhttps://www.facebook.com/{x}',
                'location': 'Boston Public Library '
                '700 Boylston St '
                'Boston MA United States 02116',
                'start': {
                    'dateTime': '2018-12-12T12:00:00-05:00',
                    'timeZone': 'UTC-05:00',
                },
                'end': {
                    'dateTime': '2018-12-12T13:00:00-05:00',
                    'timeZone': 'UTC-05:00',
                },
                'extendedProperties': {
                    'private': {
                        'facebookDigest': '<digest>',
                        'facebookId': str(x),
                        'facebookPageId': 'MyPage',
                    },
                },
            },
        ) for x in items
    ])
    mockg.new_batch_http_request.return_value.execute.assert_has_calls([
        mock.call(),
        mock.call(),
    ])