Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]Add integration tests #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.pyc
*~
*.egg-info
*.pytest_cache
8 changes: 5 additions & 3 deletions girder_raster_tasks/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@
import rasterio
from rasterio.enums import Resampling
from rasterio.warp import calculate_default_transform, reproject
from rasterio.tools.mask import mask
from rasterio.mask import mask
from shapely.ops import transform
from girder_worker.app import app
from girder_worker.utils import girder_job
from shapely.geometry import shape, mapping


def reprojectGeometry(geometry, projString):
inProj = pyproj.Proj('+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs ')
outProj = pyproj.Proj(projString)
project = partial(
pyproj.transform,
pyproj.Proj(init='epsg:4326'),
pyproj.Proj(projString)
inProj,
outProj
)
transformed = mapping(transform(project, shape(geometry)))

Expand Down
Binary file added tests/data/chicago.tif
Binary file not shown.
27 changes: 27 additions & 0 deletions tests/data/geometry.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"type": "Polygon",
"coordinates": [
[
[
-87.62412071228027,
41.88406793446202
],
[
-87.59622573852539,
41.88406793446202
],
[
-87.59622573852539,
41.902788098873515
],
[
-87.62412071228027,
41.902788098873515
],
[
-87.62412071228027,
41.88406793446202
]
]
]
}
Empty file added tests/integration/__init__.py
Empty file.
91 changes: 91 additions & 0 deletions tests/integration/test_tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import json
import os
import time
import pytest


def _waitForJob(gc, jobId):
# Wait for the clip job to be completed
timeout = 10
while timeout > 0:
time.sleep(1)
job = gc.get('job/{}'.format(jobId))
if job['status'] == 3:
timeout = 0
else:
timeout -= 1


def _uploadFile(gc, admin, tiff):
public = gc.resourceLookup('/user/{}/Public'.format(admin['login']))
size = os.stat(tiff).st_size
with open(tiff, 'rb') as f:
uploaded = gc.uploadFile(public['_id'],
f,
name=os.path.basename(tiff),
size=size,
parentType='folder')

return uploaded


@pytest.mark.plugin('resonantgeodata')
@pytest.mark.plugin('worker')
def test_clip_task(admin, db, liveServer, fsAssetstore):
liveServer.authenticate(admin['login'], 'password')
# Set worker url
liveServer.put('system/setting', parameters={'key': 'worker.api_url',
'value': liveServer.urlBase[:-1]})

public = liveServer.resourceLookup('/user/{}/Public'.format(admin['login']))
sampleTiff = 'tests/data/chicago.tif'
output = 'clipped.tif'
uploaded = _uploadFile(liveServer, admin, sampleTiff)
geometry = 'tests/data/geometry.json'

with open(geometry) as f:
data = json.load(f)

job = liveServer.get('raster/clip', parameters={
'itemId': uploaded['itemId'],
'geometry': json.dumps(data),
'name': output,
'folderId': public['_id']
})

_waitForJob(liveServer, job['_id'])
resultFile = liveServer.get('resource/search', parameters={
'q': output,
'types': '["file"]'
})

assert resultFile['file'][0]['size'] > 0


@pytest.mark.plugin('resonantgeodata')
@pytest.mark.plugin('worker')
def test_reproject_task(admin, db, liveServer, fsAssetstore):
liveServer.authenticate(admin['login'], 'password')
# Set worker url
liveServer.put('system/setting', parameters={'key': 'worker.api_url',
'value': liveServer.urlBase[:-1]})

public = liveServer.resourceLookup('/user/{}/Public'.format(admin['login']))
sampleTiff = 'tests/data/chicago.tif'
output = 'reprojected.tif'
uploaded = _uploadFile(liveServer, admin, sampleTiff)

job = liveServer.get('raster/reproject', parameters={
'itemId': uploaded['itemId'],
'crs': '+proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +a=6378137 +b=6378137 +units=m +no_defs ',
'name': output,
'folderId': public['_id']
})

_waitForJob(liveServer, job['_id'])
resultFile = liveServer.get('resource/search', parameters={
'q': output,
'types': '["file"]'
})

assert resultFile['file'][0]['size'] > 0
Empty file added tests/unit/__init__.py
Empty file.