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


Python Paper.generate_thumbnail方法代码示例

本文整理汇总了Python中papers.models.Paper.generate_thumbnail方法的典型用法代码示例。如果您正苦于以下问题:Python Paper.generate_thumbnail方法的具体用法?Python Paper.generate_thumbnail怎么用?Python Paper.generate_thumbnail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在papers.models.Paper的用法示例。


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

示例1: PaperModelTest

# 需要导入模块: from papers.models import Paper [as 别名]
# 或者: from papers.models.Paper import generate_thumbnail [as 别名]
class PaperModelTest(TestCase):

    def setUp(self):
        #Bypass the celery daemon and directly test synchronously.
        settings.CELERY_ALWAYS_EAGER = True

        #We want to mock the crocodoc API library so that our tests don't have
        #to actually issue HTTP requests.
        self.patcher = mock.patch('crocodoc.Crocodoc')
        Mock = self.patcher.start()
        self.crocodoc_instance = Mock.return_value
        self.crocodoc_instance.upload.return_value = {'shortId': 'yQZpPm', 
                'uuid': '8e5b0721-26c4-11df-b354-002170de47d3'}
        self.crocodoc_instance.get_session.return_value = {'sessionId': 
                'fgH9qWEwnsJUeB0'}
        self.crocodoc_instance.delete.return_value = True

        #Create and login test user.
        self.user = User.objects.create_user('test', '[email protected]', 'test')
        self.client.login(username = 'test', password = 'test')

        #Create a new paper entry with associated file.
        upload_filename = 'blank.pdf'
        self.data = {'user': self.user, 'title': 'Test Title', 'url':
                'http://example.com', 'journal': 'Journal of Test', 'year':
                '2011', 'volume': '1', 'authors': 
                "Author One\nAuthor Two\nAuthor Three", 'issue': '2', 'pages':
                '3-4', 'file': upload_filename }

        self.p = Paper(**self.data) #unpack dictionary to arguments
        self.p.save()

        #Now let's copy the dummy upload file from the test files location path
        #to the uploaded file location
        #NOTE: Even though we may not generate a thumbnail. It is still good to 
        #      place a dummy file so that the thumbnail generation task can run
        #      successfully if called in the right conditions.
        to_path = os.path.join(settings.UPLOAD_ROOT, self.p.user.username, self.p.hash)
        from_path = os.path.join(settings.SITE_ROOT, 'papers', 'tests',
                                 'files')
        os.makedirs(to_path, mode = 0755)
        shutil.copy2(os.path.join(from_path, upload_filename), to_path)
        self.uploaded_file = os.path.join(to_path, upload_filename)

    def tearDown(self):
        #Remove the user's upload directory recursively. This also gets rid of 
        #any test uploads.
        path = os.path.join(settings.UPLOAD_ROOT, self.user.username)
        shutil.rmtree(path)

        #Stop patching process
        self.patcher.stop()

    def test_generate_thumbnail_no_file(self):
        '''
        Call the generate thumbnail task on the new paper with no file associated
        with that paper. We expect nothing to occur and that the task returns 
        False.
        '''
        self.p.file = ''
        self.p.save()

        r = self.p.generate_thumbnail()
        self.assertFalse(r)
        self.assertFalse(self.p.has_thumbnail)
开发者ID:mikexstudios,项目名称:papersdb,代码行数:67,代码来源:models.py


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