コード例 #1
0
ファイル: test_views.py プロジェクト: pmzhou/phase
    def test_all_revisions_document_download(self):
        """
        Tests that download returns a zip file of all revisions
        of a document.
        """
        document = DocumentFactory(category=self.category, )
        sample_path = b'documents/tests/'
        native_doc = b'sample_doc_native.docx'
        pdf_doc = b'sample_doc_pdf.pdf'

        MetadataRevisionFactory(
            metadata=document.get_metadata(),
            revision=2,
            native_file=SimpleUploadedFile(native_doc,
                                           sample_path + native_doc),
            pdf_file=SimpleUploadedFile(pdf_doc, sample_path + pdf_doc),
        )
        MetadataRevisionFactory(
            metadata=document.get_metadata(),
            revision=3,
            native_file=SimpleUploadedFile(native_doc,
                                           sample_path + native_doc),
            pdf_file=SimpleUploadedFile(pdf_doc, sample_path + pdf_doc),
        )
        r = self.client.post(document.category.get_download_url(), {
            'document_ids': document.id,
            'revisions': 'all',
            'format': 'both',
        })
        self.assertEqual(r.status_code, 200)

        zipfile = BytesIO(r.content)
        filelist = ZipFile(zipfile).namelist()
        self.assertEqual(len(filelist), 4)