本文整理汇总了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()
示例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
示例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, {})
示例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'))
示例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
示例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()
示例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
)
示例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}})
示例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)
示例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')
示例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
示例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)
示例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)
示例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]))
示例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)