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


Python MagicMock.username方法代码示例

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


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

示例1: change_role

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import username [as 别名]
 def change_role(self, user, role):
     from cthulhu.calamari_ctl import assign_role
     args = MagicMock()
     args.username = user
     args.role_name = role
     assign_role(args)
     log.debug('changing role of %s to %s' % (user, role))
开发者ID:SUSE,项目名称:calamari,代码行数:9,代码来源:test_permissions.py

示例2: test_register_5to6

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import username [as 别名]
    def test_register_5to6(self, mock_subprocess):
        self.engine.options = self.create_options(
            five_to_six=True,
            destination_url="http://example.com",
            service_level="x")
        credentials = MagicMock()
        credentials.username = "foo"
        credentials.password = "bar"
        self.engine.consumer_id = "id"

        self.engine.consumer_exists = MagicMock(return_value=True)
        self.engine.select_service_level = MagicMock(return_value="y")

        mock_subprocess.return_value = 0
        self._inject_mock_valid_consumer()
        self.engine.register(credentials, "org", "env")

        arg_list = ['subscription-manager',
            'register',
            '--username=foo',
            '--password=bar',
            '--environment=env',
            '--auto-attach',
            '--serverurl=http://example.com',
            '--org=org',
            '--consumerid=id',
            '--servicelevel=y',
            ]

        self.engine.consumer_exists.assert_called_once_with(self.engine.consumer_id)
        self.engine.select_service_level.assert_called_once_with("org", "x")
        mock_subprocess.assert_called_once_with(arg_list)
开发者ID:belonesox,项目名称:subscription-manager,代码行数:34,代码来源:test_migration.py

示例3: setUp

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import username [as 别名]
    def setUp(self):
        views.RSS = MagicMock()
        self.rss_object = MagicMock()
        views.RSS.objects.all.return_value = [self.rss_object]

        # Create request user mock
        user_object = MagicMock()
        user_object.username = 'test_user'
        user_object.pk = '1111'
        user_object.is_staff = False
        self.request = MagicMock()
        self.request.user = user_object

        # Create organization mock
        self.org_object = MagicMock()
        self.org_object.name = 'test_org'
        self.org_object.managers = ['1111']
        self.org_object.payment_info = {
            'number': '4567456745674567'
        }
        views.Organization = MagicMock()
        views.Organization.objects.get.return_value = self.org_object

        views.RSSManagerFactory = MagicMock()
        self._limits_factory = MagicMock()
        views.RSSManagerFactory.return_value = self._limits_factory

        self._exp_mock = MagicMock(name="ExpenditureManager")
        self._limits_factory.get_expenditure_manager.return_value = self._exp_mock
开发者ID:Fiware,项目名称:apps.Wstore,代码行数:31,代码来源:tests.py

示例4: test_get_username

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import username [as 别名]
    def test_get_username(self, xblock):
        user = MagicMock()
        user.username = "Bob"

        xblock.xmodule_runtime = MagicMock()
        xblock.xmodule_runtime.get_real_user.return_value = user

        self.assertEqual('Bob', xblock.get_username('anon_id'))
开发者ID:Elbagoury,项目名称:edx-ora2,代码行数:10,代码来源:test_openassessment.py

示例5: _get_user

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import username [as 别名]
 def _get_user(self, netid=None):
     user = MagicMock()
     if netid is None:
         user.is_authenticated.return_value = False
     else:
         user.is_authenticated.return_value = True
         user.netid = netid
         user.username = netid + '@washington.edu'
     return user
开发者ID:jeffFranklin,项目名称:iam-identity-pdp,代码行数:11,代码来源:conftest.py

示例6: test_args

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import username [as 别名]
    def test_args(self):
        mocked_os = MagicMock()
        mocked_log = MagicMock()
        mocked_grp = MagicMock()
        mocked_pass = MagicMock()
        mocked_file = MagicMock()
        mocked_args = MagicMock()
        mocked_parser = MagicMock()
        mocked_urlparse = MagicMock()
        mocked_parse_res1 = MagicMock()
        mocked_parse_res2 = MagicMock()
        mocked_log_handler = MagicMock()
        url = '[email protected]:owner/test.git'

        mocked_file.mkdtemp.return_value = "/tmp"
        mocked_pass.getuser.return_value = "test_user"
        mocked_os.getgid.return_value = 1
        mocked_os.environ = {}
        mocked_os.path.abspath.return_value = "abs/tmp"
        mocked_grp.getgrgid().gr_name = "test_group"
        mocked_parser.parse_args.return_value = mocked_args
        mocked_args.remote_url = url
        mocked_parse_res1.scheme = None
        mocked_parse_res2.username = "user"
        mocked_urlparse.side_effect = [mocked_parse_res1, mocked_parse_res2]
        mocked_args.o = "magic=True,not_magic=False"
        mocked_args.group = None
        mocked_args.repo_path = None
        mocked_args.user = None
        mocked_args.branch = None
        mocked_args.ssh_user = None
        mocked_args.sentry_dsn = ''

        with patch.multiple('gitfs.utils.args', os=mocked_os, grp=mocked_grp,
                            getpass=mocked_pass, tempfile=mocked_file,
                            TimedRotatingFileHandler=mocked_log_handler,
                            urlparse=mocked_urlparse, log=mocked_log):

            args = Args(mocked_parser)
            asserted_results = {
                "repo_path": "abs/tmp",
                "user": "test_user",
                "group": "test_group",
                "branch": "master",
                "not_magic": "False",
                "ssh_user": "user",
            }
            for name, value in asserted_results.iteritems():
                assert value == getattr(args, name)

            assert args.config == mocked_args
            assert mocked_pass.getuser.call_count == 1
            assert mocked_file.mkdtemp.call_count == 1
            mocked_log.setLevel.assert_called_once_with('DEBUG')
            mocked_urlparse.assert_has_calls([call(url), call('ssh://' + url)])
            mocked_grp.getgrgid.has_calls([call(1)])
开发者ID:gregwjacobs,项目名称:gitfs,代码行数:58,代码来源:test_args.py

示例7: test_register_failure

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import username [as 别名]
    def test_register_failure(self, mock_subprocess):
        self.engine.options = self.create_options({'serverurl': 'foobar'})

        credentials = MagicMock()
        credentials.username = "foo"
        credentials.password = "bar"

        mock_subprocess.return_value = 1
        try:
            self.engine.register(credentials, "", "")
        except SystemExit, e:
            self.assertEquals(e.code, 2)
开发者ID:aweiteka,项目名称:subscription-manager,代码行数:14,代码来源:test_migration.py

示例8: test_register_failure

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import username [as 别名]
    def test_register_failure(self, mock_subprocess):
        self.engine.options = self.create_options(destination_url='foobar')

        credentials = MagicMock()
        credentials.username = "foo"
        credentials.password = "bar"

        self._inject_mock_invalid_consumer()
        try:
            self.engine.register(credentials, "", "")
        except SystemExit, e:
            self.assertEquals(e.code, 2)
开发者ID:belonesox,项目名称:subscription-manager,代码行数:14,代码来源:test_migration.py

示例9: _create_review_mock

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import username [as 别名]
    def _create_review_mock(self, rev_data):
        review = MagicMock()
        review.pk = rev_data['id']

        usr = MagicMock()
        usr.username = rev_data['user']

        org = MagicMock()
        org.name = rev_data['organization']
        if usr.name == rev_data['organization']:
            usr.userprofile.current_organization = org

        review.user = usr
        review.organization = org
        review.title = rev_data['title']
        review.comment = rev_data['comment']
        review.rating = rev_data['rating']
        review.offering = self.offering
        review.timestamp = datetime.strptime(rev_data['timestamp'], '%Y-%m-%d %H:%M:%S.%f')

        if 'response' in rev_data:
            response = MagicMock()
            resp_user = MagicMock()
            resp_user.username = rev_data['response']['user']
            resp_org = MagicMock()
            resp_org.name = rev_data['response']['organization']
            if resp_user.name == rev_data['response']['organization']:
                resp_user.userprofile.current_organization = resp_org

            response.user = resp_user
            response.organization = resp_org
            response.title = rev_data['response']['title']
            response.response = rev_data['response']['response']
            response.timestamp = datetime.strptime(rev_data['response']['timestamp'], '%Y-%m-%d %H:%M:%S.%f')

            review.response = response
        else:
            review.response = None

        return review
开发者ID:jartieda,项目名称:wstore,代码行数:42,代码来源:tests.py

示例10: test_args

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import username [as 别名]
 def test_args(self):
     """
     Does the correct set of arguments get passed to the ap
     """
     args = MagicMock()
     del args.channel
     args.hostname = 'mike'
     args.username = 'bob'
     args.password = 'me'
     ap = MagicMock()
     with patch('apcommand.accesspoints.atheros', ap):
         # 000
         access_point = self.sub_command.access_point(args)
         ap.AtherosAR5KAP.assert_called_with(hostname=args.hostname,
                                             username=args.username,
                                             password=args.password)
         args.password = None
         # 001
         access_point = self.sub_command.access_point(args)
         ap.AtherosAR5KAP.assert_called_with(hostname=args.hostname,
                                             username=args.username)
         args.username = None
         # 011
         access_point = self.sub_command.access_point(args)
         ap.AtherosAR5KAP.assert_called_with(hostname=args.hostname)
         
         args.password = 'cow'
         # 010
         access_point = self.sub_command.access_point(args)
         ap.AtherosAR5KAP.assert_called_with(hostname=args.hostname,
                                             password=args.password)
         args.hostname=None
         # 110
         access_point = self.sub_command.access_point(args)
         ap.AtherosAR5KAP.assert_called_with(password=args.password)
         args.password = None
         # 111
         access_point = self.sub_command.access_point(args)
         ap.AtherosAR5KAP.assert_called_with()            
     return
开发者ID:russellnakamura,项目名称:apcommand,代码行数:42,代码来源:subcommands.py

示例11: test_notify_should_send_email_to_user

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import username [as 别名]
    def test_notify_should_send_email_to_user(self, mock_send_email):
        user = MagicMock()
        email = '[email protected]'
        name = 'manchester united'
        user.email = email
        user.username = name
        subject = "some subject"
        message = "some %s message"

        CSVExportService.notify(user, subject, message)

        expected_message = "some manchester united message"
        mock_send_email.assert_called_once_with(subject, expected_message, DEFAULT_FROM_EMAIL, [email])
开发者ID:unicefuganda,项目名称:eums,代码行数:15,代码来源:test_csv_export_service.py

示例12: setUp

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import username [as 别名]
    def setUp(self):
        # Create request user mock
        user_object = MagicMock()
        user_object.username = 'test_user'
        user_object.pk = '1111'
        user_object.is_staff = False
        self.request = MagicMock()
        self.request.user = user_object

        # Create organization mock
        self.org_object = MagicMock()
        self.org_object.name = 'test_org'
        self.org_object.managers = ['1111']
        self.org_object.payment_info = {
            'number': '4567456745674567'
        }
        views.Organization = MagicMock()
        views.Organization.objects.get.return_value = self.org_object
开发者ID:jartieda,项目名称:wstore,代码行数:20,代码来源:tests.py

示例13: test_register_with_activation_keys

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import username [as 别名]
    def test_register_with_activation_keys(self, mock_subprocess):
        self.engine.options = self.create_options(destination_url='foobar', activation_keys=['hello', 'world'])

        credentials = MagicMock()
        credentials.username = "foo"
        credentials.password = "bar"

        mock_subprocess.return_value = 0
        self._inject_mock_valid_consumer()
        self.engine.register(credentials, "org", "env")

        arg_list = ['subscription-manager',
            'register',
            '--activationkey=hello',
            '--activationkey=world',
            '--serverurl=foobar',
            '--org=org',
            ]

        mock_subprocess.assert_called_with(arg_list)
开发者ID:belonesox,项目名称:subscription-manager,代码行数:22,代码来源:test_migration.py

示例14: test_register_no_auto

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import username [as 别名]
    def test_register_no_auto(self, mock_subprocess):
        self.engine.options = self.create_options(auto=False)
        credentials = MagicMock()
        credentials.username = "foo"
        credentials.password = "bar"
        self.engine.consumer_id = "id"

        mock_subprocess.return_value = 0
        self._inject_mock_valid_consumer()
        self.engine.register(credentials, "org", "env")

        arg_list = ['subscription-manager',
            'register',
            '--username=foo',
            '--password=bar',
            '--environment=env',
            '--org=org',
            ]

        mock_subprocess.assert_called_once_with(arg_list)
开发者ID:belonesox,项目名称:subscription-manager,代码行数:22,代码来源:test_migration.py

示例15: test_chat_settings

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import username [as 别名]
    def test_chat_settings(self):
        mock_user = MagicMock()
        mock_user.username = "johndoe"

        mock_course = MagicMock()
        mock_course.id = "a/b/c"

        # Stub this out in the case that it's not in the settings
        domain = "jabber.edx.org"
        settings.JABBER_DOMAIN = domain

        chat_settings = views.chat_settings(mock_course, mock_user)

        # Test the proper format of all chat settings
        self.assertEqual(chat_settings['domain'], domain)
        self.assertEqual(chat_settings['room'], "a-b-c_class")
        self.assertEqual(chat_settings['username'], "[email protected]%s" % domain)

        # TODO: this needs to be changed once we figure out how to
        #       generate/store a real password.
        self.assertEqual(chat_settings['password'], "[email protected]%s" % domain)
开发者ID:HowestX,项目名称:edx-platform,代码行数:23,代码来源:test_views.py


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