예제 #1
0
    def sets_up_deferred_saving_if_commit_is_False (self):
        form_data = {
            'opiner': self.me.pk,
            'target_type': ContentType.objects.get_for_model(LegFile).pk,
            'target_id': self.legfile.pk,
            'position': 'support',
            'statement': 'It is a good idea.',
        }
        form = OpinionStatementForm(data=form_data)

        assert form.is_valid(), form.errors
        opinion = form.save(commit=False)

        assert_is_none(opinion.pk)
        assert hasattr(form, 'save_m2m')
예제 #2
0
    def creates_a_new_opinion_if_one_by_the_user_for_the_target_does_not_exist (self):
        form_data = {
            'opiner': self.me.pk,
            'target_type': ContentType.objects.get_for_model(LegFile).pk,
            'target_id': self.legfile.pk,
            'position': 'support',
            'statement': 'It is a good idea.',
        }
        form = OpinionStatementForm(data=form_data)

        assert form.is_valid(), form.errors
        form.save()

        num_opinions = len(Opinion.objects.all())
        num_revisions = len(StatementRevision.objects.all())
        assert_equal(num_opinions, 1)
        assert_equal(num_revisions, 1)
예제 #3
0
    def creates_a_new_revision_if_an_opinion_by_the_user_for_the_target_exists (self):
        opinion = Opinion.objects.create(opiner=self.me, target=self.legfile)
        StatementRevision.objects.create(opinion=opinion, statement='blah1', position='oppose')

        form_data = {
            'opiner': self.me.pk,
            'target_type': ContentType.objects.get_for_model(LegFile).pk,
            'target_id': self.legfile.pk,
            'position': 'support',
            'statement': 'It is a good idea.',
        }
        form = OpinionStatementForm(data=form_data)

        assert form.is_valid(), form.errors
        form.save()

        num_opinions = len(Opinion.objects.all())
        num_revisions = len(StatementRevision.objects.all())
        assert_equal(num_opinions, 1)
        assert_equal(num_revisions, 2)