Esempio n. 1
0
    def test_calculated_field_is_cleared_when_term_goes_invalid(self):
        credit = CreditFactory()
        term_field = DocumentationFieldFactory(credit=credit,
                                               type='numeric',
                                               identifier='BA')
        calculated_field = DocumentationField.objects.create(
            credit=credit, type='calculated', formula='value = BA')
        credit_submission = CreditUserSubmissionFactory(credit=credit)
        term_submission = NumericDocumentationFieldSubmissionFactory(
            credit_submission=credit_submission,
            documentation_field=term_field,
            value=1)
        calculated_submission = NumericDocumentationFieldSubmissionFactory(
            credit_submission=credit_submission,
            documentation_field=calculated_field,
            value=100)

        term_submission.value = None
        term_submission.save()

        # We have a dirty read.
        calculated_submission = NumericSubmission.objects.get(
            pk=calculated_submission.pk)

        self.assertEqual(None, calculated_submission.value)
Esempio n. 2
0
    def test_calculated_field_is_calculated_when_term_changes(self):
        credit = CreditFactory()
        first_term_field = DocumentationFieldFactory(credit=credit,
                                                     type='numeric',
                                                     identifier='AA')
        second_term_field = DocumentationFieldFactory(credit=credit,
                                                      type='numeric',
                                                      identifier='AB')
        calculated_field = DocumentationField.objects.create(
            credit=credit,
            type='calculated',
            formula='value = (AA or 0) + (AB or 0)')
        credit_submission = CreditUserSubmissionFactory(credit=credit)
        first_term_submission = NumericDocumentationFieldSubmissionFactory(
            credit_submission=credit_submission,
            documentation_field=first_term_field,
            value=1)
        NumericDocumentationFieldSubmissionFactory(
            credit_submission=credit_submission,
            documentation_field=second_term_field,
            value=2)
        calculated_submission = NumericDocumentationFieldSubmissionFactory(
            credit_submission=credit_submission,
            documentation_field=calculated_field,
            value=None)

        first_term_submission.value = 10
        first_term_submission.save()

        # We have a dirty read.
        calculated_submission = NumericSubmission.objects.get(
            pk=calculated_submission.pk)

        self.assertEqual(12, calculated_submission.value)