def test_json_list(): """Verify that a json list is wrapped in a ResourceList object.""" resources = wrapped_resource(MockResponse(json.dumps([{'foo': 'bar'}]), encoding='utf-8')) assert isinstance(resources, ResourceList) eq_(1, len(resources)) eq_('bar', resources[0].foo)
def test_properties_copied(): """Certain properties should be copied to the wrapped resource.""" response = MockResponse(json.dumps({'foo': 'bar'}), status_code=200, error='This is an error', url='http://example.com') resource = wrapped_resource(response) eq_(200, resource.status_code) eq_('This is an error', resource.error) eq_('http://example.com', resource.url)
def test_properties_copied(): """Certain properties should be copied to the wrapped resource.""" response = MockResponse(json.dumps({'foo': 'bar'}), encoding='utf-8', status_code=200, reason='OK', url='http://example.com') resource = wrapped_resource(response) eq_(200, resource.status_code) eq_('OK', resource.reason) eq_('utf-8', resource.encoding) eq_('http://example.com', resource.url)
def test_proxy_servers(fake_request): """Test that providing a dictionary of proxy servers works.""" proxies = {'http': 'myproxyserver:1234'} client = soundcloud.Client(client_id='foo', proxies=proxies) expected_url = "%s?%s" % (client._resolve_resource_name('me'), urlencode({'client_id': 'foo'})) headers = {'User-Agent': soundcloud.USER_AGENT} (fake_request.expects_call().with_args(expected_url, headers=headers, proxies=proxies, allow_redirects=True).returns( MockResponse("{}"))) client.get('/me')
def test_method_dispatching_post_request(fake_post): """Test that calling client.post() results in a proper call to the post function in the requests module. TODO: Revise once read/write support has been added. """ client = soundcloud.Client(client_id='foo') expected_url = client._resolve_resource_name('tracks') data = {'client_id': 'foo'} headers = {'User-Agent': soundcloud.USER_AGENT} (fake_post.expects_call().with_args(expected_url, data=data, headers=headers, allow_redirects=True).returns( MockResponse("{}"))) client.post('tracks')
def test_method_dispatching_get_request_readonly(fake_get): """Test that calling client.get() results in a proper call to the get function in the requests module with the provided kwargs as the querystring. """ client = soundcloud.Client(client_id='foo') expected_url = '%s?%s' % (client._resolve_resource_name('tracks'), urlencode({ 'limit': 5, 'client_id': 'foo' })) headers = {'User-Agent': soundcloud.USER_AGENT} (fake_get.expects_call().with_args(expected_url, headers=headers, allow_redirects=True).returns( MockResponse("{}"))) client.get('tracks', limit=5)
def test_disabling_ssl_verification(fake_get): """We should be able to disable ssl verification when we are in dev mode""" client = soundcloud.Client(client_id='foo', host='api.soundcloud.dev', verify_ssl=False) expected_url = '%s?%s' % (client._resolve_resource_name('tracks'), urlencode({ 'limit': 5, 'client_id': 'foo' })) headers = {'User-Agent': soundcloud.USER_AGENT} (fake_get.expects_call().with_args(expected_url, headers=headers, verify=False, allow_redirects=True).returns( MockResponse("{}"))) client.get('tracks', limit=5)
def test_json_object(): """Verify that a json object is wrapped in a Resource object.""" resource = wrapped_resource(MockResponse(json.dumps({'foo': 'bar'}))) assert isinstance(resource, Resource) eq_('bar', resource.foo)
def positive_refresh_token_response(fake_http_request): response = MockResponse( '{"access_token":"access-2345","expires_in":21599,"scope":"*",' + '"refresh_token":"refresh-2345"}') fake_http_request.expects_call().returns(response) yield
def expiring_token_response(fake_http_request): response = MockResponse( '{"access_token":"access-1234","expires_in":12345,"scope":"*",' + '"refresh_token":"refresh-1234"}') fake_http_request.expects_call().returns(response) yield
def non_expiring_token_response(fake_http_request): response = MockResponse( '{"access_token":"access-1234","scope":"non-expiring"}') fake_http_request.expects_call().returns(response) yield
def response_status(fake_http_request, status): response = MockResponse('{}', status_code=status) fake_http_request.expects_call().returns(response) yield
def test_non_ascii_data(fake_put): """Test that non-ascii characters are accepted.""" client = soundcloud.Client(client_id='foo', client_secret='foo') title = u'Föo Baß' fake_put.expects_call().returns(MockResponse("{}")) client.put('/tracks', track={'title': title})
def response_status(fake_http_request, status): response = MockResponse('{}', status_code=status) response.raw = MockRaw() fake_http_request.expects_call().returns(response) yield