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


Python UserFactory.save方法代码示例

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


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

示例1: TestSearchExceptions

# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import save [as 别名]
class TestSearchExceptions(OsfTestCase):
    """
    Verify that the correct exception is thrown when the connection is lost
    """

    @classmethod
    def setUpClass(cls):
        logging.getLogger('website.project.model').setLevel(logging.CRITICAL)
        super(TestSearchExceptions, cls).setUpClass()
        if settings.SEARCH_ENGINE == 'elastic':
            cls._es = search.search_engine.es
            search.search_engine.es = None

    @classmethod
    def tearDownClass(cls):
        super(TestSearchExceptions, cls).tearDownClass()
        if settings.SEARCH_ENGINE == 'elastic':
            search.search_engine.es = cls._es

    def test_connection_error(self):
        # Ensures that saving projects/users doesn't break as a result of connection errors
        self.user = UserFactory(usename='Doug Bogie')
        self.project = ProjectFactory(
            title="Tom Sawyer",
            creator=self.user,
            is_public=True,
        )
        self.user.save()
        self.project.save()
开发者ID:PatrickEGorman,项目名称:osf.io,代码行数:31,代码来源:test_elastic.py

示例2: get_redirect_response

# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import save [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

示例3: test_update_comments_viewed_timestamp_none

# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import save [as 别名]
 def test_update_comments_viewed_timestamp_none(self):
     user = UserFactory()
     user.comments_viewed_timestamp = {}
     user.save()
     update_comments_viewed_timestamp()
     user.reload()
     assert_equal(user.comments_viewed_timestamp, {})
开发者ID:AllisonLBowers,项目名称:osf.io,代码行数:9,代码来源:test_update_comments.py

示例4: TestMigrateMailingLists

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

    def setUp(self):
        super(TestMigrateMailingLists, self).setUp()
        self.user1 = UserFactory(mailing_lists={'mail': True})
        self.user2 = UserFactory(mailing_lists={'mail': False})
        self.user3 = UserFactory()
        self.user1.save()
        self.user2.save()

    def test_get_users_with_mailing_lists(self):
        users_with_mailing_list_ids = [user._id for user in get_users_with_no_mailchimp_mailing_lists()]

        assert_equal(len(users_with_mailing_list_ids), 2)

        assert_true(self.user1._id in users_with_mailing_list_ids)
        assert_true(self.user2._id in users_with_mailing_list_ids)
        assert_false(self.user3._id in users_with_mailing_list_ids)

    def test_migration_of_mailing_lists(self):

        assert_equal(self.user1.mailchimp_mailing_lists, {})
        assert_equal(self.user2.mailchimp_mailing_lists, {})

        main()

        self.user1.reload()
        self.user2.reload()
        assert_true(self.user1.mailchimp_mailing_lists.get(u'mail'))
        assert_false(self.user2.mailchimp_mailing_lists.get(u'mail'))
开发者ID:545zhou,项目名称:osf.io,代码行数:32,代码来源:test_migrate_mailing_lists_to_mailchimp_field.py

示例5: test_userfactory

# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import save [as 别名]
def test_userfactory(session):
    user = UserFactory()
    user.save()
    assert isinstance(user, User)
    assert user.id is not None
    assert user.email is not None
    assert user.active is not None
开发者ID:DBeath,项目名称:flask-feedrsub,代码行数:9,代码来源:factory_test.py

示例6: TestSearchExceptions

# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import save [as 别名]
class TestSearchExceptions(OsfTestCase):
    """
    Verify that the correct exception is thrown when the connection is lost
    """

    @classmethod
    def setUpClass(cls):
        super(TestSearchExceptions, cls).setUpClass()
        if settings.SEARCH_ENGINE == "elastic":
            cls._es = search.search_engine.es
            search.search_engine.es = None

    @classmethod
    def tearDownClass(cls):
        super(TestSearchExceptions, cls).tearDownClass()
        if settings.SEARCH_ENGINE == "elastic":
            search.search_engine.es = cls._es

    def test_connection_error(self):
        """
        Ensures that saving projects/users doesn't break as a result of connection errors
        """
        self.user = UserFactory(usename="Doug Bogie")
        self.project = ProjectFactory(title="Tom Sawyer", creator=self.user, is_public=True)
        self.user.save()
        self.project.save()
开发者ID:erinmayhood,项目名称:osf.io,代码行数:28,代码来源:test_elastic.py

示例7: test_multiple_users_associated

# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import save [as 别名]
    def test_multiple_users_associated(self):
        # Create only one ExternalAccount for multiple OSF users
        #
        # For some providers (ex: GitHub), the act of completing the OAuth flow
        # revokes previously generated credentials. In addition, there is often no
        # way to know the user's id on the external service until after the flow
        # has completed.
        #
        # Having only one ExternalAccount instance per account on the external
        # service means that connecting subsequent OSF users to the same external
        # account will not invalidate the credentials used by the OSF for users
        # already associated.
        user_a = UserFactory()
        external_account = ExternalAccountFactory(
            provider='mock2',
            provider_id='mock_provider_id',
            provider_name='Mock Provider',
        )
        user_a.external_accounts.append(external_account)
        user_a.save()

        user_b = UserFactory()

        # Mock the exchange of the code for an access token
        _prepare_mock_oauth2_handshake_response()

        # Fake a request context for the callback
        with self.app.app.test_request_context(
                path="/oauth/callback/mock2/",
                query_string="code=mock_code&state=mock_state"
        ) as ctx:

            # make sure the user is logged in
            authenticate(user=user_b, access_token=None, response=None)

            session = get_session()
            session.data['oauth_states'] = {
                self.provider.short_name: {
                    'state': 'mock_state',
                },
            }
            session.save()

            # do the key exchange
            self.provider.auth_callback(user=user_b)

        user_a.reload()
        user_b.reload()
        external_account.reload()

        assert_equal(
            user_a.external_accounts,
            user_b.external_accounts,
        )

        assert_equal(
            ExternalAccount.find().count(),
            1
        )
开发者ID:GageGaskins,项目名称:osf.io,代码行数:61,代码来源:test_oauth.py

示例8: test_update_comments_viewed_timestamp

# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import save [as 别名]
 def test_update_comments_viewed_timestamp(self):
     user = UserFactory()
     timestamp = datetime.utcnow().replace(microsecond=0)
     user.comments_viewed_timestamp = {'abc123': timestamp}
     user.save()
     update_comments_viewed_timestamp()
     user.reload()
     assert_equal(user.comments_viewed_timestamp, {'abc123': {'node': timestamp}})
开发者ID:AllisonLBowers,项目名称:osf.io,代码行数:10,代码来源:test_update_comments.py

示例9: test_no_two_emails_to_same_person

# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import save [as 别名]
 def test_no_two_emails_to_same_person(self, mock_send):
     user = UserFactory()
     user.osf_mailing_lists[settings.OSF_HELP_LIST] = True
     user.save()
     self.queue_mail(user=user)
     self.queue_mail(user=user)
     main(dry_run=False)
     assert_equal(mock_send.call_count, 1)
开发者ID:545zhou,项目名称:osf.io,代码行数:10,代码来源:test_send_queued_mails.py

示例10: test_login_disabled_user

# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import save [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

示例11: create_request_user

# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import save [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

示例12: TestDisabledUser

# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import save [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

示例13: test_was_not_invited

# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import save [as 别名]
 def test_was_not_invited(self):
     referrer = UserFactory()
     node = NodeFactory(creator=referrer)
     user = UserFactory()
     node.add_contributor(user, auth=Auth(referrer))
     assert_false(is_invited(user))
     user.is_invited = None
     user.save()
     main(dry_run=False)
     user.reload()
     assert_false(user.is_invited)
开发者ID:545zhou,项目名称:osf.io,代码行数:13,代码来源:test_migrate_was_invited.py

示例14: test_name_fields

# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import save [as 别名]
 def test_name_fields(self):
     names = ["Bill Nye", "William", "the science guy", "Sanford", "the Great"]
     user = UserFactory(fullname=names[0])
     user.given_name = names[1]
     user.middle_names = names[2]
     user.family_name = names[3]
     user.suffix = names[4]
     user.save()
     docs = [query_user(name)["results"] for name in names]
     assert_equal(sum(map(len, docs)), len(docs))  # 1 result each
     assert_true(all([user._id == doc[0]["id"] for doc in docs]))
开发者ID:erinmayhood,项目名称:osf.io,代码行数:13,代码来源:test_elastic.py

示例15: test_employment

# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import save [as 别名]
    def test_employment(self):
        user = UserFactory(fullname="Helga Finn")
        user.save()
        institution = "Finn's Fine Filers"

        docs = query_user(institution)["results"]
        assert_equal(len(docs), 0)
        user.jobs.append({"institution": institution, "title": "The Big Finn"})
        user.save()

        docs = query_user(institution)["results"]
        assert_equal(len(docs), 1)
开发者ID:erinmayhood,项目名称:osf.io,代码行数:14,代码来源:test_elastic.py


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