當前位置: 首頁>>代碼示例>>Python>>正文


Python Job.add_report方法代碼示例

本文整理匯總了Python中jobs.models.Job.add_report方法的典型用法代碼示例。如果您正苦於以下問題:Python Job.add_report方法的具體用法?Python Job.add_report怎麽用?Python Job.add_report使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在jobs.models.Job的用法示例。


在下文中一共展示了Job.add_report方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: JobModelTest

# 需要導入模塊: from jobs.models import Job [as 別名]
# 或者: from jobs.models.Job import add_report [as 別名]
class JobModelTest(TestCase):

    def setUp(self):
        self.job = Job()
        self.job.audit = AuditFactory()
        self.job.user = UserFactory()

    def test_jobs_can_be_created(self):
        self.job.full_clean()  # Should not raise
        self.job.save()        # Should not raise

    def test_job_initial_state(self):
        "Job initial state should be RECEIVED"
        self.assertEqual(self.job.state, Job.RECEIVED_STATE)

    def test_job_creation_timestamp(self):
        start = timezone.now()
        job = JobFactory()
        end = timezone.now()

        self.assertLessEqual(start, job.created_at)
        self.assertLessEqual(job.created_at, end)

    def test_job_report_url(self):
        "Fresh and unfinished jobs have no report file"
        job = JobFactory()
        with self.assertRaises(ValueError):
            job.report_file.url


    @patch('django.core.files.storage.default_storage._wrapped')
    def test_finished_job_report_url(self, storage_mock):
        file_mock = MagicMock(spec=File, name='FileMock')
        file_mock.name = 'test_file.txt'

        storage_mock.url = MagicMock('url')
        storage_mock.url.return_value = file_mock.name
        storage_mock.save.return_value = file_mock

        self.job.add_report(file_mock)

        self.assertEqual(self.job.report_file, file_mock)
        self.assertEqual(self.job.state, Job.SUCCESS_STATE)
開發者ID:tilacog,項目名稱:paranoid,代碼行數:45,代碼來源:test_models.py


注:本文中的jobs.models.Job.add_report方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。