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


Python ProjectRegistrationProvider.validate_project方法代码示例

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


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

示例1: TestProjectRegistrationProvider

# 需要导入模块: from allura.lib.plugin import ProjectRegistrationProvider [as 别名]
# 或者: from allura.lib.plugin.ProjectRegistrationProvider import validate_project [as 别名]
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,代码行数:37,代码来源:test_plugin.py

示例2: test_validate_project_15char_user

# 需要导入模块: from allura.lib.plugin import ProjectRegistrationProvider [as 别名]
# 或者: from allura.lib.plugin.ProjectRegistrationProvider import validate_project [as 别名]
 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,代码行数:14,代码来源:test_plugin.py

示例3: TestProjectRegistrationProvider

# 需要导入模块: from allura.lib.plugin import ProjectRegistrationProvider [as 别名]
# 或者: from allura.lib.plugin.ProjectRegistrationProvider import validate_project [as 别名]
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,代码行数:54,代码来源:test_plugin.py

示例4: TestProjectRegistrationProvider

# 需要导入模块: from allura.lib.plugin import ProjectRegistrationProvider [as 别名]
# 或者: from allura.lib.plugin.ProjectRegistrationProvider import validate_project [as 别名]
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,代码行数:45,代码来源:test_plugin.py


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