Skip to content

Commit

Permalink
Updated tests to fit to django-raster 0.3, added coverage to tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowcap committed Oct 27, 2016
1 parent e3aceff commit c0e884f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ language: python
python:
- '2.7'
- '3.4'
- '3.5'

sudo: false

Expand All @@ -28,8 +29,12 @@ install:
- pip install django-filter==0.10.0
- pip install flake8==2.5.0
- pip install isort==4.2.2
- pip install coverage==4.2
- pip install coveralls

script: django-admin.py test
script: coverage run --include="raster-aggregation/*" $(which django-admin.py) test

after_success: coveralls

notifications:
email: false
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
install_requires=[
'Django>=1.9',
'celery>=3.1.18',
'django-raster>=0.1.6',
'django-raster>=0.3',
'django-filter>=0.10.0',
'djangorestframework>=3.3.3',
'djangorestframework-gis>=0.9',
Expand Down
12 changes: 7 additions & 5 deletions tests/aggregation_testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import tempfile

import numpy
from raster.models import Legend, LegendEntry, LegendSemantics, RasterLayer
from raster.models import Legend, LegendEntry, LegendEntryOrder, LegendSemantics, RasterLayer

from django.core.files import File
from django.test import TestCase
Expand All @@ -21,8 +21,8 @@ def setUp(self):
)
)

self.rasterfile = File(open(os.path.join(self.pwd, 'data/raster.tif.zip'), 'rb'))
shapefile = File(open(os.path.join(self.pwd, 'data/shapefile.zip'), 'rb'))
self.rasterfile = File(open(os.path.join(self.pwd, 'data/raster.tif.zip'), 'rb'), name='raster.tif.zip')
shapefile = File(open(os.path.join(self.pwd, 'data/shapefile.zip'), 'rb'), name='shapefile.zip')

self.media_root = tempfile.mkdtemp()

Expand Down Expand Up @@ -63,9 +63,11 @@ def setUp(self):
ent3 = LegendEntry.objects.create(semantics=sem3, expression='(x >= 2) & (x < 5)', color='#123456')
# Create legends
self.legend_float = Legend.objects.create(title='Float key legend')
self.legend_float.entries.add(ent1, ent2)
LegendEntryOrder.objects.create(legend=self.legend_float, legendentry=ent1, code='1')
LegendEntryOrder.objects.create(legend=self.legend_float, legendentry=ent2, code='2')

self.legend_exp = Legend.objects.create(title='Expression key legend')
self.legend_exp.entries.add(ent3)
LegendEntryOrder.objects.create(legend=self.legend_exp, legendentry=ent3, code='1')

# Compute expected totals from numpy value count
self.expected = {}
Expand Down
6 changes: 2 additions & 4 deletions tests/test_aggregation_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,10 @@ def test_aggregation_api_count_minmaxzoom_parameter(self):
name='Raster data',
description='Second small raster for testing',
datatype='ca',
nodata='0',
nodata=0,
max_zoom=3,
rasterfile=self.rasterfile
)
rasterlayer_low_res.metadata.max_zoom = 3
rasterlayer_low_res.metadata.save()
rasterlayer_low_res.save()
# Setup request with fromula that will multiply the rasterlayer by itself
response = self.client.get(self.url + '?layers=a={0},b={1}&formula=a*b&minmaxzoom'.format(self.rasterlayer.id, rasterlayer_low_res.id))
self.assertEqual(response.status_code, 200)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_aggregation_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_count_values_for_st_petersburg(self):
result = {k: float(v) for k, v in result.value.items()}
self.assertEqual(
result,
{'1': 545, '2': 56, '3': 4094, '4': 30970, '8': 1260, '9': 2817, '15': 734}
{'1': 605, u'15': 747, '2': 56, '3': 4115, '4': 31362, '8': 1284, '9': 2879}
)

def test_count_values_for_coverall(self):
Expand Down

0 comments on commit c0e884f

Please sign in to comment.