def test_build_url_with_non_existant_endpoint_errors(): """ Supplying _build_url with an endpoint that does not exist in the endpoints dictionary should result in a ValueError. """ api = ScrapydAPI(HOST_URL) with pytest.raises(ValueError): api._build_url('does-not-exist')
def test_build_url_with_default_endpoints(): """ Absolute URL constructor should form correct URL when the client is relying on the default endpoints. """ api = ScrapydAPI('http://localhost') url = api._build_url(ADD_VERSION_ENDPOINT) assert url == 'http://localhost/addversion.json' # Test trailing slash on target. api = ScrapydAPI('http://localhost/') url = api._build_url(ADD_VERSION_ENDPOINT) assert url == 'http://localhost/addversion.json'
def test_build_url_with_custom_endpoints(): """ The absolute URL constructor should correctly form URL when the client has custom endpoints passed in. """ custom_endpoints = {ADD_VERSION_ENDPOINT: '/addversion-custom.json'} api = ScrapydAPI('http://localhost', endpoints=custom_endpoints) url = api._build_url(ADD_VERSION_ENDPOINT) assert url == 'http://localhost/addversion-custom.json' # Test trailing slash on target. api = ScrapydAPI('http://localhost/', endpoints=custom_endpoints) url = api._build_url(ADD_VERSION_ENDPOINT) assert url == 'http://localhost/addversion-custom.json' # Test that endpoints that were not overridden by the custom_endpoints # still work as the defaults. url = api._build_url(CANCEL_ENDPOINT) assert url == 'http://localhost/cancel.json'
def test_build_url_with_custom_endpoints(): """ The absolute URL constructor should correctly form URL when the client has custom endpoints passed in. """ custom_endpoints = { ADD_VERSION_ENDPOINT: '/addversion-custom.json' } api = ScrapydAPI('http://localhost', endpoints=custom_endpoints) url = api._build_url(ADD_VERSION_ENDPOINT) assert url == 'http://localhost/addversion-custom.json' # Test trailing slash on target. api = ScrapydAPI('http://localhost/', endpoints=custom_endpoints) url = api._build_url(ADD_VERSION_ENDPOINT) assert url == 'http://localhost/addversion-custom.json' # Test that endpoints that were not overridden by the custom_endpoints # still work as the defaults. url = api._build_url(CANCEL_ENDPOINT) assert url == 'http://localhost/cancel.json'