Esempio n. 1
0
    def test_validate_changed_denominator_ratio_in_amendment(self):
        """Not allowed to change denominator if in amendment mode
        and display_type is ratio
        """
        self.intervention.in_amendment = True
        self.intervention.save()
        self.indicator.display_type = IndicatorBlueprint.RATIO
        self.indicator.save()
        self.applied_indicator.indicator = self.indicator
        self.applied_indicator.save()

        self.data["cluster_indicator_id"] = "404"
        self.data["target"] = {'d': 1, 'v': 2}
        self.intervention.flat_locations.add(self.location)
        self.assertTrue(self.intervention.in_amendment)
        self.assertEqual(self.intervention.status, Intervention.ACTIVE)
        self.assertEqual(self.applied_indicator.indicator.display_type,
                         IndicatorBlueprint.RATIO)
        serializer = AppliedIndicatorSerializer(
            data=self.data, instance=self.applied_indicator)
        self.assertFalse(serializer.is_valid())
        self.assertEqual(
            serializer.errors, {
                "non_field_errors": [
                    'You cannot change the Indicator Target Denominator if PD/SSFA is not in status Draft or Signed'
                ]
            })
Esempio n. 2
0
 def test_validate_value_numbers(self):
     self.data["target"] = {"d": 123, "v": "$321"}
     self.data["baseline"] = {"d": "wrong", "v": 321}
     self.intervention.flat_locations.add(self.location)
     serializer = AppliedIndicatorSerializer(data=self.data)
     self.assertFalse(serializer.is_valid())
     self.assertIn("target", serializer.errors)
     self.assertIn("baseline", serializer.errors)
Esempio n. 3
0
 def test_validate_indicator_used(self):
     """CHeck that is indicator already used we fail validation"""
     self.applied_indicator.indicator = self.indicator
     self.applied_indicator.save()
     serializer = AppliedIndicatorSerializer(data=self.data)
     self.assertFalse(serializer.is_valid())
     self.assertEqual(serializer.errors, {"non_field_errors": [
         'This indicator is already being monitored for this Result'
     ]})
Esempio n. 4
0
 def test_validate_invalid_section(self):
     """If sector already set on applied indicator then fail validation"""
     self.data["section"] = SectionFactory().pk
     serializer = AppliedIndicatorSerializer(data=self.data)
     self.assertFalse(serializer.is_valid())
     self.assertEqual(serializer.errors, {"non_field_errors": [
         'This indicator can only have a section that was '
         'previously saved on the intervention'
     ]})
Esempio n. 5
0
 def test_validate_invalid_location(self):
     """If location is not related to intervention, then fail validation"""
     self.intervention.flat_locations.remove(self.location)
     serializer = AppliedIndicatorSerializer(data=self.data)
     self.assertFalse(serializer.is_valid())
     self.assertEqual(serializer.errors, {"non_field_errors": [
         'This indicator can only have locations that were '
         'previously saved on the intervention'
     ]})
Esempio n. 6
0
 def test_create(self):
     applied_qs = AppliedIndicator.objects.filter(
         lower_result__pk=self.lower_result.pk)
     count = applied_qs.count()
     serializer = AppliedIndicatorSerializer(data=self.data)
     self.assertTrue(serializer.is_valid())
     indicator = serializer.create(serializer.validated_data)
     self.assertIsInstance(indicator, AppliedIndicator)
     self.assertEqual(applied_qs.count(), count + 1)
Esempio n. 7
0
    def test_validate_no_section(self):
        """If no section provided on indicator creation, then fail validation"""
        del self.data["section"]

        request = RequestFactory().post(
            reverse('partners_api:intervention-indicators-update', args=[self.intervention.id])
        )
        serializer = AppliedIndicatorSerializer(data=self.data, context={"request": request})
        self.assertFalse(serializer.is_valid())
        self.assertEqual(serializer.errors, {"non_field_errors": [
            'Section is required'
        ]})

        # PATCHing an indicator should not require to have sections in the request
        request = RequestFactory().patch(
            reverse('partners_api:intervention-indicators-update', args=[self.intervention.id])
        )
        serializer = AppliedIndicatorSerializer(data=self.data, context={"request": request})
        self.assertTrue(serializer.is_valid())
Esempio n. 8
0
 def test_validate_partial_exception(self):
     """If partial validation, and indicator is not blueprint indicator
     instance then fail"""
     self.data["indicator"] = {"title": "wrong"}
     serializer = AppliedIndicatorSerializer(data=self.data, partial=True)
     self.assertFalse(serializer.is_valid())
     self.assertEqual(serializer.errors, {"non_field_errors": [
         'Indicator blueprint cannot be updated after first use, '
         'please remove this indicator and add another or contact the eTools Focal Point in '
         'your office for assistance'
     ]})
Esempio n. 9
0
    def test_validate_changed_denominator_status_signed(self):
        """Allowed to change denominator if in signed status"""
        self.intervention.status = Intervention.SIGNED
        self.intervention.save()
        self.applied_indicator.indicator = self.indicator
        self.applied_indicator.save()

        self.data["cluster_indicator_id"] = "404"
        self.data["target"] = {'d': 1, 'v': 2}
        self.intervention.flat_locations.add(self.location)
        self.assertEqual(self.intervention.status, Intervention.SIGNED)
        serializer = AppliedIndicatorSerializer(
            data=self.data, instance=self.applied_indicator)
        self.assertTrue(serializer.is_valid())
Esempio n. 10
0
    def test_validate_changed_denominator_in_amendment(self):
        """Allowed to change denominator if in amendment mode"""
        self.intervention.in_amendment = True
        self.intervention.save()
        self.applied_indicator.indicator = self.indicator
        self.applied_indicator.save()

        self.data["cluster_indicator_id"] = "404"
        self.data["target"] = {'d': 1, 'v': 2}
        self.intervention.flat_locations.add(self.location)
        self.assertTrue(self.intervention.in_amendment)
        self.assertEqual(self.intervention.status, Intervention.ACTIVE)
        serializer = AppliedIndicatorSerializer(
            data=self.data, instance=self.applied_indicator)
        self.assertTrue(serializer.is_valid())
Esempio n. 11
0
 def test_validate(self):
     """If cluster indicator provided, no check is happening that value"""
     self.data["cluster_indicator_id"] = "404"
     self.intervention.flat_locations.add(self.location)
     serializer = AppliedIndicatorSerializer(data=self.data)
     self.assertTrue(serializer.is_valid())
Esempio n. 12
0
 def test_validate_no_cluster_indicator(self):
     """Check that validation passes when given no cluster indicator id"""
     self.intervention.flat_locations.add(self.location)
     serializer = AppliedIndicatorSerializer(data=self.data)
     self.assertTrue(serializer.is_valid())