本文整理汇总了Python中allura.lib.plugin.ProjectRegistrationProvider.check_phone_verification方法的典型用法代码示例。如果您正苦于以下问题:Python ProjectRegistrationProvider.check_phone_verification方法的具体用法?Python ProjectRegistrationProvider.check_phone_verification怎么用?Python ProjectRegistrationProvider.check_phone_verification使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类allura.lib.plugin.ProjectRegistrationProvider
的用法示例。
在下文中一共展示了ProjectRegistrationProvider.check_phone_verification方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestProjectRegistrationProviderPhoneVerification
# 需要导入模块: from allura.lib.plugin import ProjectRegistrationProvider [as 别名]
# 或者: from allura.lib.plugin.ProjectRegistrationProvider import check_phone_verification [as 别名]
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)