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


Python MagicMock.user_id方法代码示例

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


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

示例1: test_get_involved_users_org

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import user_id [as 别名]
    def test_get_involved_users_org(self, list_comments_mock):

        datarequest_id = 'dr1'
        follower1 = MagicMock()
        follower2 = MagicMock()
        follower1.user_id = 'user-2'
        follower2.user_id = 'user-3'

        list_comments_mock.return_value = [{'user_id': 'user-1'}, {'user_id': 'user-2'}]
        actions.db.DataRequestFollower.get.return_value = [follower1, follower2]

        self.context['auth_user_obj'].id = 'user-7'
        datarequest = {
            'id': datarequest_id,
            'user_id': 'user-1',
            'organization': {'users': [{'id': 'user-3'}, {'id': 'user-4'}]}
        }

        result = actions._get_datarequest_involved_users(self.context, datarequest)

        self.assertEquals(set(['user-1', 'user-2', 'user-3', 'user-4']), result)

        actions.db.DataRequestFollower.get.assert_called_once_with(datarequest_id=datarequest_id)
        list_comments_mock.assert_called_once_with({'ignore_auth': True,
                                                    'model': self.context['model']},
                                                   {'datarequest_id': datarequest_id})
开发者ID:yhteentoimivuuspalvelut,项目名称:ckanext-datarequests,代码行数:28,代码来源:test_actions.py

示例2: test_tranformer_shutdown_instance

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import user_id [as 别名]
    def test_tranformer_shutdown_instance(self):
        status = rd_instance.ServiceStatuses.SHUTDOWN.api_status
        db_instance = self.build_db_instance(status)

        server = MagicMock(spec=Server)
        server.user_id = 'test_user_id'
        mgmt_instance = mgmtmodels.SimpleMgmtInstance(self.context,
                                                      db_instance,
                                                      server,
                                                      None)
        flavor = MagicMock(spec=Flavor)
        flavor.name = 'db.small'

        with patch.object(Backup, 'running', return_value=None):
            self.assertThat(mgmt_instance.status, Equals('SHUTDOWN'))
            with patch.object(mgmtmodels, 'load_mgmt_instances',
                              return_value=[mgmt_instance]):
                with patch.object(self.flavor_mgr, 'get', return_value=flavor):
                    # invocation
                    transformer = mgmtmodels.NovaNotificationTransformer(
                        context=self.context)
                    payloads = transformer()
                    # assertion that SHUTDOWN instances are not reported
                    self.assertIsNotNone(payloads)
                    self.assertThat(len(payloads), Equals(0))
开发者ID:B-Rich,项目名称:trove,代码行数:27,代码来源:test_models.py

示例3: test_regular

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import user_id [as 别名]
    def test_regular(self):
        sender = MagicMock()
        detect = MagicMock()
        context = MagicMock()
        suggest = Mock()
        target = Target(sender, detect, context, suggest)
        target.json_decode = MagicMock(return_value={"_rev": "context_revision_value"})
        target.context_responder.unsupported_entities = MagicMock()

        response = Mock()
        response.body = "response_body_value"

        handler = MagicMock()
        handler.user_id = "user_id_value"
        handler.application_id = "application_id_value"
        handler.session_id = "session_id_value"
        handler.locale = "locale_value"

        target.get_context_callback(response, handler, "message_value")

        target.json_decode.assert_called_once_with("response_body_value")

        target.context_responder.unsupported_entities.assert_called_once_with(
            handler, {"_rev": "context_revision_value"}
        )

        self.assertEqual(1, suggest.post_suggest.call_count)
        self.assertEqual("user_id_value", suggest.post_suggest.call_args_list[0][0][0])
        self.assertEqual("application_id_value", suggest.post_suggest.call_args_list[0][0][1])
        self.assertEqual("session_id_value", suggest.post_suggest.call_args_list[0][0][2])
        self.assertEqual("locale_value", suggest.post_suggest.call_args_list[0][0][3])
        self.assertDictEqual({"_rev": "context_revision_value"}, suggest.post_suggest.call_args_list[0][0][4])
开发者ID:rdefeo,项目名称:api,代码行数:34,代码来源:test_new_message_NewMessageText.py

示例4: test_tranformer_flavor_cache

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import user_id [as 别名]
    def test_tranformer_flavor_cache(self):
        status = rd_instance.ServiceStatuses.BUILDING.api_status
        db_instance = MockMgmtInstanceTest.build_db_instance(
            status, InstanceTasks.BUILDING)

        server = MagicMock(spec=Server)
        server.user_id = 'test_user_id'
        mgmt_instance = mgmtmodels.SimpleMgmtInstance(self.context,
                                                      db_instance,
                                                      server,
                                                      None)
        flavor = MagicMock(spec=Flavor)
        flavor.name = 'db.small'

        with patch.object(mgmtmodels, 'load_mgmt_instances',
                          return_value=[mgmt_instance]):
            with patch.object(self.flavor_mgr, 'get', return_value=flavor):
                transformer = mgmtmodels.NovaNotificationTransformer(
                    context=self.context)
                transformer()
                # call twice ensure client.flavor invoked once
                payloads = transformer()
                self.assertIsNotNone(payloads)
                self.assertThat(len(payloads), Equals(1))
                payload = payloads[0]
                self.assertThat(payload['audit_period_beginning'],
                                Not(Is(None)))
                self.assertThat(payload['audit_period_ending'], Not(Is(None)))
                self.assertThat(payload['state'], Equals(status.lower()))
                self.assertThat(payload['instance_type'], Equals('db.small'))
                self.assertThat(payload['instance_type_id'],
                                Equals('flavor_1'))
                self.assertThat(payload['user_id'], Equals('test_user_id'))
                # ensure cache was used to get flavor second time
                self.flavor_mgr.get.assert_any_call('flavor_1')
开发者ID:B-Rich,项目名称:trove,代码行数:37,代码来源:test_models.py

示例5: test_tranformer_shutdown_instance

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import user_id [as 别名]
    def test_tranformer_shutdown_instance(self):
        status = rd_instance.ServiceStatuses.SHUTDOWN.api_status
        instance, service_status = self.build_db_instance(status)
        service_status.set_status(rd_instance.ServiceStatuses.SHUTDOWN)
        server = MagicMock(spec=Server)
        server.user_id = 'test_user_id'

        mgmt_instance = mgmtmodels.SimpleMgmtInstance(self.context,
                                                      instance,
                                                      server,
                                                      service_status)
        flavor = MagicMock(spec=Flavor)
        flavor.name = 'db.small'
        transformer = mgmtmodels.NovaNotificationTransformer(
            context=self.context)
        with patch.object(Backup, 'running', return_value=None):
            self.assertThat(mgmt_instance.status, Equals('SHUTDOWN'))
            with patch.object(mgmtmodels, 'load_mgmt_instances',
                              return_value=[mgmt_instance]):
                with patch.object(self.flavor_mgr, 'get', return_value=flavor):
                    payloads = transformer()
                    # assertion that SHUTDOWN instances are not reported
                    self.assertIsNotNone(payloads)
                    self.assertNotIn(status.lower(),
                                     [db['status']
                                      for db in payloads])
        self.addCleanup(self.do_cleanup, instance, service_status)
开发者ID:cp16net,项目名称:trove,代码行数:29,代码来源:test_models.py

示例6: test_public_exists_events

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import user_id [as 别名]
    def test_public_exists_events(self):
        status = rd_instance.ServiceStatuses.BUILDING.api_status
        instance, service_status = self.build_db_instance(
            status, task_status=InstanceTasks.BUILDING)
        server = MagicMock(spec=Server)
        server.user_id = 'test_user_id'
        mgmt_instance = mgmtmodels.SimpleMgmtInstance(self.context,
                                                      instance,
                                                      server,
                                                      service_status)

        flavor = MagicMock(spec=Flavor)
        flavor.name = 'db.small'

        notifier = MagicMock()
        with patch.object(rpc, 'get_notifier', return_value=notifier):
            with patch.object(mgmtmodels, 'load_mgmt_instances',
                              return_value=[mgmt_instance]):
                with patch.object(self.flavor_mgr, 'get', return_value=flavor):
                    self.assertThat(self.context.auth_token,
                                    Is('some_secret_password'))
                    with patch.object(notifier, 'info', return_value=None):
                        # invocation
                        mgmtmodels.publish_exist_events(
                            mgmtmodels.NovaNotificationTransformer(
                                context=self.context),
                            self.context)
                        # assertion
                        notifier.info.assert_any_call(
                            self.context, 'trove.instance.exists', ANY)
                        self.assertThat(self.context.auth_token, Is(None))
        self.addCleanup(self.do_cleanup, instance, service_status)
开发者ID:cp16net,项目名称:trove,代码行数:34,代码来源:test_models.py

示例7: test_organic_topk_coldstart

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import user_id [as 别名]
    def test_organic_topk_coldstart(self):
        """PrecomputedUserTopkBlueprintInterpreter test cold starts. """
        self._train_task()

        topk_req = MagicMock()
        topk_req.user_id = ['Foobar']
        topk_req.known_items = False
        topk_req.n_items = 20
        topk_req.threshold = None
        request = Request(scoring_data=topk_req)

        vertex = MagicMock()
        vertex.steps = [[self.task]]
        vertex_data = {'vertex_object': vertex}
        model = PrecomputedUserTopkBlueprintInterpreter(MagicMock(), MagicMock(),
                                                        request=request)
        model.vertex_factory = MagicMock()
        model.vertex_factory.get.return_value = vertex_data
        out = model.predict()
        self.assertEqual(len(out), len(topk_req.user_id))
        self.assertEqual(out[0][0], topk_req.user_id[0])
        topk = self.task.topk_[(-1, -1)]
        desired_items = map(lambda iid: topk.item_inv_map[iid], topk.coldstart_items[:topk_req.n_items])
        np.testing.assert_array_equal(out[0][1], desired_items)
        np.testing.assert_array_equal(out[0][2], topk.coldstart_ratings[:topk_req.n_items])

        # check if all output item ids are in training set
        item_set = set(np.unique(self.df['item_id']))
        items = out[0][1]
        for eid in items:
            self.assertTrue(eid in item_set)
开发者ID:tkincaid,项目名称:tkincaid.github.com,代码行数:33,代码来源:test_recommender.py

示例8: test_organic_topk_smoke

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import user_id [as 别名]
    def test_organic_topk_smoke(self):
        """PrecomputedUserTopkBlueprintInterpreter smoke test. """
        self._train_task()

        topk_req = MagicMock()
        topk_req.user_id = ['UID-1']
        topk_req.known_items = False
        topk_req.n_items = 20
        topk_req.threshold = None
        request = Request(scoring_data=topk_req)

        vertex = MagicMock()
        vertex.steps = [[self.task]]
        vertex_data = {'vertex_object': vertex}
        model = PrecomputedUserTopkBlueprintInterpreter(MagicMock(), MagicMock(),
                                                        request=request)
        model.vertex_factory = MagicMock()
        model.vertex_factory.get.return_value = vertex_data
        out = model.predict()
        self.assertEqual(len(out), len(topk_req.user_id))
        self.assertEqual(out[0][0], topk_req.user_id[0])

        # check if all output item ids are in training set
        item_set = set(np.unique(self.df['item_id']))
        items = out[0][1]
        for eid in items:
            self.assertTrue(eid in item_set)
开发者ID:tkincaid,项目名称:tkincaid.github.com,代码行数:29,代码来源:test_recommender.py

示例9: test_on_taskrun_submit_event

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import user_id [as 别名]
 def test_on_taskrun_submit_event(self, mock_update_feed,
                                  mock_add_user,
                                  mock_is_task,
                                  mock_update_task,
                                  mock_create_result,
                                  mock_push):
     """Test on_taskrun_submit is called."""
     conn = MagicMock()
     target = MagicMock()
     target.id = 1
     target.project_id = 1
     target.task_id = 2
     target.user_id = 3
     tmp = Project(id=1, name='name', short_name='short_name',
                   info=dict(container=1, thumbnail="avatar.png"),
                   published=True,
                   webhook='http://localhost.com')
     conn.execute.return_value = [tmp]
     on_taskrun_submit(None, conn, target)
     obj = tmp.to_public_json()
     obj['action_updated'] = 'TaskCompleted'
     mock_add_user.assert_called_with(conn, target.user_id, obj)
     mock_update_task.assert_called_with(conn, target.task_id)
     mock_update_feed.assert_called_once_with(obj)
     obj_with_webhook = tmp.to_public_json()
     obj_with_webhook['webhook'] = tmp.webhook
     obj_with_webhook['action_updated'] = 'TaskCompleted'
     mock_push.assert_called_with(obj_with_webhook, target.task_id, 1)
开发者ID:influencerplus123,项目名称:tinybee.ai,代码行数:30,代码来源:test_event_listeners.py

示例10: test_tranformer_invalid_datastore_manager

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import user_id [as 别名]
    def test_tranformer_invalid_datastore_manager(self):
        status = rd_instance.ServiceStatuses.BUILDING.api_status
        db_instance = MockMgmtInstanceTest.build_db_instance(
            status, task_status=InstanceTasks.BUILDING)

        server = MagicMock(spec=Server)
        server.user_id = 'test_user_id'
        stub_datastore_version = MagicMock()
        stub_datastore_version.id = "stub_datastore_version"
        stub_datastore_version.manager = "m0ng0"
        stub_datastore = MagicMock()
        stub_datastore.default_datastore_version = "stub_datastore_version"

        flavor = MagicMock(spec=Flavor)
        flavor.name = 'db.small'

        with patch.object(datastore_models.DatastoreVersion, 'load',
                          return_value=stub_datastore_version):
            with patch.object(datastore_models.DatastoreVersion,
                              'load_by_uuid',
                              return_value=stub_datastore_version):
                with patch.object(datastore_models.Datastore, 'load',
                                  return_value=stub_datastore):
                    mgmt_instance = mgmtmodels.SimpleMgmtInstance(self.context,
                                                                  db_instance,
                                                                  server,
                                                                  None)
                    with patch.object(mgmtmodels, 'load_mgmt_instances',
                                      return_value=[mgmt_instance]):
                        with patch.object(self.flavor_mgr,
                                          'get', return_value=flavor):

                            # invocation
                            transformer = (
                                mgmtmodels.NovaNotificationTransformer(
                                    context=self.context)
                            )

                            payloads = transformer()
                            # assertions
                            self.assertIsNotNone(payloads)
                            self.assertThat(len(payloads), Equals(1))
                            payload = payloads[0]
                            self.assertThat(payload['audit_period_beginning'],
                                            Not(Is(None)))
                            self.assertThat(payload['audit_period_ending'],
                                            Not(Is(None)))
                            self.assertThat(payload['state'],
                                            Equals(status.lower()))
                            self.assertThat(payload['instance_type'],
                                            Equals('db.small'))
                            self.assertThat(payload['instance_type_id'],
                                            Equals('flavor_1'))
                            self.assertThat(payload['user_id'],
                                            Equals('test_user_id'))
                            self.assertThat(payload['service_id'],
                                            Equals('unknown-service-id-error'))
开发者ID:B-Rich,项目名称:trove,代码行数:59,代码来源:test_models.py

示例11: _generate_basic_comment

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import user_id [as 别名]
def _generate_basic_comment(id=COMMENT_ID, user_id='example_uuidv4_user',
                            comment='Example Comment', datarequest_id='example_dr_id'):
    comment = MagicMock()
    comment.id = id
    comment.user_id = user_id
    comment.comment = comment
    comment.datarequest_id = datarequest_id
    comment.time = datetime.datetime.now()

    return comment
开发者ID:amercader,项目名称:ckanext-datarequests,代码行数:12,代码来源:test_actions_data.py

示例12: test_tranformer

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import user_id [as 别名]
    def test_tranformer(self):
        status = rd_instance.ServiceStatuses.BUILDING.api_status
        db_instance = MockMgmtInstanceTest.build_db_instance(
            status, task_status=InstanceTasks.BUILDING)

        stub_dsv_db_info = MagicMock(spec=datastore_models.DBDatastoreVersion)
        stub_dsv_db_info.id = "test_datastore_version"
        stub_dsv_db_info.datastore_id = "mysql_test_version"
        stub_dsv_db_info.name = "test_datastore_name"
        stub_dsv_db_info.image_id = "test_datastore_image_id"
        stub_dsv_db_info.packages = "test_datastore_pacakges"
        stub_dsv_db_info.active = 1
        stub_dsv_db_info.manager = "mysql"
        stub_datastore_version = datastore_models.DatastoreVersion(
            stub_dsv_db_info)

        flavor = MagicMock(spec=Flavor)
        flavor.name = 'db.small'

        server = MagicMock(spec=Server)
        server.user_id = 'test_user_id'
        mgmt_instance = mgmtmodels.SimpleMgmtInstance(self.context,
                                                      db_instance,
                                                      server,
                                                      None)

        with patch.object(DatabaseModelBase, 'find_by',
                          return_value=stub_datastore_version):

            with patch.object(mgmtmodels, 'load_mgmt_instances',
                              return_value=[mgmt_instance]):

                with patch.object(self.flavor_mgr, 'get', return_value=flavor):

                    # invocation
                    transformer = mgmtmodels.NovaNotificationTransformer(
                        context=self.context)
                    payloads = transformer()

                    # assertions
                    self.assertIsNotNone(payloads)
                    self.assertThat(len(payloads), Equals(1))
                    payload = payloads[0]
                    self.assertThat(payload['audit_period_beginning'],
                                    Not(Is(None)))
                    self.assertThat(payload['audit_period_ending'],
                                    Not(Is(None)))
                    self.assertThat(payload['state'], Equals(status.lower()))
                    self.assertThat(payload['instance_type'],
                                    Equals('db.small'))
                    self.assertThat(payload['instance_type_id'],
                                    Equals('flavor_1'))
                    self.assertThat(payload['user_id'], Equals('test_user_id'))
                    self.assertThat(payload['service_id'], Equals('123'))
开发者ID:B-Rich,项目名称:trove,代码行数:56,代码来源:test_models.py

示例13: _generate_basic_datarequest

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import user_id [as 别名]
def _generate_basic_datarequest(id=DATAREQUEST_ID, user_id='example_uuidv4_user',
                                title='This is a title', description='This is a basic description',
                                organization_id='example_uuidv4_organization', closed=False):
    datarequest = MagicMock()
    datarequest.id = id
    datarequest.user_id = user_id
    datarequest.title = title
    datarequest.description = description
    datarequest.organization_id = organization_id
    datarequest.open_time = datetime.datetime.now()
    datarequest.closed = closed
    datarequest.close_time = None
    datarequest.accepted_dataset_id = None
    datarequest.accepted_dataset = {'test': 'test1', 'test2': 'test3'}

    return datarequest
开发者ID:amercader,项目名称:ckanext-datarequests,代码行数:18,代码来源:test_actions_data.py

示例14: test_threshold_known_items

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import user_id [as 别名]
    def test_threshold_known_items(self, mock_task_func):
        """Filter by threshold & known items - corner case with 0 items returned"""
        mock_task = MagicMock()
        mock_task.topk_ = {(-1, -1): self.topk}
        mock_task_func.return_value = mock_task

        topk_req = MagicMock()
        topk_req.user_id = ['UID-1']
        topk_req.known_items = False
        topk_req.n_items = 20
        topk_req.threshold = 1.0
        request = Request(scoring_data=topk_req)
        model = PrecomputedUserTopkBlueprintInterpreter(MagicMock(), MagicMock(),
                                                        request=request)
        out = model.predict()
        self.assertEqual(out, [('UID-1', [], tuple())])
开发者ID:tkincaid,项目名称:tkincaid.github.com,代码行数:18,代码来源:test_recommender.py

示例15: test_coldstart_threshold

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import user_id [as 别名]
    def test_coldstart_threshold(self, mock_task_func):
        """Threshold applies to coldstart. """
        mock_task = MagicMock()
        mock_task.topk_ = {(-1, -1): self.topk}
        mock_task_func.return_value = mock_task

        topk_req = MagicMock()
        topk_req.user_id = ['UID-666']
        topk_req.known_items = False
        topk_req.n_items = 20
        topk_req.threshold = 3.1
        request = Request(scoring_data=topk_req)
        model = PrecomputedUserTopkBlueprintInterpreter(MagicMock(), MagicMock(),
                                                        request=request)
        out = model.predict()
        self.assertEqual(out, [('UID-666', [], tuple())])
开发者ID:tkincaid,项目名称:tkincaid.github.com,代码行数:18,代码来源:test_recommender.py


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