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


Python UserFactory.check_password方法代码示例

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


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

示例1: AccountFormTests

# 需要导入模块: from myjobs.tests.factories import UserFactory [as 别名]
# 或者: from myjobs.tests.factories.UserFactory import check_password [as 别名]
class AccountFormTests(MyJobsBase):
    def setUp(self):
        super(AccountFormTests, self).setUp()
        self.user = UserFactory()
        self.name = PrimaryNameFactory(user=self.user)
        
    def test_password_form(self):
        invalid_data = [
            { 'data': {'password': 'cats',
                       'new_password1': '7dY=Ybtk',
                       'new_password2': '7dY=Ybtk'},
              u'errors': [['password', [u"Wrong password."]]]},
            { 'data': {'password': '[email protected]',
                       'new_password1': '7dY=Ybtk',
                       'new_password2': 'notnewpassword'},
                u'errors':
                    [[u'new_password2', [u'The new password fields did not match.']],
                    [u'new_password1', [u'The new password fields did not match.']]],
            
            },
        ]

        for item in invalid_data:
            form = ChangePasswordForm(user=self.user, data=item['data'])
            self.failIf(form.is_valid())
            self.assertEqual(form.errors[item[u'errors'][0][0]],
                             item[u'errors'][0][1])

        form = ChangePasswordForm(user=self.user,data={'password': '[email protected]',
                                                       'new_password1': '7dY=Ybtk',
                                                       'new_password2': '7dY=Ybtk'})
        
        self.failUnless(form.is_valid())
        form.save()
        self.failUnless(self.user.check_password('7dY=Ybtk'))
开发者ID:kepinae,项目名称:MyJobs,代码行数:37,代码来源:test_forms.py

示例2: AccountFormTests

# 需要导入模块: from myjobs.tests.factories import UserFactory [as 别名]
# 或者: from myjobs.tests.factories.UserFactory import check_password [as 别名]
class AccountFormTests(TestCase):
    def setUp(self):
        self.user = UserFactory()
        self.name = PrimaryNameFactory(user=self.user)

    def test_password_form(self):
        invalid_data = [
            {
                "data": {"password": "cats", "new_password1": "newpassword", "new_password2": "newpassword"},
                u"errors": [["password", [u"Wrong password."]]],
            },
            {
                "data": {"password": "secret", "new_password1": "newpassword", "new_password2": "notnewpassword"},
                u"errors": [
                    [u"new_password2", [u"The new password fields did not match."]],
                    [u"new_password1", [u"The new password fields did not match."]],
                ],
            },
        ]

        for item in invalid_data:
            form = ChangePasswordForm(user=self.user, data=item["data"])
            self.failIf(form.is_valid())
            self.assertEqual(form.errors[item[u"errors"][0][0]], item[u"errors"][0][1])

        form = ChangePasswordForm(
            user=self.user,
            data={"password": "secret", "new_password1": "anothersecret", "new_password2": "anothersecret"},
        )

        self.failUnless(form.is_valid())
        form.save()
        self.failUnless(self.user.check_password("anothersecret"))

    def test_no_name_account_form(self):
        """
        Leaving both the first and last name fields blank produces a valid save.
        It also deletes the primary name object from the Name model.
        """
        data = {"gravatar": "[email protected]", "user": self.user}
        form = EditAccountForm(data, **{"user": self.user})
        self.assertTrue(form.is_valid())
        form.save(self.user)
        self.assertEqual(Name.objects.count(), 0)

    def test_both_names_account_form(self):
        """
        Filling out both name fields produces a valid save.
        """

        data = {"given_name": "Alicia", "family_name": "Smith", "gravatar": "[email protected]"}
        form = EditAccountForm(data, **{"user": self.user})
        self.assertTrue(form.is_valid())

    def test_partial_name_account_form(self):
        """
        Filling out only the first name or only the last name produces an error.
        """
        data = {"given_name": "Alicia", "gravatar": "[email protected]", "user": self.user}
        form = EditAccountForm(data, **{"user": self.user})
        self.assertFalse(form.is_valid())
        self.assertEqual(form.errors["family_name"][0], "Both a first and last name required.")
开发者ID:panyang,项目名称:MyJobs,代码行数:64,代码来源:forms.py

示例3: AccountFormTests

# 需要导入模块: from myjobs.tests.factories import UserFactory [as 别名]
# 或者: from myjobs.tests.factories.UserFactory import check_password [as 别名]
class AccountFormTests(TestCase):
    def setUp(self):
        self.user = UserFactory()
        self.name = PrimaryNameFactory(user=self.user)
        self.client = TestClient()
        
    def test_password_form(self):
        invalid_data = [
            { 'data': {'password': 'cats',
                       'new_password1': 'newpassword',
                       'new_password2': 'newpassword'},
              u'errors': [['password', [u"Wrong password."]]]},
            { 'data': {'password': 'secret',
                       'new_password1': 'newpassword',
                       'new_password2': 'notnewpassword'},
                u'errors':
                    [[u'new_password2', [u'The new password fields did not match.']],
                    [u'new_password1', [u'The new password fields did not match.']]],
            
            },
        ]

        for item in invalid_data:
            form = ChangePasswordForm(user=self.user, data=item['data'])
            self.failIf(form.is_valid())
            self.assertEqual(form.errors[item[u'errors'][0][0]],
                             item[u'errors'][0][1])

        form = ChangePasswordForm(user=self.user,data={'password': 'secret',
                                                       'new_password1': 'anothersecret',
                                                       'new_password2': 'anothersecret'})
        
        self.failUnless(form.is_valid())
        form.save()
        self.failUnless(self.user.check_password('anothersecret'))

    def test_no_name_account_form(self):
        """
        Leaving both the first and last name fields blank produces a valid save.
        It also deletes the primary name object from the Name model.
        """
        data = {"gravatar": "[email protected]", "user": self.user}
        form = EditAccountForm(data, **{'user':self.user})
        self.assertTrue(form.is_valid())
        form.save(self.user)
        self.assertEqual(Name.objects.count(), 0) 

    def test_both_names_account_form(self):
        """
        Filling out both name fields produces a valid save.
        """
        
        data = {"given_name": "Alicia", "family_name": "Smith",
                "gravatar": "[email protected]"}
        form = EditAccountForm(data, **{'user':self.user})
        self.assertTrue(form.is_valid())

    def test_partial_name_account_form(self):
        """
        Filling out only the first name or only the last name produces an error.
        """
        data = {"given_name": "Alicia", "gravatar": "[email protected]",
                "user": self.user}
        form = EditAccountForm(data, **{'user':self.user})
        self.assertFalse(form.is_valid())
        self.assertEqual(form.errors['family_name'][0],
                         "Both a first and last name required.")

    def test_gravatar_email_list(self):
        """
        Dropdowns for selecting the user's preferred Gravatar email should be
        the only dropdowns that include "Do not use Gravatar" as an option -
        others should default to the user's primary email address.
        """
        self.client.login_user(self.user)
        response = self.client.get(reverse('edit_communication'))
        soup = BeautifulSoup(response.content)
        options = soup.select('#id_digest_email option')
        self.assertEqual(len(options), 1)
        self.assertTrue(self.user.gravatar in options[0])

        response = self.client.get(reverse('edit_basic'))
        soup = BeautifulSoup(response.content)
        options = soup.select('#id_gravatar option')
        self.assertEqual(len(options), 2)
        self.assertTrue('Do not use Gravatar' in options[0])
        self.assertTrue(self.user.gravatar in options[1])
开发者ID:jpaezsa,项目名称:MyJobs,代码行数:89,代码来源:forms.py


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