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


Python plugin.ProjectRegistrationProvider类代码示例

本文整理汇总了Python中allura.lib.plugin.ProjectRegistrationProvider的典型用法代码示例。如果您正苦于以下问题:Python ProjectRegistrationProvider类的具体用法?Python ProjectRegistrationProvider怎么用?Python ProjectRegistrationProvider使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: TestProjectRegistrationProvider

class TestProjectRegistrationProvider(object):

    def setUp(self):
        self.provider = ProjectRegistrationProvider()

    @patch('allura.lib.security.has_access')
    def test_validate_project_15char_user(self, has_access):
        has_access.return_value = TruthyCallable(lambda: True)
        nbhd = M.Neighborhood()
        self.provider.validate_project(
            neighborhood=nbhd,
            shortname='u/' + ('a' * 15),
            project_name='15 char username',
            user=MagicMock(),
            user_project=True,
            private_project=False,
        )

    @patch('allura.model.Project')
    def test_shortname_validator(self, Project):
        Project.query.get.return_value = None
        nbhd = Mock()
        v = self.provider.shortname_validator.to_python

        v('thisislegit', neighborhood=nbhd)
        assert_raises(ProjectShortnameInvalid, v,
                      'not valid', neighborhood=nbhd)
        assert_raises(ProjectShortnameInvalid, v,
                      'this-is-valid-but-too-long', neighborhood=nbhd)
        assert_raises(ProjectShortnameInvalid, v,
                      'this is invalid and too long', neighborhood=nbhd)
        assert_raises(ProjectShortnameInvalid, v,
                      'end-dash-', neighborhood=nbhd)
        Project.query.get.return_value = Mock()
        assert_raises(ProjectConflict, v, 'thisislegit', neighborhood=nbhd)
开发者ID:apache,项目名称:allura,代码行数:35,代码来源:test_plugin.py

示例2: test_validate_project_15char_user

 def test_validate_project_15char_user(self, has_access):
     has_access.return_value = TruthyCallable(lambda: True)
     provider = ProjectRegistrationProvider()
     nbhd = M.Neighborhood()
     provider.validate_project(
         neighborhood=nbhd,
         shortname='u/' + ('a' * 15),
         project_name='15 char username',
         user=MagicMock(),
         user_project=True,
         private_project=False,
     )
开发者ID:johnsca,项目名称:incubator-allura,代码行数:12,代码来源:test_plugin.py

示例3: TestProjectRegistrationProvider

class TestProjectRegistrationProvider(object):

    def setUp(self):
        self.provider = ProjectRegistrationProvider()

    @patch('allura.lib.security.has_access')
    def test_validate_project_15char_user(self, has_access):
        has_access.return_value = TruthyCallable(lambda: True)
        nbhd = M.Neighborhood()
        self.provider.validate_project(
            neighborhood=nbhd,
            shortname='u/' + ('a' * 15),
            project_name='15 char username',
            user=MagicMock(),
            user_project=True,
            private_project=False,
        )

    def test_suggest_name(self):
        f = self.provider.suggest_name
        assert_equals(f('A More Than Fifteen Character Name', Mock()),
                'amorethanfifteencharactername')

    def test_valid_project_shortname(self):
        f = self.provider.valid_project_shortname
        p = Mock()
        valid = (True, None)
        invalid = (False,
                'Please use only letters, numbers, and dashes '
                '3-15 characters long.')
        assert_equals(f('thisislegit', p), valid)
        assert_equals(f('not valid', p), invalid)
        assert_equals(f('this-is-valid-but-too-long', p), invalid)
        assert_equals(f('this is invalid and too long', p), invalid)

    def test_allowed_project_shortname(self):
        allowed = valid = (True, None)
        invalid = (False, 'invalid')
        taken = (False, 'This project name is taken.')
        cases = [
                (valid, False, allowed),
                (invalid, False, invalid),
                (valid, True, taken),
            ]
        p = Mock()
        vps = self.provider.valid_project_shortname = Mock()
        nt = self.provider._name_taken = Mock()
        f = self.provider.allowed_project_shortname
        for vps_v, nt_v, result in cases:
            vps.return_value = vps_v
            nt.return_value = nt_v
            assert_equals(f('project', p), result)
开发者ID:wwitzel3,项目名称:incubator-allura,代码行数:52,代码来源:test_plugin.py

示例4: execute

 def execute(cls, options):
     provider = ProjectRegistrationProvider.get()
     for proj in options.projects:
         proj = cls.get_project(proj)
         if proj:
             log.info('Purging %s%s. Reason: %s', proj.neighborhood.url_prefix, proj.shortname, options.reason)
             provider.purge_project(proj, disable_users=options.disable_users, reason=options.reason)
开发者ID:joequant,项目名称:allura,代码行数:7,代码来源:delete_projects.py

示例5: search_projects

 def search_projects(self, q=None, f=None, page=0, limit=None, **kw):
     fields = [('shortname', 'shortname'), ('name', 'full name')]
     add_fields = aslist(tg.config.get('search.project.additional_search_fields'), ',')
     r = self._search(M.Project, fields, add_fields, q, f, page, limit, **kw)
     r['search_results_template'] = 'allura:templates/site_admin_search_projects_results.html'
     r['additional_display_fields'] = \
         aslist(tg.config.get('search.project.additional_display_fields'), ',')
     r['provider'] = ProjectRegistrationProvider.get()
     return r
开发者ID:abhinavthomas,项目名称:allura,代码行数:9,代码来源:site_admin.py

示例6: TestProjectRegistrationProvider

class TestProjectRegistrationProvider(object):

    def setUp(self):
        self.provider = ProjectRegistrationProvider()

    @patch('allura.lib.security.has_access')
    def test_validate_project_15char_user(self, has_access):
        has_access.return_value = TruthyCallable(lambda: True)
        nbhd = M.Neighborhood()
        self.provider.validate_project(
            neighborhood=nbhd,
            shortname='u/' + ('a' * 15),
            project_name='15 char username',
            user=MagicMock(),
            user_project=True,
            private_project=False,
        )

    def test_suggest_name(self):
        f = self.provider.suggest_name
        assert_equals(f('Foo Bar', Mock()), 'foo-bar')
        assert_equals(f('A More Than Fifteen Character Name', Mock()),
                      'a-more-than-fifteen-character-name')
        assert_equals(f('foo! bar?.. the great!!', Mock()),
                      'foo-bar-the-great')

    @patch('allura.model.Project')
    def test_shortname_validator(self, Project):
        Project.query.get.return_value = None
        nbhd = Mock()
        v = self.provider.shortname_validator.to_python

        v('thisislegit', neighborhood=nbhd)
        assert_raises(ProjectShortnameInvalid, v,
                      'not valid', neighborhood=nbhd)
        assert_raises(ProjectShortnameInvalid, v,
                      'this-is-valid-but-too-long', neighborhood=nbhd)
        assert_raises(ProjectShortnameInvalid, v,
                      'this is invalid and too long', neighborhood=nbhd)
        assert_raises(ProjectShortnameInvalid, v,
                      'end-dash-', neighborhood=nbhd)
        Project.query.get.return_value = Mock()
        assert_raises(ProjectConflict, v, 'thisislegit', neighborhood=nbhd)
开发者ID:dastanforever,项目名称:allura,代码行数:43,代码来源:test_plugin.py

示例7: parse_projects

 def parse_projects(self, projects):
     """Takes projects from user input and returns a list of tuples (input, project, error)"""
     provider = ProjectRegistrationProvider.get()
     projects = projects.splitlines()
     projects = self.remove_comments(projects)
     parsed_projects = []
     for input in projects:
         if input.strip():
             p, error = provider.project_from_url(input.strip())
             parsed_projects.append((input, p, error))
     return parsed_projects
开发者ID:abhinavthomas,项目名称:allura,代码行数:11,代码来源:site_admin.py

示例8: execute

    def execute(cls, options):
        provider = ProjectRegistrationProvider.get()
        auth_provider = AuthenticationProvider.get(Request.blank('/'))
        for proj in options.projects:
            proj = cls.get_project(proj)
            if proj:
                if proj.is_user_project:
                    # disable user as well
                    user = proj.user_project_of
                    if user:
                        auth_provider.disable_user(user, audit=False)
                        msg = u'Account disabled because user-project was specified for deletion. Reason: {}'.format(
                            options.reason)
                        log_entry = h.auditlog_user(msg, user=user)
                        session(log_entry).flush(log_entry)
                    else:
                        log.info('Could not find associated user for user-project %s', proj.shortname)

                log.info('Purging %s Reason: %s', proj.url(), options.reason)
                provider.purge_project(proj, disable_users=options.disable_users, reason=options.reason)
开发者ID:abhinavthomas,项目名称:allura,代码行数:20,代码来源:delete_projects.py

示例9: setUp

 def setUp(self):
     self.provider = ProjectRegistrationProvider()
开发者ID:dastanforever,项目名称:allura,代码行数:2,代码来源:test_plugin.py

示例10: TestProjectRegistrationProviderPhoneVerification

class TestProjectRegistrationProviderPhoneVerification(object):

    def setUp(self):
        self.p = ProjectRegistrationProvider()
        self.user = UserMock()
        self.nbhd = MagicMock()

    def test_phone_verified_disabled(self):
        with h.push_config(tg.config, **{'project.verify_phone': 'false'}):
            assert_true(self.p.phone_verified(self.user, self.nbhd))

    @patch.object(plugin.security, 'has_access', autospec=True)
    def test_phone_verified_admin(self, has_access):
        has_access.return_value.return_value = True
        with h.push_config(tg.config, **{'project.verify_phone': 'true'}):
            assert_true(self.p.phone_verified(self.user, self.nbhd))

    @patch.object(plugin.security, 'has_access', autospec=True)
    def test_phone_verified_project_admin(self, has_access):
        has_access.return_value.return_value = False
        with h.push_config(tg.config, **{'project.verify_phone': 'true'}):
            self.user.set_projects([Mock()])
            assert_false(self.p.phone_verified(self.user, self.nbhd))
            self.user.set_projects([Mock(neighborhood_id=self.nbhd._id)])
            assert_true(self.p.phone_verified(self.user, self.nbhd))

    @patch.object(plugin.security, 'has_access', autospec=True)
    def test_phone_verified(self, has_access):
        has_access.return_value.return_value = False
        with h.push_config(tg.config, **{'project.verify_phone': 'true'}):
            assert_false(self.p.phone_verified(self.user, self.nbhd))
            self.user.set_tool_data('phone_verification', number_hash='123')
            assert_true(self.p.phone_verified(self.user, self.nbhd))

    @patch.object(plugin, 'g')
    def test_verify_phone_disabled(self, g):
        g.phone_service = Mock(spec=phone.PhoneService)
        with h.push_config(tg.config, **{'project.verify_phone': 'false'}):
            result = self.p.verify_phone(self.user, '12345')
            assert_false(g.phone_service.verify.called)
            assert_equal(result, {'status': 'ok'})

    @patch.object(plugin, 'g')
    def test_verify_phone(self, g):
        g.phone_service = Mock(spec=phone.PhoneService)
        with h.push_config(tg.config, **{'project.verify_phone': 'true'}):
            result = self.p.verify_phone(self.user, '123 45 45')
            g.phone_service.verify.assert_called_once_with('1234545')
            assert_equal(result, g.phone_service.verify.return_value)

    @patch.object(plugin, 'g')
    def test_check_phone_verification_disabled(self, g):
        g.phone_service = Mock(spec=phone.PhoneService)
        with h.push_config(tg.config, **{'project.verify_phone': 'false'}):
            result = self.p.check_phone_verification(
                self.user, 'request-id', '1111', 'hash')
            assert_false(g.phone_service.check.called)
            assert_equal(result, {'status': 'ok'})

    @patch.object(plugin.h, 'auditlog_user', autospec=True)
    @patch.object(plugin, 'g')
    def test_check_phone_verification_fail(self, g, audit):
        g.phone_service = Mock(spec=phone.PhoneService)
        with h.push_config(tg.config, **{'project.verify_phone': 'true'}):
            result = self.p.check_phone_verification(
                self.user, 'request-id', '1111', 'hash')
            g.phone_service.check.assert_called_once_with(
                'request-id', '1111')
            assert_equal(result, g.phone_service.check.return_value)
            assert_equal(
                self.user.get_tool_data('phone_verification', 'number_hash'),
                None)
            audit.assert_called_once_with(
                'Phone verification failed. Hash: hash', user=self.user)

    @patch.object(plugin.h, 'auditlog_user', autospec=True)
    @patch.object(plugin, 'g')
    def test_check_phone_verification_success(self, g, audit):
        g.phone_service = Mock(spec=phone.PhoneService)
        with h.push_config(tg.config, **{'project.verify_phone': 'true'}):
            g.phone_service.check.return_value = {'status': 'ok'}
            result = self.p.check_phone_verification(
                self.user, 'request-id', '1111', 'hash')
            g.phone_service.check.assert_called_once_with(
                'request-id', '1111')
            assert_equal(
                self.user.get_tool_data('phone_verification', 'number_hash'),
                'hash')
            audit.assert_called_once_with(
                'Phone verification succeeded. Hash: hash', user=self.user)
开发者ID:dastanforever,项目名称:allura,代码行数:90,代码来源:test_plugin.py

示例11: __init__

 def __init__(self, source):
     super(ProjectImportForm, self).__init__()
     provider = ProjectRegistrationProvider.get()
     self.add_field('tools', ToolsValidator(source))
     self.add_field('project_shortname', provider.shortname_validator)
     self.allow_extra_fields = True
开发者ID:jekatgithub,项目名称:incubator-allura,代码行数:6,代码来源:base.py

示例12: deserialize

 def deserialize(self, node, cstruct):
     if cstruct is col.null:
         return col.null
     return ProjectRegistrationProvider.get().shortname_validator.to_python(cstruct,
                                                                            check_allowed=not self.update,
                                                                            neighborhood=self.nbhd)
开发者ID:apache,项目名称:allura,代码行数:6,代码来源:project-import.py


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