Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_make_valid_url(self):
url = ('http://goodtables.okfnlabs.org/reports?'
'data_url=http://data.defra.gov.uk/ops/government_procurement_card/over_£500_GPC_apr_2013.csv')
assertion = '£' not in utilities.helpers.make_valid_url(url)
self.assertTrue(assertion)
def test_make_valid_url_urlencode(self):
url = 'http://data.defra.gov.uk/ops/government_procurement_card/over_£500_GPC_apr_2013.csv'
valid_url = 'http://data.defra.gov.uk/ops/government_procurement_card/over_%c2%a3500_GPC_apr_2013.csv'
self.assertEqual(utilities.helpers.make_valid_url(url), valid_url)
def test_make_valid_url_dont_break_query(self):
url = 'http://next.openspending.org/fdp-adapter/convert?url=https%3A%2F%2Fraw.githubusercontent.com%2Fkravets-levko%2Fdata%2Fmaster%2Ftest.xlsx.csv'
self.assertEqual(utilities.helpers.make_valid_url(url), url)
def test_make_valid_composed_url(self):
url = ('http://webarchive.nationalarchives.gov.uk/+/'
'http://www.nio.gov.uk/transaction_spend_data_august_10_northern_ireland_office.xls')
assertion = '+' in utilities.helpers.make_valid_url(url)
self.assertTrue(assertion)
def _stream_from_url(self, url):
"""Return a seekable and readable stream from a URL."""
stream = io.BufferedRandom(io.BytesIO())
valid_url = helpers.make_valid_url(url)
try:
document = compat.urlopen(valid_url)
except compat.HTTPError as e:
raise exceptions.DataSourceHTTPError(status=e.getcode())
stream.write(document.read())
stream.seek(0)
return stream