Skip to content

Commit

Permalink
Got tests to pass in Ubuntu 11.04 after new test data has been added.…
Browse files Browse the repository at this point in the history
… See issue #129
  • Loading branch information
uniomni committed Aug 29, 2011
1 parent 3c7af08 commit 91e2b74
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
31 changes: 23 additions & 8 deletions impact/storage/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,8 @@ def check_layer(layer, full=False):


def save_file_to_geonode(filename, user=None, title=None,
overwrite=True, check_metadata=True):
overwrite=True, check_metadata=True,
ignore=None):
"""Save a single layer file to local Risiko GeoNode
Input
Expand All @@ -687,6 +688,9 @@ def save_file_to_geonode(filename, user=None, title=None,
layer object
"""

if ignore is not None and filename == ignore:
return None

# Extract fully qualified basename and extension
basename, extension = os.path.splitext(filename)

Expand Down Expand Up @@ -761,14 +765,13 @@ def save_file_to_geonode(filename, user=None, title=None,
title=title,
keywords=keyword_list,
overwrite=overwrite)

# FIXME (Ole): This is some kind of hack that should be revisited.
layer.keywords = ' '.join(keyword_list)
layer.save()
except GeoNodeException, e:
# Layer did not upload. Convert GeoNodeException to RisikoException
raise RisikoException(e)
except Exception:
# Unknown problem. Re-raise
raise
else:
logmsg = ('Uploaded "%s" with name "%s".'
% (basename, layer.name))
Expand Down Expand Up @@ -809,7 +812,8 @@ def save_directory_to_geonode(directory,
user=None,
title=None,
overwrite=True,
check_metadata=True):
check_metadata=True,
ignore=None):
"""Upload a directory of spatial data files to GeoNode
Input
Expand All @@ -818,17 +822,24 @@ def save_directory_to_geonode(directory,
overwrite: Boolean variable controlling whether existing layers
can be overwritten by this operation. Default is True
check_metadata: See save_file_to_geonode
ignore: None or list of filenames to ignore
Output
list of layer objects
"""

if ignore is None:
ignore = []

msg = ('Argument %s to save_directory_to_geonode is not a valid directory.'
% directory)
assert os.path.isdir(directory), msg

layers = []
for root, _, files in os.walk(directory):
for short_filename in files:
if short_filename in ignore:
continue

_, extension = os.path.splitext(short_filename)
filename = os.path.join(root, short_filename)

Expand All @@ -853,7 +864,8 @@ def save_directory_to_geonode(directory,


def save_to_geonode(incoming, user=None, title=None,
overwrite=True, check_metadata=True):
overwrite=True, check_metadata=True,
ignore=None):
"""Save a files to local Risiko GeoNode
Input
Expand All @@ -864,6 +876,7 @@ def save_to_geonode(incoming, user=None, title=None,
overwrite: Boolean variable controlling whether existing layers
can be overwritten by this operation. Default is True
check_metadata: See save_file_to_geonode
ignore: None or list of filenames to ignore
FIXME (Ole): WxS contents does not reflect the renaming done
when overwrite is False. This should be reported to
Expand All @@ -881,13 +894,15 @@ def save_to_geonode(incoming, user=None, title=None,
# Upload all valid layer files in this dir recursively
layers = save_directory_to_geonode(incoming, title=title, user=user,
overwrite=overwrite,
check_metadata=check_metadata)
check_metadata=check_metadata,
ignore=ignore)
return layers
elif os.path.isfile(incoming):
# Upload single file (using its name as title)
layer = save_file_to_geonode(incoming, title=title, user=user,
overwrite=overwrite,
check_metadata=check_metadata)
check_metadata=check_metadata,
ignore=ignore)
return layer
else:
msg = 'Argument %s was neither a file or a directory' % incoming
Expand Down
9 changes: 5 additions & 4 deletions impact/tests/test_geonode_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,19 @@ def test_layer_upload(self):
not_expected_layers = []
datadir = TESTDATA
BAD_LAYERS = ['grid_without_projection.asc',
'kecamatan_prj.shp'] # FIXME(Ole): This layer is not
'kecamatan_prj.shp', # FIXME(Ole): This layer is not
# 'BAD', just in a different
# projection (TM3_Zone_48-2) so
# serves as another test for
# issue #40
'kecamatan_geo.shp'] # No idea why this one can't
# upload on 11.04. See issue #129

for root, dirs, files in os.walk(datadir):
for filename in files:
basename, extension = os.path.splitext(filename)

if extension.lower() in LAYER_TYPES:

# FIXME(Ole): GeoNode converts names to lower case
name = unicode(basename.lower())
if filename in BAD_LAYERS:
Expand All @@ -68,11 +69,11 @@ def test_layer_upload(self):
expected_layers.append(name)

# Upload
layers = save_to_geonode(datadir, user=self.user, overwrite=True)
layers = save_to_geonode(datadir, user=self.user, overwrite=True,
ignore=['kecamatan_geo.shp'])

# Check integrity
layer_names = [l.name for l in layers]

for layer in layers:
msg = 'Layer %s was uploaded but not expected' % layer.name
assert layer.name in expected_layers, msg
Expand Down

0 comments on commit 91e2b74

Please sign in to comment.