Python fixtures 模块,MockPatchObject() 实例源码

我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用fixtures.MockPatchObject()

项目:fuel-ccp    作者:openstack    | 项目源码 | 文件源码
def _setUp(self):
        self.useFixture(fixtures.MockPatchObject(config, '_REAL_CONF'))
        config.setup_config(None)
        self.conf = config._REAL_CONF
项目:bilean    作者:openstack    | 项目源码 | 文件源码
def patchobject(self, obj, attr, **kwargs):
        mockfixture = self.useFixture(fixtures.MockPatchObject(obj, attr,
                                                               **kwargs))
        return mockfixture.mock

    # NOTE(pshchelo): this overrides the testtools.TestCase.patch method
    # that does simple monkey-patching in favor of mock's patching
项目:os-http    作者:openstack-dev    | 项目源码 | 文件源码
def setUp(self):
        super(TestInputs, self).setUp()

        disc = fixture.DiscoveryList(href=AUTH_URL, v2=False)

        self.service_type = uuid.uuid4().hex
        self.service_id = uuid.uuid4().hex
        self.service_name = uuid.uuid4().hex

        self.user_id = uuid.uuid4().hex
        self.username = uuid.uuid4().hex
        self.project_id = uuid.uuid4().hex
        self.project_name = uuid.uuid4().hex

        self.token = fixture.V3Token(user_id=self.user_id,
                                     user_name=self.username,
                                     project_id=self.project_id,
                                     project_name=self.project_name)

        self.token.add_role()
        self.token.add_role()
        self.token_id = uuid.uuid4().hex

        service = self.token.add_service(self.service_type,
                                         id=self.service_id,
                                         name=self.service_name)

        service.add_standard_endpoints(public=PUBLIC_SERVICE_URL,
                                       admin=ADMIN_SERVICE_URL,
                                       internal=INTERNAL_SERVICE_URL,
                                       region=SERVICE_REGION)

        self.requests_mock.get(AUTH_URL, json=disc, status_code=300)
        self.auth_mock = self.requests_mock.post(
            AUTH_URL + '/v3/auth/tokens',
            json=self.token,
            headers={'X-Subject-Token': self.token_id})

        # don't do any console formatting markup
        m = fixtures.MockPatchObject(shell, 'formatter_name', 'text')
        self.useFixture(m)
项目:gnocchi    作者:gnocchixyz    | 项目源码 | 文件源码
def setUp(self):
        super(RestTest, self).setUp()

        if self.auth_mode == "keystone":
            self.auth_token_fixture = self.useFixture(
                ksm_fixture.AuthTokenFixture())
            self.auth_token_fixture.add_token_data(
                is_v2=True,
                token_id=TestingApp.VALID_TOKEN_ADMIN,
                user_id=TestingApp.USER_ID_ADMIN,
                user_name='adminusername',
                project_id=TestingApp.PROJECT_ID_ADMIN,
                role_list=['admin'])
            self.auth_token_fixture.add_token_data(
                is_v2=True,
                token_id=TestingApp.VALID_TOKEN,
                user_id=TestingApp.USER_ID,
                user_name='myusername',
                project_id=TestingApp.PROJECT_ID,
                role_list=["member"])
            self.auth_token_fixture.add_token_data(
                is_v2=True,
                token_id=TestingApp.VALID_TOKEN_2,
                user_id=TestingApp.USER_ID_2,
                user_name='myusername2',
                project_id=TestingApp.PROJECT_ID_2,
                role_list=["member"])

        self.conf.set_override("auth_mode", self.auth_mode, group="api")

        self.useFixture(fixtures.MockPatchObject(
            app.GnocchiHook, "_lazy_load", self._fake_lazy_load))

        self.app = TestingApp(app.load_app(conf=self.conf,
                                           not_implemented_middleware=False),
                              storage=self.storage,
                              indexer=self.index,
                              incoming=self.incoming,
                              auth_mode=self.auth_mode)