当前位置: 首页>>代码示例>>Python>>正文


Python factories.DocumentFactory类代码示例

本文整理汇总了Python中documents.factories.DocumentFactory的典型用法代码示例。如果您正苦于以下问题:Python DocumentFactory类的具体用法?Python DocumentFactory怎么用?Python DocumentFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了DocumentFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_jsonification

    def test_jsonification(self):
        """Tests that a jsonified document returns the appropriate values."""

        date = datetime.datetime(2013, 04, 20, 12, 0, 0, tzinfo=utc)

        document = DocumentFactory(
            document_key='FAC09001-FWF-000-HSE-REP-0004',
            created_on=date,
            current_revision_date=date,
            metadata={
                'title': 'HAZOP report',
            },
            revision={
                'status': 'STD',
                'revision_date': date,
                'created_on': date,
                'updated_on': date,
            }
        )

        self.assertEqual(
            document.to_json(),
            {
                u'status': u'STD',
                u'title': u'HAZOP report',
                u'url': document.get_absolute_url(),
                u'revision': 1,
                u'is_latest_revision': True,
                u'pk': document.metadata.latest_revision.pk,
                u'document_pk': document.pk,
                u'metadata_pk': document.metadata.pk,
                u'document_key': 'FAC09001-FWF-000-HSE-REP-0004',
                u'document_number': 'FAC09001-FWF-000-HSE-REP-0004',
            }
        )
开发者ID:andyjia,项目名称:phase,代码行数:35,代码来源:test_models.py

示例2: test_edition_errors

    def test_edition_errors(self):
        """
        Tests that a document can't be edited without required fields.
        """
        required_error = 'This field is required.'
        doc = DocumentFactory(
            category=self.category,
            document_key='FAC09001-FWF-000-HSE-REP-0004',
            metadata={
                'title': 'HAZOP related 1',
            },
            revision={
                'status': 'STD',
            }
        )
        c = self.client
        edit_url = doc.get_edit_url()
        r = c.get(edit_url)
        self.assertEqual(r.status_code, 200)

        r = c.post(edit_url, {'document_number': doc.document_key})
        self.assertEqual(r.status_code, 200)
        self.assertEqual(r.context['form'].errors, {
            'title': [required_error],
        })
开发者ID:Talengi,项目名称:phase,代码行数:25,代码来源:test_forms.py

示例3: test_command

    def test_command(self):
        document = DocumentFactory(
            category=self.category,
        )
        native_doc = 'sample_doc_native.docx'
        pdf_doc = 'sample_doc_pdf.pdf'

        MetadataRevisionFactory(
            metadata=document.get_metadata(),
            revision=2,
            native_file=SimpleUploadedFile(native_doc, b'content'),
            pdf_file=SimpleUploadedFile(pdf_doc, b'content'),
        )
        # Document without files
        DocumentFactory(
            category=self.category,
        )
        rev = document.get_latest_revision()
        filepath = rev.pdf_file.path
        # check file is on disk after doc deletion
        document.delete()
        self.assertTrue(os.path.exists(filepath))

        call_command('clearmedia')
        # command has deleted file
        self.assertFalse(os.path.exists(filepath))
开发者ID:Talengi,项目名称:phase,代码行数:26,代码来源:test_command.py

示例4: test_edition_updates_document_key

    def test_edition_updates_document_key(self):
        doc = DocumentFactory(
            category=self.category,
            document_key='FAC09001-FWF-000-HSE-REP-0004',
            metadata={
                'title': 'HAZOP related 1',
            },
            revision={
                'status': 'STD',
            }
        )
        c = self.client
        c.post(doc.get_edit_url(), {
            'document_number': 'New Document Number',
            'title': 'a new title',
            'docclass': 1,
            'created_on': '2015-10-10',
            'received_date': '2015-10-10',
            'save-view': 'View',
        }, follow=True)

        doc.refresh_from_db()
        self.assertEqual(doc.document_number, 'New Document Number')
        self.assertEqual(doc.document_key, 'NEW-DOCUMENT-NUMBER')

        metadata = doc.get_metadata()
        self.assertEqual(metadata.document_number, 'New Document Number')
        self.assertEqual(metadata.document_key, 'NEW-DOCUMENT-NUMBER')
开发者ID:Talengi,项目名称:phase,代码行数:28,代码来源:test_forms.py

示例5: test_edition_success

 def test_edition_success(self):
     """
     Tests that a document can be created with required fields.
     """
     original_number_of_document = Document.objects.all().count()
     doc = DocumentFactory(
         category=self.category,
         document_key='FAC09001-FWF-000-HSE-REP-0004',
         metadata={
             'title': 'HAZOP related 1',
         },
         revision={
             'status': 'STD',
         }
     )
     c = self.client
     r = c.post(doc.get_edit_url(), {
         'document_number': doc.document_key,
         'title': 'a new title',
     })
     if r.status_code == 302:
         self.assertEqual(
             original_number_of_document + 1,
             Document.objects.all().count()
         )
     else:
         # Debug purpose
         self.assertEqual(r.context['form'].errors, {})
开发者ID:Talengi,项目名称:phase,代码行数:28,代码来源:test_forms.py

示例6: test_deleted_document_is_unindexed

 def test_deleted_document_is_unindexed(self, index_mock, unindex_mock):
     doc = DocumentFactory(
         category=self.category,
         document_key='FAC09001-FWF-000-HSE-REP-0004',
     )
     doc.delete()
     self.assertEqual(unindex_mock.call_count, 1)
开发者ID:thibault,项目名称:phase,代码行数:7,代码来源:test_signals.py

示例7: test_new_revision_can_update_document_key

    def test_new_revision_can_update_document_key(self):
        doc = DocumentFactory(
            category=self.category,
            document_key='FAC09001-FWF-000-HSE-REP-0004',
            revision={
                'status': 'STD',
            }
        )
        url = reverse('document_revise', args=[
            self.category.organisation.slug,
            self.category.slug,
            doc.document_key
        ])
        self.client.post(url, {
            'document_number': 'Another Document Number',
            'title': doc.metadata.title,
            'status': 'SPD',
            'docclass': 1,
            'created_on': '2015-10-10',
            'revision_date': '2015-10-10',
            'received_date': '2015-10-10',
        }, follow=True)

        doc.refresh_from_db()
        self.assertEqual(doc.document_number, 'Another Document Number')
        self.assertEqual(doc.document_key, 'ANOTHER-DOCUMENT-NUMBER')

        metadata = doc.get_metadata()
        self.assertEqual(metadata.document_number, 'Another Document Number')
        self.assertEqual(metadata.document_key, 'ANOTHER-DOCUMENT-NUMBER')
开发者ID:Talengi,项目名称:phase,代码行数:30,代码来源:test_forms.py

示例8: setUp

    def setUp(self):
        self.tmpdir = tempfile.mkdtemp(prefix='phasetest_', suffix='_trs')
        self.incoming = join(self.tmpdir, 'incoming')
        self.tobechecked = join(self.tmpdir, 'tobechecked')
        self.accepted = join(self.tmpdir, 'accepted')
        self.rejected = join(self.tmpdir, 'rejected')

        os.mkdir(self.accepted)
        os.mkdir(self.rejected)
        os.mkdir(self.tobechecked)

        doc = DocumentFactory(
            document_key='FAC10005-CTR-CLT-TRS-00001',
            metadata_factory_class=TransmittalFactory,
            revision_factory_class=TransmittalRevisionFactory,
            metadata={
                'status': 'tobechecked',
                'tobechecked_dir': self.tobechecked,
                'accepted_dir': self.accepted,
                'rejected_dir': self.rejected,
                'contractor': 'test'
            }
        )
        self.transmittal = doc.get_metadata()
        os.mkdir(self.transmittal.full_tobechecked_name)
开发者ID:Talengi,项目名称:phase,代码行数:25,代码来源:test_models.py

示例9: test_all_revisions_document_download

    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)
开发者ID:andyjia,项目名称:phase,代码行数:34,代码来源:test_views.py

示例10: generate_random_documents

def generate_random_documents(nb_of_docs, category):
    """Generate a bunch of random documents.

    This function is useful for testing purpose.

    """
    if category.category_template.metadata_model.model_class() != DemoMetadata:
        error_message = ('This function is only useful for testing purpose. '
                         'The category you pass as an argument can only host '
                         'documents of the DemoMetadata type.')
        raise Exception(error_message)

    for i in range(nb_of_docs):
        document = DocumentFactory(
            category=category,
        )
        metadata = document.get_metadata()
        max_revision = choice(list(range(1, 5)))
        for revision_number in range(2, max_revision):
            MetadataRevisionFactory(
                revision=revision_number,
                revision_date='{year}-{month:0>2}-{day:0>2}'.format(
                    year=2008 + revision_number,
                    month=choice(list(range(1, 13))),
                    day=choice(list(range(1, 29))),
                ),
                metadata=metadata
            )
开发者ID:Talengi,项目名称:phase,代码行数:28,代码来源:utils.py

示例11: test_jsonification

    def test_jsonification(self):
        """Tests that a jsonified document returns the appropriate values."""

        date = datetime.datetime(2013, 04, 20, 12, 0, 0, tzinfo=utc)

        document = DocumentFactory(
            document_key="FAC09001-FWF-000-HSE-REP-0004",
            created_on=date,
            current_revision_date=date,
            metadata={"title": "HAZOP report"},
            revision={"status": "STD", "revision_date": date, "created_on": date, "updated_on": date},
        )

        self.assertEqual(
            document.to_json(),
            {
                "status": "STD",
                "title": "HAZOP report",
                "url": document.get_absolute_url(),
                "revision": 1,
                "is_latest_revision": True,
                "pk": document.metadata.latest_revision.pk,
                "document_pk": document.pk,
                "metadata_pk": document.metadata.pk,
                "document_key": "FAC09001-FWF-000-HSE-REP-0004",
                "document_number": "FAC09001-FWF-000-HSE-REP-0004",
            },
        )
开发者ID:thibault,项目名称:phase,代码行数:28,代码来源:test_models.py

示例12: setUp

 def setUp(self):
     self.category = CategoryFactory()
     self.user = UserFactory(
         email='[email protected]',
         password='pass',
         is_superuser=True,
         category=self.category
     )
     self.client.login(email=self.user.email, password='pass')
     self.doc1 = DocumentFactory(
         category=self.category,
         revision={
             'leader': self.user,
             'received_date': datetime.date.today(),
         }
     )
     self.doc2 = DocumentFactory(
         category=self.category,
         revision={
             'leader': self.user,
             'received_date': datetime.date.today(),
         }
     )
     self.doc3 = DocumentFactory(
         category=self.category,
         revision={
             'reviewers': [],
             'leader': None,
             'approver': None,
             'received_date': datetime.date.today(),
         }
     )
     self.content_type = ContentType.objects.get_for_model(self.doc3.metadata)
     self.ok = 'The review started for the following documents'
     self.nok = "We failed to start the review for the following documents"
开发者ID:Talengi,项目名称:phase,代码行数:35,代码来源:test_tasks.py

示例13: test_updated_document_is_indexed

 def test_updated_document_is_indexed(self, index_mock):
     doc = DocumentFactory(
         category=self.category,
         document_key='FAC09001-FWF-000-HSE-REP-0004',
     )
     doc.title = 'foobar'
     doc.save()
     self.assertEqual(index_mock.call_count, 2)
开发者ID:thibault,项目名称:phase,代码行数:8,代码来源:test_signals.py

示例14: test_revised_document_is_indexed

 def test_revised_document_is_indexed(self, index_mock):
     doc = DocumentFactory(
         category=self.category,
         document_key='FAC09001-FWF-000-HSE-REP-0004',
     )
     revision = doc.latest_revision
     revision.pk = None
     revision.save()
     doc.save()
     self.assertEqual(index_mock.call_count, 2)
开发者ID:thibault,项目名称:phase,代码行数:10,代码来源:test_signals.py

示例15: PendingReviewsReminderTests

class PendingReviewsReminderTests(TestCase):
    def setUp(self):
        self.category = CategoryFactory()
        self.user = UserFactory(
            email='[email protected]',
            password='pass',
            is_superuser=True,
            category=self.category
        )
        self.client.login(email=self.user.email, password='pass')
        self.doc1 = DocumentFactory(
            category=self.category,
            revision={
                'leader': self.user,
                'received_date': datetime.date.today(),
            }
        )
        self.doc2 = DocumentFactory(
            category=self.category,
            revision={
                'leader': self.user,
                'received_date': datetime.date.today(),
            }
        )

    def test_empty_reminder_list(self):
        call_command('send_review_reminders')
        self.assertEqual(len(mail.outbox), 0)

    def test_send_reminders(self):
        self.doc1.get_latest_revision().start_review()
        self.assertEqual(Review.objects.all().count(), 1)

        call_command('send_review_reminders')
        self.assertEqual(len(mail.outbox), 1)

    def test_finished_reviews(self):
        rev = self.doc1.get_latest_revision()
        rev.start_review()
        rev.end_review()
        self.assertEqual(Review.objects.all().count(), 1)

        call_command('send_review_reminders')
        self.assertEqual(len(mail.outbox), 0)

    def test_do_not_send_reminder(self):
        """Reminders are not send to users if their mail config says so."""
        self.doc1.get_latest_revision().start_review()
        self.assertEqual(Review.objects.all().count(), 1)

        self.user.send_pending_reviews_mails = False
        self.user.save()

        call_command('send_review_reminders')
        self.assertEqual(len(mail.outbox), 0)
开发者ID:Talengi,项目名称:phase,代码行数:55,代码来源:test_emails.py


注:本文中的documents.factories.DocumentFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。