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


Python Mock.contents方法代码示例

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


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

示例1: get_file

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import contents [as 别名]
 def get_file(filepath):
     fileobj = Mock()
     if filepath.endswith('node'):
         fileobj.contents = node.as_json()
     elif filepath.endswith('definition'):
         fileobj.contents = definitions_file.as_yaml()
     elif filepath.endswith('attributes'):
         fileobj.contents = attributes_file.as_yaml()
     return fileobj
开发者ID:IntelligentVisibility,项目名称:ztpserver,代码行数:11,代码来源:test_controller.py

示例2: test_upload_an_image_with_json_format

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import contents [as 别名]
    def test_upload_an_image_with_json_format(self, ImageTruck, delay):
        truck = Mock()
        ImageTruck.new_from_url.return_value = truck
        truck.filename = 'CA741C'
        truck.url.return_value = 'cloudfrunt.nut/CA741C'
        truck.contents = b''
        truck.content_type = "image/gif"

        task_id = str(uuid.uuid4())
        delay.return_value = task_id

        response = self.app.post('/add.json', data={
            'album': '',
            'url': 'imgur.com/cool_cat.gif'})
        eq_(response.status_code, 200, response.data)

        session = Client().session()
        image = session.query(Image).one()
        body = json.loads(response.data)

        eq_(body,
            [{
                'url': 'cloudfrunt.nut/CA741C',
                'image_id': image.image_id,
                'task_id': task_id,
            }])
        contents = session.query(ImageContents).one()
        eq_(contents.image_id, image.image_id)
        delay.assert_called_with([],
                                 process_image,
                                 contents.image_contents_id)
开发者ID:ErinCall,项目名称:catsnap,代码行数:33,代码来源:test_add.py

示例3: test_upload_an_image

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import contents [as 别名]
    def test_upload_an_image(self, ImageTruck, delay):
        truck = Mock()
        ImageTruck.new_from_stream.return_value = truck
        truck.filename = 'CA7'
        truck.url.return_value = 'ess three'
        truck.contents = b''
        truck.content_type = "image/jpeg"

        session = Client().session()
        album = Album(name='11:11 Eleven Eleven')
        session.add(album)
        session.flush()

        response = self.app.post('/add', data={
            'url': '',
            'album_id': album.album_id,
            'file': (StringIO(str('booya')), 'img.jpg')})

        image = session.query(Image).one()

        eq_(image.filename, 'CA7')
        eq_(image.source_url, '')
        eq_(image.album_id, album.album_id)

        eq_(response.status_code, 302, response.data)
        eq_(response.headers['Location'],
            'http://localhost/image/{0}'.format(image.image_id))

        contents = session.query(ImageContents).one()
        eq_(image.image_id, contents.image_id)

        delay.assert_called_with(
                [], process_image, contents.image_contents_id)
开发者ID:ErinCall,项目名称:catsnap,代码行数:35,代码来源:test_add.py

示例4: test_upload_an_image_twice

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import contents [as 别名]
    def test_upload_an_image_twice(self, ImageTruck, delay):
        truck = Mock()
        ImageTruck.new_from_stream.return_value = truck
        truck.filename = 'CA7'
        truck.url.return_value = 'ess three'
        truck.contents = b''
        truck.content_type = "image/jpeg"

        response = self.app.post('/add', data={
            'url': '',
            'file': (StringIO(str('booya')), 'img.jpg')})
        eq_(response.status_code, 302)
        response = self.app.post('/add', data={
            'url': '',
            'file': (StringIO(str('booya')), 'img.jpg')})
        eq_(response.status_code, 302)

        session = Client().session()
        image = session.query(Image).one()
        contentses = session.query(ImageContents).all()
        for contents in contentses:
            eq_(contents.image_id, image.image_id)
        contents_calls = [call([], process_image, x.image_contents_id)
                          for x in contentses]
        delay.assert_has_calls(contents_calls)
开发者ID:ErinCall,项目名称:catsnap,代码行数:27,代码来源:test_add.py

示例5: get_file

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import contents [as 别名]
 def get_file(filepath):
     fileobj = Mock()
     if filepath.endswith('node'):
         fileobj.contents = node.as_json()
         return fileobj
     elif filepath.endswith('pattern'):
         return fileobj
     raise ztpserver.repository.FileObjectNotFound
开发者ID:einstone,项目名称:ztpserver,代码行数:10,代码来源:test_controller.py

示例6: test_tag_no_arguments

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import contents [as 别名]
    def test_tag_no_arguments(self):
        parser = Mock()
        token = Mock()
        token.contents = Mock(methods=['split'])
        token.contents.split.return_value = ['tagged_in_object', ]

        self.assertRaises(template.TemplateSyntaxError,
                          TaggedInObjects.tag, parser, token)
开发者ID:alej0varas,项目名称:django-o2o_tagging,代码行数:10,代码来源:tests_templatetags.py

示例7: mock_truck

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import contents [as 别名]
 def mock_truck(self):
     truck = Mock()
     with open(SOME_GIF, 'r') as fh:
         truck.contents = fh.read()
     truck.url.return_value = 'https://catsnap.cdn/ca7face'
     truck.filename = 'ca7face'
     truck.content_type = 'image/gif'
     return truck
开发者ID:dariaphoebe,项目名称:catsnap,代码行数:10,代码来源:test_add_image.py

示例8: _build_module

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import contents [as 别名]
 def _build_module(self, ds_id, ds_ver_id):
     module = Mock()
     module.datastore_id = ds_id
     module.datastore_version_id = ds_ver_id
     module.contents = crypto_utils.encode_data(
         crypto_utils.encrypt_data(
             'VGhpc2lzbXlkYXRhc3RyaW5n',
             'thisismylongkeytouse'))
     return module
开发者ID:Tesora,项目名称:tesora-trove,代码行数:11,代码来源:test_instance_models.py

示例9: test_get_members_tag_missing_arg

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import contents [as 别名]
    def test_get_members_tag_missing_arg(self):
        parser = Parser(None)
        token = Mock(spec=['split_contents'], name='Taxonomy Mock')
        token.contents = 'get_members %s' %self.taxonomy_group.name
        token.split_contents.return_value = ('get_members', self.taxonomy_group.name,
                                             self.taxonomy_item.name)
        token.split_contents.side_effect = ValueError


        from templatetags.taxonomy_tags import get_taxonomy_members
        self.assertRaises(TemplateSyntaxError, get_taxonomy_members, *[parser,token])
开发者ID:jmichalicek,项目名称:django-taxonomies,代码行数:13,代码来源:tests.py

示例10: test_reorients_images

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import contents [as 别名]
    def test_reorients_images(self, ReorientImage, ImageTruck):
        transaction_id = TaskTransaction.new_id()
        image_data = self.image_data()
        (image, contents) = self.setup_contents(image_data)
        truck = Mock()
        truck.contents = image_data
        ImageTruck.return_value = truck
        ReorientImage.reorient_image.return_value = image_data

        process_image(transaction_id, contents.image_contents_id)

        ReorientImage.reorient_image.assert_called_with(image_data)
开发者ID:ErinCall,项目名称:catsnap,代码行数:14,代码来源:test_process_image.py

示例11: test_uploads_to_s3

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import contents [as 别名]
    def test_uploads_to_s3(self, ImageTruck):
        transaction_id = TaskTransaction.new_id()
        image_data = self.image_data()
        (image, contents) = self.setup_contents(image_data)
        truck = Mock()
        truck.contents = image_data
        ImageTruck.return_value = truck

        process_image(transaction_id, contents.image_contents_id)

        ImageTruck.assert_called_with(image_data, 'image/png', None)
        truck.upload.assert_called_with()
开发者ID:ErinCall,项目名称:catsnap,代码行数:14,代码来源:test_process_image.py

示例12: test_deletes_processed_contents

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import contents [as 别名]
    def test_deletes_processed_contents(self, ImageTruck):
        session = Client().session()
        transaction_id = TaskTransaction.new_id()
        image_data = self.image_data()
        (image, contents) = self.setup_contents(image_data)
        truck = Mock()
        truck.contents = image_data
        ImageTruck.return_value = truck

        process_image(transaction_id, contents.image_contents_id)

        session = Client().session()
        contents = session.query(ImageContents).all()

        eq_(contents, [])
开发者ID:ErinCall,项目名称:catsnap,代码行数:17,代码来源:test_process_image.py

示例13: test_makes_resizes

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import contents [as 别名]
    def test_makes_resizes(self, ResizeImage, ImageTruck):
        transaction_id = TaskTransaction.new_id()
        image_data = self.image_data()
        (image, contents) = self.setup_contents(image_data)
        truck = Mock()
        truck.contents = image_data
        ImageTruck.return_value = truck

        process_image(transaction_id, contents.image_contents_id)

        call_args = ResizeImage.make_resizes.call_args
        eq_(call_args[0][0], image)
        eq_(call_args[0][1], truck)
        # the 3rd arg is the after_upload callback, which we can't assert well
        eq_(len(call_args[0]), 3)
开发者ID:ErinCall,项目名称:catsnap,代码行数:17,代码来源:test_process_image.py

示例14: test_tag

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import contents [as 别名]
    def test_tag(self, Variable, search):
        parser = Mock()
        token = Mock()
        token.contents = Mock(methods=['split'])
        token.contents.split.return_value = ['tagged_in_object',
                                             'tagged_in as tags']
        m = Mock()
        m.groups.return_value = ('tagged_in', 'tags')
        search.return_value = m

        node = BaseTaggedInObjects.tag(parser, token)

        self.assertTrue(token.contents.split.called)
        search.assert_called_with(r'(.*?) as (\w+)', 'tagged_in as tags')
        self.assertTrue(m.groups.called)
        self.assertEqual(node.tagged_in, Variable.return_value)
        self.assertEqual(node.tags, Variable.return_value)
开发者ID:alej0varas,项目名称:django-o2o_tagging,代码行数:19,代码来源:tests_templatetags.py

示例15: test_resize_happens_before_main_upload

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import contents [as 别名]
    def test_resize_happens_before_main_upload(
            self, ResizeImage, ImageTruck):
        class StopDoingThingsNow(StandardError): pass

        transaction_id = TaskTransaction.new_id()
        image_data = self.image_data()
        (image, contents) = self.setup_contents(image_data)
        truck = Mock()
        truck.contents = image_data
        truck.upload.side_effect = StopDoingThingsNow
        ImageTruck.return_value = truck

        try:
            process_image(transaction_id, contents.image_contents_id)
        except StopDoingThingsNow:
            pass

        call_args = ResizeImage.make_resizes.call_args
        eq_(call_args[0][0], image)
        eq_(call_args[0][1], truck)
        # the 3rd arg is the after_upload callback, which we can't assert well
        eq_(len(call_args[0]), 3)
开发者ID:ErinCall,项目名称:catsnap,代码行数:24,代码来源:test_process_image.py


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