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


Python Mock.filename方法代码示例

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


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

示例1: test_add_module

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import filename [as 别名]
    def test_add_module(self, mock_shutil):
        module_path = '/tmp/mod.tar.gz'
        feed_url = 'http://host/root/PULP_MANAFEST'
        unit_key = {'name': 'puppet-module'}
        unit_metadata = {'A': 1, 'B': 2}
        unit = Mock()
        unit.storage_path = '/tmp/%s' % uuid4()

        mock_conduit = Mock()
        mock_conduit.init_unit = Mock(return_value=unit)

        config = {constants.CONFIG_FEED: feed_url}

        mock_module = Mock()
        mock_module.unit_key = Mock(return_value=unit_key)
        mock_module.unit_metadata = Mock(return_value=unit_metadata)
        mock_module.filename = Mock(return_value='puppet-module')

        # test

        method = SynchronizeWithDirectory(mock_conduit, config)
        method._add_module(module_path, mock_module)

        # validation

        mock_conduit.init_unit.assert_called_with(
            constants.TYPE_PUPPET_MODULE, unit_key, unit_metadata, mock_module.filename())
        mock_shutil.copy.assert_called_with(module_path, unit.storage_path)
开发者ID:asmacdo,项目名称:pulp_puppet,代码行数:30,代码来源:test_directory.py

示例2: test_ignore

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import filename [as 别名]
    def test_ignore(self):
        evt = Mock()
        evt.filename = "event.txt"

        if not self.test_obj.__ignore__:
            self.assertFalse(self.test_obj.ignore(evt))
        else:
            self.assertFalse(self.test_obj.ignore(evt))
            for extension in self.test_obj.__ignore__:
                for name in ["event.txt", "....", extension, "." + extension]:
                    for filler in ["", ".blah", "......", "." + extension]:
                        evt.filename = name + filler + "." + extension
                        self.assertTrue(self.test_obj.ignore(evt))
开发者ID:rcuza,项目名称:bcfg2,代码行数:15,代码来源:Test_init.py

示例3: _mock

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import filename [as 别名]
    def _mock(self, val):
        # Mock has an attr `mixed`, which inadvertantly gets called by formencode to_python method :/
        def f(filename): pass

        m = Mock(spec=f)
        m.filename = val
        return m
开发者ID:brondsem,项目名称:allura,代码行数:9,代码来源:test_validators.py

示例4: setup_mock_options

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import filename [as 别名]
 def setup_mock_options(cls, hosts=None, filename=None, grouping=None):
   mock_options = Mock(spec=['hosts', 'filename', 'verbosity', 'min_instance_count', 'grouping'])
   mock_options.hosts = hosts
   mock_options.filename = filename
   mock_options.verbosity = False
   mock_options.grouping = grouping or DEFAULT_GROUPING
   return mock_options
开发者ID:bhuvan,项目名称:incubator-aurora,代码行数:9,代码来源:test_admin_sla.py

示例5: test_upload_an_image_with_json_format

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import filename [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

示例6: test_add_module_not_copied

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import filename [as 别名]
    def test_add_module_not_copied(self, mock_shutil):
        module_path = '/tmp/mod.tar.gz'
        feed_url = 'http://host/root/PULP_MANAFEST'
        unit_key = {'name': 'puppet-module'}
        unit_metadata = {'A': 1, 'B': 2}
        unit = Mock()
        unit.storage_path = os.path.join(os.getcwd(), __file__)

        mock_conduit = Mock()
        mock_conduit.init_unit = Mock(return_value=unit)

        config = {constants.CONFIG_FEED: feed_url}

        mock_module = Mock()
        mock_module.unit_key = Mock(return_value=unit_key)
        mock_module.unit_metadata = Mock(return_value=unit_metadata)
        mock_module.filename = Mock(return_value='puppet-module')

        # test

        method = SynchronizeWithDirectory(mock_conduit, config)
        method._add_module(module_path, mock_module)

        # validation

        self.assertFalse(mock_shutil.copy.called)
开发者ID:asmacdo,项目名称:pulp_puppet,代码行数:28,代码来源:test_directory.py

示例7: test_entry_init

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import filename [as 别名]
    def test_entry_init(self, mock_entry_init):
        eset = self.get_obj()
        eset.entries = dict()
        evt = Mock()
        evt.filename = "test.txt"
        handler = Mock()
        handler.__basenames__ = []
        handler.__extensions__ = []
        handler.deprecated = False
        handler.experimental = False
        handler.__specific__ = True

        # test handling an event with the parent entry_init
        eset.entry_init(evt, handler)
        mock_entry_init.assert_called_with(eset, evt, entry_type=handler, specific=handler.get_regex.return_value)
        self.assertItemsEqual(eset.entries, dict())

        # test handling the event with a Cfg handler
        handler.__specific__ = False
        eset.entry_init(evt, handler)
        handler.assert_called_with(os.path.join(eset.path, evt.filename))
        self.assertItemsEqual(eset.entries, {evt.filename: handler.return_value})
        handler.return_value.handle_event.assert_called_with(evt)

        # test handling an event for an entry that already exists with
        # a Cfg handler
        handler.reset_mock()
        eset.entry_init(evt, handler)
        self.assertFalse(handler.called)
        self.assertItemsEqual(eset.entries, {evt.filename: handler.return_value})
        eset.entries[evt.filename].handle_event.assert_called_with(evt)
开发者ID:rcuza,项目名称:bcfg2,代码行数:33,代码来源:Test_init.py

示例8: test_handles

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import filename [as 别名]
    def test_handles(self, mock_get_regex):
        match = Mock()
        mock_get_regex.return_value = Mock()
        mock_get_regex.return_value.match = match

        evt = Mock()
        evt.filename = "event.txt"

        if self.test_obj.__basenames__:
            match.return_value = False
            self.assertFalse(self.test_obj.handles(evt))
            mock_get_regex.assert_called_with([b for b in self.test_obj.__basenames__])
            print("match calls: %s" % match.call_args_list)
            print("expected: %s" % [call(evt.filename) for b in self.test_obj.__basenames__])
            match.assert_called_with(evt.filename)

            mock_get_regex.reset_mock()
            match.reset_mock()
            match.return_value = True
            self.assertTrue(self.test_obj.handles(evt))
            match.assert_called_with(evt.filename)
        else:
            match.return_value = False
            self.assertFalse(self.test_obj.handles(evt, basename=os.path.basename(self.path)))
            mock_get_regex.assert_called_with([os.path.basename(self.path)])
            match.assert_called_with(evt.filename)

            mock_get_regex.reset_mock()
            match.reset_mock()
            match.return_value = True
            self.assertTrue(self.test_obj.handles(evt, basename=os.path.basename(self.path)))
            mock_get_regex.assert_called_with([os.path.basename(self.path)])
            match.assert_called_with(evt.filename)
开发者ID:rcuza,项目名称:bcfg2,代码行数:35,代码来源:Test_init.py

示例9: test_HandleEvent

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import filename [as 别名]
 def test_HandleEvent(self, mock_load_xml):
     config = self.get_config_object("groups.xml")
     evt = Mock()
     evt.filename = os.path.join(self.metadata.data, "groups.xml")
     evt.code2str = Mock(return_value="changed")
     self.assertTrue(config.HandleEvent(evt))
     mock_load_xml.assert_called_with()
开发者ID:seacoastboy,项目名称:bcfg2,代码行数:9,代码来源:TestMetadata.py

示例10: test_upload_an_image

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import filename [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

示例11: test_upload_an_image_twice

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import filename [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

示例12: make_mock_options

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import filename [as 别名]
 def make_mock_options(self):
   mock_options = Mock()
   mock_options.filename = None
   mock_options.hosts = ','.join(self.HOSTNAMES)
   mock_options.cluster = self.TEST_CLUSTER
   mock_options.verbosity = False
   return mock_options
开发者ID:MustafaOrkunAcar,项目名称:incubator-aurora,代码行数:9,代码来源:test_maintenance.py

示例13: mock_truck

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import filename [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

示例14: test_upload_filedata_returns_false_if_extension_not_correct

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import filename [as 别名]
    def test_upload_filedata_returns_false_if_extension_not_correct(self):
        # given
        uploaded_file = Mock()
        uploaded_file.filename = 'filename.oops'

        # when
        success = upload_filedata(uploaded_file)

        # then
        self.assertFalse(success)
开发者ID:jrm2k6,项目名称:jeremydagorn-blog,代码行数:12,代码来源:test_parse_file.py

示例15: load_groups_data

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import filename [as 别名]
 def load_groups_data(self, metadata=None, xdata=None):
     if metadata is None:
         metadata = get_metadata_object()
     metadata.groups_xml.data = xdata or copy.deepcopy(groups_test_tree)
     metadata.groups_xml.basedata = copy.copy(metadata.groups_xml.data)
     evt = Mock()
     evt.filename = os.path.join(datastore, "Metadata", "groups.xml")
     evt.code2str = Mock(return_value="changed")
     metadata.HandleEvent(evt)
     return metadata
开发者ID:seacoastboy,项目名称:bcfg2,代码行数:12,代码来源:TestMetadata.py


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