def test_upload_with_store_params(post_mock, store_params, expected_store_task): post_mock.return_value = DummyHttpResponse(json_dict={'handle': 'newHandle'}) handle = upload_external_url(url, apikey, store_params=store_params) assert handle == 'newHandle' post_args, _ = post_mock.call_args req_url = post_args[0] assert expected_store_task in req_url
def test_upload(post_mock): post_mock.return_value = DummyHttpResponse( json_dict={'handle': 'newHandle'}) handle = upload_external_url(url, apikey) assert handle == 'newHandle' post_mock.assert_called_once_with('{}/{}/store/{}'.format( config.CDN_URL, apikey, url))
def test_upload_with_security(post_mock): post_mock.return_value = DummyHttpResponse(json_dict={'handle': 'newHandle'}) security = Security({'expiry': 123123123123, 'call': ['write']}, 'SECRET') handle = upload_external_url(url, apikey, security=security) assert handle == 'newHandle' expected_url = '{}/{}/store/{}/{}'.format( config.CDN_URL, apikey, security.as_url_string(), encoded_url ) post_mock.assert_called_once_with(expected_url)
def upload_url(self, url, store_params=None, security=None): """ Uploads local file from external url Args: url (str): file URL store_params (dict): store parameters to be used during upload security (:class:`filestack.Security`): Security object that will be used for this API call Returns: :class:`filestack.Filelink`: new Filelink object """ sec = security or self.security handle = upload_external_url(url, self.apikey, store_params, security=sec) return filestack.models.Filelink(handle=handle, security=sec)
def test_upload_with_store_params(post_mock, default_storage, store_params, security, expected_store_tasks): expected_payload = { 'apikey': 'TESTAPIKEY', 'sources': ['http://image.url'], 'tasks': expected_store_tasks } post_mock.return_value = DummyHttpResponse( json_dict={'handle': 'newHandle'}) upload_response = upload_external_url(url, apikey, default_storage, store_params=store_params, security=security) assert upload_response['handle'] == 'newHandle' post_args, _ = post_mock.call_args post_mock.assert_called_once_with('{}/process'.format(config.CDN_URL), json=expected_payload)
def test_upload_exception(post_mock): error_message = 'Oops!' post_mock.side_effect = Exception(error_message) with pytest.raises(Exception, match=error_message): upload_external_url(url, apikey)