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


Python User.validate_secret方法代码示例

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


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

示例1: TestUsers

# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import validate_secret [as 别名]
class TestUsers(TestCase):
    def run(self, result=None):
        with test_database(test_db, (User, Company)):
            super(TestUsers, self).run(result)

    def create_test_data(self):
        self._company = Company().create(name='test_name', phone_number='1223456789', address='123 test road, testville test')
        self._user = User().create(name='test_name', email='[email protected]', title='the_boss',
                          secret_question='what is the answer?',
                            phone_number='1234567891', authentication_level=3, company=self._company.pk)
        self._user.set_password('test_password')
        self._user.set_secret_answer('42')
        self._admin = User().create(name='admin', email='[email protected]', title='the_boss',
                           secret_question='what is the answer?',
                               phone_number='1234567891', authentication_level=1, company=self._company.pk)
        self._admin.set_password('test_password')
        self._admin.set_secret_answer('42')

    def test_user_creation(self):
        self.create_test_data()
        self.assertEqual(self._user.name, 'test_name')
        self.assertEqual(self._user.email, '[email protected]')
        self.assertEqual(self._user.title, 'the_boss')
        self.assertEqual(self._user.secret_question, 'what is the answer?')
        self.assertEqual(self._user.phone_number, '1234567891')
        self.assertEqual(self._user.authentication_level, 3)

    def test_user_delete(self):
        self.create_test_data()
        deleted = self._user.delete()
        self.assertEqual(deleted, 1)

    def test_user_validation(self):
        self.create_test_data()
        self.assertTrue(self._user.validate_login(plaintext_password='test_password'))

    def test_user_validation_after_update(self):
        self.create_test_data()
        test_name = "test_name"
        self._user.name = test_name
        self._user.save()
        self.assertTrue(self._user.validate_login(plaintext_password='test_password'))

    def test_user_secret_question(self):
        self.create_test_data()
        self.assertTrue(self._user.validate_secret('42'))
        self.assertTrue(self._user.validate_secret('  42  '))
        self.assertFalse(self._user.validate_secret('  forty-two  '))

    def test_user_change_info(self):
        self.create_test_data()
        query = User().update(authentication_level=2, email='[email protected]',
                                      phone_number='1231231234', name='new_name', title='new_title').where(User.pk == self._user.pk)
        query.execute()
        pk = self._user.pk
        self._user_2 = User().get(pk=pk)
        self.assertEqual(self._user_2.authentication_level, 2)
        self.assertEqual(self._user_2.phone_number, '1231231234')
        self.assertEqual(self._user_2.name, 'new_name')
        self.assertEqual(self._user_2.title, 'new_title')

    def test_user_change_password(self):
        self.create_test_data()
        self._user.set_password('new_password')
        self.assertFalse(self._user.validate_login(plaintext_password='test_password'))
        self.assertTrue(self._user.validate_login(plaintext_password='new_password'))

    def test_user_change_secret_question(self):
        self.create_test_data()
        self._user.set_secret_answer('neW Answer')
        self.assertFalse(self._user.validate_secret('test_password'))
        self.assertTrue(self._user.validate_secret('new answer'))
        self.assertTrue(self._user.validate_secret('newanswer'))

    def test_get_user_by_pk(self):
        self.create_test_data()
        pk_1 = self._user.pk
        _user = User().get(pk=pk_1)
        self.assertIsNotNone(_user)
        _user3 = User().get(pk=pk_1)
        pk_2 = _user3.pk
        self.assertEqual(pk_1, pk_2)

    def test_get_user_by_email(self):
        self.create_test_data()
        email = '[email protected]'
        _user_1 = User().get(email=email)
        self.assertIsNotNone(_user_1)
        _user_2 = User().get(email=email)
        self.assertEqual(_user_2.pk, self._user.pk)

    def test_get_company(self):
        self.create_test_data()
        self.assertEqual(self._company.pk, self._user.company.pk)
开发者ID:odonnellryan,项目名称:HappyClient,代码行数:96,代码来源:user_test.py


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