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


Python UserFactory.set_password方法代码示例

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


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

示例1: get_redirect_response

# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import set_password [as 别名]
class TestSignInRedirect:
    def get_redirect_response(self, client, next=None):
        password = "password"
        self.user = UserFactory()
        self.user.set_password(password)
        self.user.save()
        url = reverse("userena_signin")
        if next:
            url += f"?next={next}"

        return client.post(
            url,
            data={"identification": self.user.username, "password": password},
            follow=True,
        )

    def test_default_redirect(self, client):
        response = self.get_redirect_response(client)
        assert response.redirect_chain[0][1] == status.HTTP_302_FOUND
        assert response.redirect_chain[0][0] == reverse("profile_redirect")
        assert response.status_code == status.HTTP_200_OK

    def test_redirect(self, client):
        expected_url = "/challenges/"
        response = self.get_redirect_response(client, expected_url)
        assert response.redirect_chain[0][1] == status.HTTP_302_FOUND
        assert response.status_code == status.HTTP_200_OK
        assert response.redirect_chain[0][0] == expected_url

    def test_no_logout_redirect(self, client):
        response = self.get_redirect_response(client, settings.LOGOUT_URL)
        assert response.redirect_chain[0][1] == status.HTTP_302_FOUND
        assert response.redirect_chain[0][0] == reverse("profile_redirect")
        assert response.status_code == status.HTTP_200_OK
开发者ID:comic,项目名称:comic-django,代码行数:36,代码来源:test_views.py

示例2: test_login_disabled_user

# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import set_password [as 别名]
    def test_login_disabled_user(self):
        """Logging in to a disabled account fails"""
        user = UserFactory()
        user.set_password('Leeloo')
        user.is_disabled = True
        user.save()

        with assert_raises(auth.LoginDisabledError):
            auth.login(user.username, 'Leeloo')
开发者ID:erinmayhood,项目名称:osf.io,代码行数:11,代码来源:test_auth.py

示例3: create_request_user

# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import set_password [as 别名]
def create_request_user(username=None, password=None):
    if username:
        user = UserFactory(username=username)
    else:
        user = UserFactory()
    if password:
        user.set_password(password)
    else:
        user.set_password('password')
    user.save()
    return user
开发者ID:tkdchen,项目名称:Nitrate,代码行数:13,代码来源:__init__.py

示例4: TestDisabledUser

# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import set_password [as 别名]
class TestDisabledUser(OsfTestCase):
    def setUp(self):
        super(TestDisabledUser, self).setUp()
        self.user = UserFactory()
        self.user.set_password("Korben Dallas")
        self.user.is_disabled = True
        self.user.save()

    def test_profile_disabled_returns_401(self):
        res = self.app.get(self.user.url, expect_errors=True)
        assert_equal(res.status_code, 410)
开发者ID:Alpani,项目名称:osf.io,代码行数:13,代码来源:webtest_tests.py

示例5: test_user_check_password

# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import set_password [as 别名]
    def test_user_check_password(self):
        with self.instance.test_request_context() as request:
            u = UserFactory(login='john', email='[email protected]')

            self.assertTrue(u.is_authenticated())
            self.assertTrue(u.is_active())
            self.assertFalse(u.is_anonymous())

            password = '123456'
            u.set_password(password)

            self.assertTrue(u.check_password(password))
开发者ID:clayman74,项目名称:jotun,代码行数:14,代码来源:test_core.py

示例6: create_fake_user

# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import set_password [as 别名]
def create_fake_user():
    email = fake.email()
    name = fake.name()
    parsed = utils.impute_names(name)
    user = UserFactory(username=email, fullname=name,
                       is_registered=True, is_claimed=True,
                       date_registered=fake.date_time(),
                       emails=[email],
                       **parsed
                   )
    user.set_password('faker123')
    user.save()
    logger.info('Created user: {0} <{1}>'.format(user.fullname, user.username))
    return user
开发者ID:baylee-d,项目名称:osf.io,代码行数:16,代码来源:create_fakes.py

示例7: TestAUser

# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import set_password [as 别名]
class TestAUser(OsfTestCase):

    def setUp(self):
        super(TestAUser, self).setUp()
        self.user = UserFactory()
        self.user.set_password('science')
        # Add an API key for quicker authentication
        api_key = ApiKeyFactory()
        self.user.api_keys.append(api_key)
        self.user.save()
        self.auth = ('test', api_key._primary_key)

    def _login(self, username, password):
        '''Log in a user via at the login page.'''
        res = self.app.get('/account/').maybe_follow()
        # Fills out login info
        form = res.forms['signinForm']  # Get the form from its ID
        form['username'] = username
        form['password'] = password
        # submits
        res = form.submit().maybe_follow()
        return res

    def test_can_see_profile_url(self):
        res = self.app.get(self.user.url).maybe_follow()
        assert_in(self.user.url, res)

    def test_can_see_homepage(self):
        # Goes to homepage
        res = self.app.get('/').maybe_follow()  # Redirects
        assert_equal(res.status_code, 200)

    def test_can_log_in(self):
        # Log in and out
        self._login(self.user.username, 'science')
        self.app.get('/logout/')
        # Goes to home page
        res = self.app.get('/').maybe_follow()
        # Clicks sign in button
        res = res.click('Create an Account or Sign-In').maybe_follow()
        # Fills out login info
        form = res.forms['signinForm']  # Get the form from its ID
        form['username'] = self.user.username
        form['password'] = 'science'
        # submits
        res = form.submit().maybe_follow()
        # Sees dashboard with projects and watched projects
        assert_in('Projects', res)
        assert_in('Watchlist', res)

    def test_sees_flash_message_on_bad_login(self):
        # Goes to log in page
        res = self.app.get('/account/').maybe_follow()
        # Fills the form with incorrect password
        form  = res.forms['signinForm']
        form['username'] = self.user.username
        form['password'] = 'thisiswrong'
        # Submits
        res = form.submit()
        # Sees a flash message
        assert_in('Log-in failed', res)

    def test_is_redirected_to_dashboard_already_logged_in_at_login_page(self):
        res = self._login(self.user.username, 'science')
        res = self.app.get('/login/').follow()
        assert_equal(res.request.path, '/dashboard/')

    def test_sees_projects_in_her_dashboard(self):
        # the user already has a project
        project = ProjectFactory(creator=self.user)
        project.add_contributor(self.user)
        project.save()
        # Goes to homepage, already logged in
        res = self._login(self.user.username, 'science')
        res = self.app.get('/').maybe_follow()
        # Clicks Dashboard link in navbar
        res = res.click('Dashboard', index=0)
        assert_in('Projects', res)  # Projects heading
        # The project title is listed
        # TODO: (bgeiger) figure out how to make this assertion work with hgrid view
        #assert_in(project.title, res)

    def test_does_not_see_osffiles_in_user_addon_settings(self):
        res = self._login(self.user.username, 'science')
        res = self.app.get('/settings/addons/', auth=self.auth, auto_follow=True)
        assert_not_in('OSF Storage', res)

    def test_sees_osffiles_in_project_addon_settings(self):
        project = ProjectFactory(creator=self.user)
        project.add_contributor(
            self.user,
            permissions=['read', 'write', 'admin'],
            save=True)
        res = self.app.get('/{0}/settings/'.format(project._primary_key), auth=self.auth, auto_follow=True)
        assert_in('OSF Storage', res)

    @unittest.skip("Can't test this, since logs are dynamically loaded")
    def test_sees_log_events_on_watched_projects(self):
        # Another user has a public project
        u2 = UserFactory(username='[email protected]', fullname='Bono')
#.........这里部分代码省略.........
开发者ID:lbanner,项目名称:osf.io,代码行数:103,代码来源:webtest_tests.py


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