예제 #1
0
    def test_formset_can_validate(self):
        "Just a spike test to learn about formset validation"

        post_data, file_data = self.create_formset_data()

        formset = DocumentFormSet(post_data, file_data)

        self.assertTrue(formset.is_valid())
예제 #2
0
    def test_formset_save_return_new_documents_pks(self):
        user = UserFactory()

        post_data, file_data = self.create_formset_data()
        formset = DocumentFormSet(post_data, file_data)
        return_value = formset.save(user)

        expected_return_value = [i for i in range(1, len(file_data)+1)]

        self.assertEqual(return_value, expected_return_value)
예제 #3
0
    def test_formset_save_instantiate_new_objects(self):
        user = UserFactory()

        # assert no objs exist
        self.assertEqual(Document.objects.count(), 0)

        post_data, file_data = self.create_formset_data()
        formset = DocumentFormSet(post_data, file_data)
        formset.save(user)

        # assert expected objs now exist
        expected_num_documents = len(file_data)
        self.assertEqual(Document.objects.count(), expected_num_documents)
예제 #4
0
파일: views.py 프로젝트: tilacog/paranoid
def audit_page(request, audit_pk):
    audit = Audit.objects.get(id=audit_pk)

    if request.method == "POST":
        formset = DocumentFormSet(request.POST, request.FILES)
        if formset.is_valid():
            new_docs_pks = formset.save(request.user)
            job = Job.objects.create(audit=audit, user=request.user)
            job.documents.add(*new_docs_pks)
            return redirect(job)

    if request.method == "GET":
        formset = DocumentFormSet(audit_pk=audit_pk)

    return render(request, "audit.html", {"audit": audit, "formset": formset})
예제 #5
0
    def test_formset_save_wont_create_new_objects_if_form_is_invalid(
        self, mock_form_method
    ):
        mock_form_method.return_value = False
        user = UserFactory()

        # assert no objs exist
        self.assertEqual(Document.objects.count(), 0)

        post_data, file_data = self.create_formset_data()
        formset = DocumentFormSet(post_data, file_data)

        with self.assertRaises(RuntimeError):
            formset.save(user.pk)

        self.assertEqual(Document.objects.count(), 0)