예제 #1
0
    def test_form_count_under_limit(self):
        """There should be at least two forms"""
        data = {
            'goal_set-TOTAL_FORMS': '1',
            'goal_set-INITIAL_FORMS': '0',
            'goal_set-0-description': 'Minimo',
            'goal_set-0-value': '5',
            'goal_set-0-percentage': '80',
        }

        formset = GoalFormSet(data, instance=self.objective)

        self.assertFalse(formset.is_valid())
예제 #2
0
    def test_unique_goal_value(self):
        """Goal values should be unique"""
        data = {
            'goal_set-TOTAL_FORMS': '2',
            'goal_set-INITIAL_FORMS': '0',
            'goal_set-0-description': 'Minimo',
            'goal_set-0-value': '5',
            'goal_set-0-percentage': '80',
            'goal_set-1-description': 'Medio',
            'goal_set-1-value': '5',
            'goal_set-1-percentage': '100',
        }

        formset = GoalFormSet(data, instance=self.objective)

        self.assertFalse(formset.is_valid())
예제 #3
0
    def test_unsorted_percentage_causes_no_effect(self):
        """Percentages should be auto-sorted in order to determine whether values are decreasing"""
        data = {
            'goal_set-TOTAL_FORMS': '3',
            'goal_set-INITIAL_FORMS': '0',
            'goal_set-0-description': 'Maximo',
            'goal_set-0-value': '7',
            'goal_set-0-percentage': '80',
            'goal_set-1-description': 'Minimo',
            'goal_set-1-value': '5',
            'goal_set-1-percentage': '100',
            'goal_set-2-description': 'Medio',
            'goal_set-2-value': '6',
            'goal_set-2-percentage': '90',
        }

        formset = GoalFormSet(data, instance=self.objective)

        self.assertTrue(formset.is_valid())
예제 #4
0
    def test_decreasing_values_are_valid(self):
        """Values that are strictly decreasing should be valid"""
        data = {
            'goal_set-TOTAL_FORMS': '3',
            'goal_set-INITIAL_FORMS': '0',
            'goal_set-0-description': 'Maximo',
            'goal_set-0-value': '7',
            'goal_set-0-percentage': '80',
            'goal_set-1-description': 'Medio',
            'goal_set-1-value': '6',
            'goal_set-1-percentage': '90',
            'goal_set-2-description': 'Minimo',
            'goal_set-2-value': '5',
            'goal_set-2-percentage': '100',
        }

        formset = GoalFormSet(data, instance=self.objective)

        self.assertTrue(formset.is_valid())
예제 #5
0
    def test_non_decreasing_values_in_decreasing_set_are_not_valid(self):
        """Values that are not strictly decreasing on a decreasing set are invalid"""
        data = {
            'goal_set-TOTAL_FORMS': '3',
            'goal_set-INITIAL_FORMS': '0',
            'goal_set-0-description': 'Uno',
            'goal_set-0-value': '5',
            'goal_set-0-percentage': '80',
            'goal_set-1-description': 'Dos',
            'goal_set-1-value': '4',
            'goal_set-1-percentage': '90',
            'goal_set-2-description': 'Tres',
            'goal_set-2-value': '6',
            'goal_set-2-percentage': '100',
        }

        formset = GoalFormSet(data, instance=self.objective)

        self.assertFalse(formset.is_valid())