def test_get_image_from_url(monkeypatch):
    monkeypatch.setattr('requests.get',
                        lambda url: response(200, b'image_data'))
    image = get_image_from_url('test')
    image.seek(0)

    assert type(image) is File
    assert image.read() == b'image_data'

    monkeypatch.setattr('requests.get', lambda url: response(400, None))
    assert get_image_from_url('test') is None
Example #2
0
def test_go_retrieve_user_invalid(monkeypatch):
    monkeypatch.setattr(
        'requests.get', lambda url, **kwargs: response(
            400, {'error_description': 'Access Token is invalid!'}))

    user = users.services.go_retrieve_user('token')

    assert user.get('error') == 'Access Token is invalid!'
Example #3
0
    def test_url(generated_url):
        facebook_url = users.services.FACEBOOK_API_URL
        facebook_url += 'me?fields=id,first_name,last_name,email,picture{url}'
        facebook_url += f'&access_token={access_token}'

        assert generated_url == facebook_url

        return response(200, api_response)
Example #4
0
    def test_url(generated_url, **kwargs):

        google_url = users.services.GOOGLE_API_URL
        google_url += 'oauth2/v2/userinfo'

        assert generated_url == google_url
        assert pydash.get(kwargs,
                          'headers.Authorization') == f'Bearer {access_token}'

        return response(200, api_response)
Example #5
0
def test_fb_retrieve_user_invalid(monkeypatch):
    monkeypatch.setattr(
        'requests.get', lambda url: response(
            400, {'error': {
                'message': 'Access Token is invalid!'
            }}))

    user = users.services.fb_retrieve_user('token')

    assert user.get('error') == 'Access Token is invalid!'