Skip to content

Commit

Permalink
#8 fix validate_uri; add env to travis
Browse files Browse the repository at this point in the history
  • Loading branch information
akorosov committed Jun 18, 2018
1 parent 7f892d4 commit ba6d44e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 20 deletions.
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
language: python
python:
- "2.7"
sudo: false

before_install:
Expand All @@ -9,11 +7,12 @@ before_install:
- export PATH=$HOME/miniconda/bin:$PATH

env:
- DJANGO_VERSION=1.11.7
- PYTHON_VERSION=2.7 DJANGO_VERSION=1.11.7
- PYTHON_VERSION=3.6 DJANGO_VERSION=2.0.6

script:
- conda update -q conda --yes
- conda create -n test_env python=2 django=1.11.7 gdal mock nansat pythesint -c conda-forge --yes
- conda create -n test_env python=$PYTHON_VERSION django=$DJANGO_VERSION gdal mock nansat pythesint -c conda-forge --yes
- source activate test_env
- pip install https://github.com/ghaering/pysqlite/archive/2.8.1.tar.gz
- pip install django-forms-bootstrap
Expand Down
2 changes: 1 addition & 1 deletion geospaas/nansat_ingestor/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def setUp(self):
def tearDown(self):
self.patcher.stop()

class TestDataset(BasetForTests):
class TestDatasetManager(BasetForTests):
def test_getorcreate_localfile(self):
uri = 'file://localhost/some/folder/filename.ext'
ds0, cr0 = Dataset.objects.get_or_create(uri)
Expand Down
33 changes: 19 additions & 14 deletions geospaas/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
try:
from urlparse import urlparse
except ImportError:
import urllib.parse as urlparse
from urllib.parse import urlparse

from django.conf import settings

Expand Down Expand Up @@ -42,19 +42,24 @@ def product_path(module, filename):
return path(module, filename, settings.PRODUCTS_ROOT)

def validate_uri(uri):
validation_result = False
request = urllib2.Request(uri)
try:
if URLLIB_VERSION == 2:
request = urllibN.Request(uri)
else:
request = urllibN.PoolManager().request('GET', uri)
response.close()
validation_result = True
except IOError as e:
if len(e.args)>1 and e.args[1]==u'Is a directory':
validation_result = True
return validation_result
""" Validation of URI:
URI should be either: file://localhost/some/path/filename.ext
or accessible: http://www.eee.rrr/some/path
If URI is not valid, the function rasies a ValueError or urrlib error
"""
uri_parts = urlparse(uri)
if uri_parts.scheme == 'file' and uri_parts.netloc == 'localhost' and len(uri_parts.path) > 0:

This comment has been minimized.

Copy link
@mortenwh

mortenwh Oct 24, 2018

Contributor

@akorosov what were you thinking about here? It causes all ingestion of remote data to fail.... I am reverting this change. Also, I don't agree in making utils a directory - especially since it resulted in failing code. The least that should be done in such a case is to make a pull request.

return True
else:
raise ValueError('Invalid URI: %s' % uri)

if URLLIB_VERSION == 2:
request = urllibN.Request(uri)
else:
request = urllibN.PoolManager().request('GET', uri)

return True

def nansat_filename(uri):
# Check if data should be read as stream or as file? Or just:
Expand Down
2 changes: 1 addition & 1 deletion runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
django.setup()
TestRunner = get_runner(settings)
test_runner = TestRunner(verbosity=1, interactive=True)
failures = test_runner.run_tests(["geospaas.catalog"])
failures = test_runner.run_tests(["geospaas"])
sys.exit(bool(failures))

0 comments on commit ba6d44e

Please sign in to comment.