本文整理汇总了Python中tests.factories.UserFactory方法的典型用法代码示例。如果您正苦于以下问题:Python factories.UserFactory方法的具体用法?Python factories.UserFactory怎么用?Python factories.UserFactory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tests.factories
的用法示例。
在下文中一共展示了factories.UserFactory方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_list
# 需要导入模块: from tests import factories [as 别名]
# 或者: from tests.factories import UserFactory [as 别名]
def test_list(self, monkeypatch, sm_test_data):
site = sm_test_data['site']
org = sm_test_data['organization']
if organizations_support_sites():
caller = UserFactory()
UserOrganizationMappingFactory(user=caller,
organization=org,
is_amc_admin=True)
else:
caller = UserFactory(is_staff=True)
request = APIRequestFactory().get(self.request_path)
request.META['HTTP_HOST'] = site.domain
monkeypatch.setattr(django.contrib.sites.shortcuts,
'get_current_site',
lambda req: site)
force_authenticate(request, user=caller)
view = self.view_class.as_view({'get': 'list'})
response = view(request)
assert response.status_code == status.HTTP_200_OK
示例2: test_site_metrics_list
# 需要导入模块: from tests import factories [as 别名]
# 或者: from tests.factories import UserFactory [as 别名]
def test_site_metrics_list(self, monkeypatch, sm_test_data):
site = sm_test_data['site']
org = sm_test_data['organization']
if organizations_support_sites():
caller = UserFactory()
UserOrganizationMappingFactory(user=caller,
organization=org,
is_amc_admin=True)
else:
caller = UserFactory(is_staff=True)
request = APIRequestFactory().get(self.request_path)
request.META['HTTP_HOST'] = site.domain
monkeypatch.setattr(django.contrib.sites.shortcuts,
'get_current_site',
lambda req: site)
force_authenticate(request, user=caller)
view = self.view_class.as_view({'get': 'list'})
response = view(request)
assert response.status_code == status.HTTP_200_OK
示例3: test_current_user_session_working
# 需要导入模块: from tests import factories [as 别名]
# 或者: from tests.factories import UserFactory [as 别名]
def test_current_user_session_working(session, token, app):
"""
Test the current_user endpoint, using a valid session.
This should work
"""
# Create a user
user = factories.UserFactory()
session.add(user)
session.commit()
# Login with that user (we have to use a custom client here)
with app.test_client(user=user) as client:
rv = client.get("/rest_api/v1/users/current")
# Check the request was successful
assert rv.status_code == 200, rv.json
# Validate the response
schemas.UserSchema().validate(rv.json)
示例4: test_sees_error_message_if_user_already_registered
# 需要导入模块: from tests import factories [as 别名]
# 或者: from tests.factories import UserFactory [as 别名]
def test_sees_error_message_if_user_already_registered(self, user, testapp):
"""Show error if user already registered."""
user = UserFactory(active=True) # A registered user
user.save()
# Goes to registration page
res = testapp.get(url_for("account.signup"))
# Fills out form, but username is already registered
form = res.forms["registerForm"]
form["username"] = user.username
form["email"] = "foo@bar.com"
form["password"] = "secret"
form["confirm"] = "secret"
# Submits
res = form.submit()
# sees error
assert "Username already registered" in res
示例5: test_retrieve
# 需要导入模块: from tests import factories [as 别名]
# 或者: from tests.factories import UserFactory [as 别名]
def test_retrieve(self, monkeypatch, sm_test_data):
monkeypatch.setattr(django.contrib.sites.shortcuts,
'get_current_site',
lambda req: site)
site = sm_test_data['site']
org = sm_test_data['organization']
co = sm_test_data['course_overviews'][0]
if organizations_support_sites():
caller = UserFactory()
UserOrganizationMappingFactory(user=caller,
organization=org,
is_amc_admin=True)
else:
caller = UserFactory(is_staff=True)
request_path = self.request_path + '?pk=' + str(co.id)
request = APIRequestFactory().get(request_path)
request.META['HTTP_HOST'] = site.domain
force_authenticate(request, user=caller)
view = self.view_class.as_view({'get': 'retrieve'})
response = view(request, pk=str(co.id))
assert response.status_code == status.HTTP_200_OK
# TODO: Assert data are correct
示例6: token
# 需要导入模块: from tests import factories [as 别名]
# 或者: from tests.factories import UserFactory [as 别名]
def token(db):
user = factories.UserFactory(is_admin=False)
db.session.add(user)
db.session.commit()
return user.api_token
示例7: admin_token
# 需要导入模块: from tests import factories [as 别名]
# 或者: from tests.factories import UserFactory [as 别名]
def admin_token(db):
user = factories.UserFactory(is_admin=True)
db.session.add(user)
db.session.commit()
return user.api_token
示例8: test_current_user_session_invalid
# 需要导入模块: from tests import factories [as 别名]
# 或者: from tests.factories import UserFactory [as 别名]
def test_current_user_session_invalid(session, client, token):
"""
Test the current_user endpoint, using a valid session.
This should work
"""
# Create a user
user = factories.UserFactory()
session.add(user)
session.commit()
rv = client.get("/rest_api/v1/users/current")
# Check the request was unauthorized
assert rv.status_code == 401
示例9: setUp
# 需要导入模块: from tests import factories [as 别名]
# 或者: from tests.factories import UserFactory [as 别名]
def setUp(self):
self.user = factories.UserFactory()
self.client = Client()
self.response = self.client.query(self.query)
self.data = self.response.json()
示例10: test_factory
# 需要导入模块: from tests import factories [as 别名]
# 或者: from tests.factories import UserFactory [as 别名]
def test_factory(self, db):
"""Test user factory."""
user = UserFactory(password="myprecious")
db.session.commit()
assert bool(user.username)
assert bool(user.email)
assert bool(user.created_at)
assert user.active is True
assert user.check_password("myprecious")