Пример #1
0
    def test_annual_rainfall_unit_conversion(self):
        rainfall_unit_key, rainfall_unit = get_value_display_attr(
            self.instance, 'greenInfrastructure', 'rainfall', 'units')
        self.assertEqual(rainfall_unit, 'in')
        __, __, unit_key = dotted_split(rainfall_unit_key, 3, maxsplit=2)

        self.assertEqual(rainfall_unit, 'in')

        config_key = 'annual_rainfall_inches'
        request_key = 'instance.config.annual_rainfall_inches'
        updates = {request_key: 10}
        json_updates = json.dumps(updates)
        request = make_request(method='PUT',
                               body=json_updates,
                               user=self.commander)

        green_infrastructure(request, self.instance)

        self.assertEqual(self.instance.config[config_key], 10.0)

        self.instance.config[unit_key] = 'cm'

        config_key = 'annual_rainfall_inches'
        request_key = 'instance.config.{}'.format(config_key)
        updates = {request_key: 25.4}
        json_updates = json.dumps(updates)
        request = make_request(method='PUT',
                               body=json_updates,
                               user=self.commander)

        green_infrastructure(request, self.instance)

        self.assertEqual(self.instance.config[config_key], 10.0)
Пример #2
0
    def test_map_feature_inapplicable_config_validation(self):
        self._activate('RainBarrel')
        request_key = 'instance.config.map_feature_config.RainBarrel'\
                      '.should_show_eco'
        updates = {request_key: True}
        json_updates = json.dumps(updates)
        request = make_request(method='PUT',
                               body=json_updates,
                               user=self.commander)

        with self.assertRaises(ValidationError):
            green_infrastructure(request, self.instance)
Пример #3
0
    def test_add_map_feature_types(self):
        mft = 'Bioswale'
        key = 'map_feature_types'
        updates = {'instance.config.{}.{}'.format(key, mft): True}

        json_updates = json.dumps(updates)
        request = make_request(method='PUT',
                               body=json_updates,
                               user=self.commander)

        green_infrastructure(request, self.instance)

        map_feature_types = self.instance.config.get(key)
        self.assertGreater(len(map_feature_types), 0)
        self.assertIn(mft, map_feature_types)
Пример #4
0
    def test_show_eco_without_constant(self):
        self._activate('Bioswale')
        self.instance.annual_rainfall_inches = 8.0
        Bioswale.set_config_property(self.instance, 'diversion_rate', None)

        request_key = 'instance.config.map_feature_config.Bioswale'\
                      '.should_show_eco'
        updates = {request_key: True}
        json_updates = json.dumps(updates)
        request = make_request(method='PUT',
                               body=json_updates,
                               user=self.commander)

        with self.assertRaises(ValidationError):
            green_infrastructure(request, self.instance)
Пример #5
0
    def test_annual_rainfall_config_validation(self):
        request_key = 'instance.config.annual_rainfall_inches'
        updates = {request_key: 'x'}
        json_updates = json.dumps(updates)
        request = make_request(method='PUT',
                               body=json_updates,
                               user=self.commander)

        with self.assertRaises(ValidationError):
            green_infrastructure(request, self.instance)

        updates[request_key] = '-10'
        json_updates = json.dumps(updates)
        request = make_request(method='PUT',
                               body=json_updates,
                               user=self.commander)

        with self.assertRaises(ValidationError):
            green_infrastructure(request, self.instance)

        updates[request_key] = '10'
        json_updates = json.dumps(updates)
        request = make_request(method='PUT',
                               body=json_updates,
                               user=self.commander)

        green_infrastructure(request, self.instance)

        self.assertEqual(self.instance.annual_rainfall_inches, 10.0)
Пример #6
0
    def test_remove_map_feature_types(self):
        mft = 'Bioswale'
        key = 'map_feature_types'
        request_key = 'instance.config.{}.{}'.format(key, mft)
        updates = {request_key: True}

        json_updates = json.dumps(updates)
        request = make_request(method='PUT',
                               body=json_updates,
                               user=self.commander)

        green_infrastructure(request, self.instance)

        updates[request_key] = False

        json_updates = json.dumps(updates)
        request = make_request(method='PUT',
                               body=json_updates,
                               user=self.commander)

        green_infrastructure(request, self.instance)
        map_feature_types = self.instance.config.get(key)
        self.assertNotIn(mft, map_feature_types)
Пример #7
0
    def test_map_feature_applicable_constant_validation(self):
        self._activate('Bioswale')

        request_key = 'instance.config.map_feature_config.Bioswale'\
                      '.diversion_rate'
        updates = {request_key: 'x'}
        json_updates = json.dumps(updates)
        request = make_request(method='PUT',
                               body=json_updates,
                               user=self.commander)

        with self.assertRaises(ValidationError):
            green_infrastructure(request, self.instance)

        updates = {request_key: -.166}
        json_updates = json.dumps(updates)
        request = make_request(method='PUT',
                               body=json_updates,
                               user=self.commander)

        with self.assertRaises(ValidationError):
            green_infrastructure(request, self.instance)

        updates = {request_key: 1.66}
        json_updates = json.dumps(updates)
        request = make_request(method='PUT',
                               body=json_updates,
                               user=self.commander)

        with self.assertRaises(ValidationError):
            green_infrastructure(request, self.instance)

        updates = {request_key: .166}
        json_updates = json.dumps(updates)
        request = make_request(method='PUT',
                               body=json_updates,
                               user=self.commander)

        green_infrastructure(request, self.instance)

        bioswale_config = Bioswale.get_config(self.instance)
        self.assertEqual(bioswale_config.get('diversion_rate', None), 0.166)