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

Commit

Permalink
Add tests between indicator and serializer logic
Browse files Browse the repository at this point in the history
  • Loading branch information
fungjj92 committed Jan 20, 2017
1 parent d8e06ff commit a3e5e99
Showing 1 changed file with 32 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,36 @@ 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()))


class PercentileIndicatorParamsTestCase(IndicatorParamsTestCase):

def setUp(self):
Expand Down

0 comments on commit a3e5e99

Please sign in to comment.