Skip to content
This repository has been archived by the owner on Aug 28, 2023. It is now read-only.

Commit

Permalink
Merge pull request #237 from azavea/feature/aggtests
Browse files Browse the repository at this point in the history
Add tests between indicator and serializer logic
  • Loading branch information
fungjj92 authored Jan 23, 2017
2 parents cb63c0e + 3787947 commit 0f15658
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from django.core.exceptions import ValidationError
from django.test import TestCase

from climate_data.tests.mixins import ClimateDataSetupMixin
from indicators import indicators
from indicators.params import IndicatorParam, IndicatorParams, Percentile99IndicatorParams
from indicators.utils import merge_dicts
from indicators.validators import ChoicesValidator
Expand Down Expand Up @@ -94,6 +96,37 @@ def test_validate_valid_optional_defaults(self):
indicator_params.time_aggregation.default)


class IndicatorParamsBeforeSerializerTestCase(ClimateDataSetupMixin, TestCase):

def setUp(self):
super(IndicatorParamsBeforeSerializerTestCase, self).setUp()

def test_parsing_single_agg_string_input(self):
""" tests a string input of single aggregation method """

self._test_parsing_agg_string_input('99th')

def test_parsing_multi_agg_string_input(self):
""" tests a comma-separated string input of multi aggregation methods """

self._test_parsing_agg_string_input('avg,99th,stdev')

def _test_parsing_agg_string_input(self, agg_input):
""" method should ensure a csv string input for the aggregation param gets
parsed into a list before serialization
"""
parameters = merge_dicts({}, {'agg': agg_input})
# test string parsing on an arbitrary indicator
indicator = indicators.TotalPrecipitation(self.city1, self.rcp45, parameters=parameters)
results = indicator.calculate()

split_input = agg_input.split(',')
for idx in results:
# only need to check keys from one result since all results will have identical keys
return self.assertTrue(set(split_input) == set(results[idx].keys()),
msg="Agg inputs improperly formatted or parsed")


class PercentileIndicatorParamsTestCase(IndicatorParamsTestCase):

def setUp(self):
Expand Down

0 comments on commit 0f15658

Please sign in to comment.