Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

Commit

Permalink
Only submit_to_dspace once
Browse files Browse the repository at this point in the history
closes #69
  • Loading branch information
JPrevost committed Oct 6, 2015
1 parent a704beb commit 76686ef
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
32 changes: 20 additions & 12 deletions kepler/tasks.py
Expand Up @@ -60,18 +60,26 @@ def index_geotiff(job, data):


def submit_to_dspace(job, data):
username = current_app.config['SWORD_SERVICE_USERNAME']
password = current_app.config['SWORD_SERVICE_PASSWORD']
pkg = sword.SWORDPackage(uuid=job.item.uri)
tiff = get_geotiff(data)
pkg.datafiles.append(tiff)
pkg.metadata = _fgdc_to_mods(get_fgdc(data))
with tempfile.NamedTemporaryFile(suffix='.zip') as fp:
pkg.write(fp)
handle = sword.submit(current_app.config['SWORD_SERVICE_URL'], fp.name,
auth=(username, password))
job.item.handle = handle
db.session.commit()
"""Upload GeoTIFF to DSpace.
.. note:: only runs if `Item.handle` has not previously been set.
:param job: :class:`~kepler.models.Job`
:param data: absolute path to bag containing GeoTIFF
"""
if not job.item.handle:
username = current_app.config['SWORD_SERVICE_USERNAME']
password = current_app.config['SWORD_SERVICE_PASSWORD']
pkg = sword.SWORDPackage(uuid=job.item.uri)
tiff = get_geotiff(data)
pkg.datafiles.append(tiff)
pkg.metadata = _fgdc_to_mods(get_fgdc(data))
with tempfile.NamedTemporaryFile(suffix='.zip') as fp:
pkg.write(fp)
handle = sword.submit(current_app.config['SWORD_SERVICE_URL'], fp.name,
auth=(username, password))
job.item.handle = handle
db.session.commit()


def upload_shapefile(job, data):
Expand Down
14 changes: 14 additions & 0 deletions tests/test_tasks.py
Expand Up @@ -16,6 +16,7 @@
@pytest.fixture
def job():
j = Mock()
j.item.handle = None
j.item.uri = 'urn:uuid:c8921f5a-eac7-509b-bac5-bd1b2cb202dc'
j.item.access = 'public'
return j
Expand Down Expand Up @@ -55,6 +56,19 @@ def testSubmitToDspaceAddsHandleToItem(job, bag_tif):
assert job.item.handle == 'foobar'


def testSubmitToDspaceWithExistingHandleDoesNotSubmit(job, bag_tif):
job.item.handle = "popcorn"
with patch('kepler.tasks.sword.submit') as mock:
submit_to_dspace(job, bag_tif)
assert not mock.called


def testSubmitToDspaceWithExistingHandleDoesNotChangeHandle(job, bag_tif):
job.item.handle = "popcorn"
submit_to_dspace(job, bag_tif)
assert job.item.handle == "popcorn"


def testUploadShapefileCallsUploadWithMimetype(job, bag, shapefile):
with patch('kepler.tasks._upload_to_geoserver') as mock:
upload_shapefile(job, bag)
Expand Down

0 comments on commit 76686ef

Please sign in to comment.