本文整理汇总了Python中django.contrib.messages.storage.fallback.FallbackStorage方法的典型用法代码示例。如果您正苦于以下问题:Python fallback.FallbackStorage方法的具体用法?Python fallback.FallbackStorage怎么用?Python fallback.FallbackStorage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.messages.storage.fallback
的用法示例。
在下文中一共展示了fallback.FallbackStorage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: from django.contrib.messages.storage import fallback [as 别名]
# 或者: from django.contrib.messages.storage.fallback import FallbackStorage [as 别名]
def setUp(self):
Site.objects.get_or_create(id=settings.SITE_ID, domain='example.com', name='example.com')
self.obj = get_usersettings_model().objects.create(**self.usersettings_data)
self.user = get_user_model().objects.create_superuser(
self.username, self.email, self.password)
self.assertTrue(self.client.login(
username=self.username, password=self.password),
'Failed to login user %s' % self.email)
factory = RequestFactory()
request = factory.get('/admin')
request.user = self.user
request.session = {}
self.request = request
self.settings_admin = SettingsAdmin(get_usersettings_model(), AdminSite())
# Hack to test this function as it calls 'messages.add'
# See https://code.djangoproject.com/ticket/17971
setattr(self.request, 'session', 'session')
messages = FallbackStorage(self.request)
setattr(self.request, '_messages', messages)
示例2: setUp
# 需要导入模块: from django.contrib.messages.storage import fallback [as 别名]
# 或者: from django.contrib.messages.storage.fallback import FallbackStorage [as 别名]
def setUp(self):
get_user_model().objects.create_superuser(self.user_email, self.user_password)
self.assertTrue(self.client.login(
username=self.user_email, password=self.user_password),
'Failed to login user %s' % self.user_email)
get_user_model().objects.create_user('user1@example.com', 'pa$sw0Rd1', is_active=False)
factory = RequestFactory()
self.request = factory.get('/admin')
# Hack to test this function as it calls 'messages.add'
# See https://code.djangoproject.com/ticket/17971
setattr(self.request, 'session', 'session')
messages = FallbackStorage(self.request)
setattr(self.request, '_messages', messages)
示例3: test_login_redirect_to_organization_dashboard
# 需要导入模块: from django.contrib.messages.storage import fallback [as 别名]
# 或者: from django.contrib.messages.storage.fallback import FallbackStorage [as 别名]
def test_login_redirect_to_organization_dashboard(self):
user = UserFactory.create()
org = OrganizationFactory.create()
view = org_views.OrganizationEdit.as_view()
request = HttpRequest()
request.META['HTTP_REFERER'] = '/account/login/'
setattr(request, 'user', user)
setattr(request, 'method', 'GET')
setattr(request, 'session', 'session')
self.messages = FallbackStorage(request)
setattr(request, '_messages', self.messages)
kwargs = {'slug': org.slug}
exp_redirect = reverse('organization:dashboard', kwargs=kwargs)
response = view(request, **kwargs)
assert response.status_code == 302
assert exp_redirect == response['location']
示例4: test_login_redirect_from_org_dashboard_to_dashboard
# 需要导入模块: from django.contrib.messages.storage import fallback [as 别名]
# 或者: from django.contrib.messages.storage.fallback import FallbackStorage [as 别名]
def test_login_redirect_from_org_dashboard_to_dashboard(self):
user = UserFactory.create()
assign_user_policies(user, *[])
org = OrganizationFactory.create()
view = org_views.OrganizationDashboard.as_view()
request = HttpRequest()
request.META['HTTP_REFERER'] = '/account/login/'
setattr(request, 'user', user)
setattr(request, 'method', 'GET')
setattr(request, 'session', 'session')
self.messages = FallbackStorage(request)
setattr(request, '_messages', self.messages)
kwargs = {'slug': org.slug}
def get_full_path():
return '/organizations/{}/'.format(org.slug)
setattr(request, 'get_full_path', get_full_path)
exp_redirect = reverse('core:dashboard')
response = view(request, **kwargs)
assert response.status_code == 302
assert exp_redirect == response['location']
示例5: test_add_log_to_contact
# 需要导入模块: from django.contrib.messages.storage import fallback [as 别名]
# 或者: from django.contrib.messages.storage.fallback import FallbackStorage [as 别名]
def test_add_log_to_contact(self):
logs = models.LogEntry.objects.filter(contact=self.contact)
self.assertEqual(0, len(logs))
self.request = self.request_factory.post(
self.contact.get_absolute_url(),
{'kind': 'in person', 'notes': 'Met at DjangoCon!'}
)
self.request.user = self.user
self.request.current_book = self.book
setattr(self.request, 'session', 'session')
messages = FallbackStorage(self.request)
setattr(self.request, '_messages', messages)
response = views.contact_views.ContactView.as_view()(
self.request,
pk=self.contact.pk,
)
self.assertEqual(302, response.status_code)
logs = models.LogEntry.objects.filter(contact=self.contact)
self.assertEqual(1, len(logs))
示例6: rf
# 需要导入模块: from django.contrib.messages.storage import fallback [as 别名]
# 或者: from django.contrib.messages.storage.fallback import FallbackStorage [as 别名]
def rf():
"""A RequestFactory instance."""
from django.contrib.auth.models import AnonymousUser
from django.contrib.messages.storage.fallback import FallbackStorage
from django.contrib.sessions.backends.db import SessionStore
from django.test.client import RequestFactory as BaseRequestFactory
class RequestFactory(BaseRequestFactory):
def request(self, user=None, **request):
request = super().request(**request)
request.user = AnonymousUser()
request.session = SessionStore()
request._messages = FallbackStorage(request)
return request
return RequestFactory()
示例7: test_register_method
# 需要导入模块: from django.contrib.messages.storage import fallback [as 别名]
# 或者: from django.contrib.messages.storage.fallback import FallbackStorage [as 别名]
def test_register_method(self):
"""undocumented"""
testdata = {
"email": "testuserl@test.com",
"first_name": "Spencer",
"last_name": "Huang",
"password1": "testpassword1",
"password2": "testpassword1",
}
request = self.factory.post("/register", data=testdata)
setattr(request, "session", "ssession")
messages = FallbackStorage(request)
setattr(request, "_messages", messages)
# request = self.factory.post("/register", data=testdata, messages=messages)
response = views.register(request)
assert response.status_code == 302
示例8: test_uploadcsv_post
# 需要导入模块: from django.contrib.messages.storage import fallback [as 别名]
# 或者: from django.contrib.messages.storage.fallback import FallbackStorage [as 别名]
def test_uploadcsv_post(self, generate_csv_file):
"""undocumented"""
# with open(generate_csv_file) as f:
# request = self.factory.post("/upload_csv")
# request = self.factory.post("/upload_csv",
# f=SimpleUploadedFile(f.read(), b"file_content"))
f = generate_csv_file.open()
request = self.factory.post("/upload_csv", {"file": f})
# request.FILES["file"] = f.read()
# request.FILES["file"] = f.read()
# request.FILES['file'].read()
setattr(request, "session", "ssession")
messages = FallbackStorage(request)
setattr(request, "_messages", messages)
response = views.upload_csv(request)
assert response.status_code == 200
# pylint: disable=R0201
示例9: test_assignments_login_post_is_valid
# 需要导入模块: from django.contrib.messages.storage import fallback [as 别名]
# 或者: from django.contrib.messages.storage.fallback import FallbackStorage [as 别名]
def test_assignments_login_post_is_valid(self):
"""undocumented"""
obj = mixer.blend(
"gatorgrouper.Assignment",
assignment_id=1,
assignment_name="Group Project",
description="This is an assignment",
)
class_obj = mixer.blend("gatorgrouper.Semester_Class")
testdata = {
"assignment_id": obj.assignment_id,
"class_id": class_obj.class_id,
"assignment_name": "Group Project",
"description": "it's lab one",
}
request = self.factory.post("/assignments", data=testdata)
setattr(request, "session", "ssession")
messages = FallbackStorage(request)
setattr(request, "_messages", messages)
# response = views.create_classes(request)
request.user = self.user
response = views.assignments(request)
assert response.status_code == 200
示例10: test_add_students_post
# 需要导入模块: from django.contrib.messages.storage import fallback [as 别名]
# 或者: from django.contrib.messages.storage.fallback import FallbackStorage [as 别名]
def test_add_students_post(self):
"""undocumented"""
mixer.blend("gatorgrouper.Student", first_name="test", last_name="user")
class_obj = mixer.blend("gatorgrouper.Semester_Class")
testdata = {
"class_id": class_obj.class_id,
"first_name": "test",
"last_name": "user",
}
request = self.factory.post("/add-students", data=testdata)
request.user = self.user
setattr(request, "session", "ssession")
messages = FallbackStorage(request)
setattr(request, "_messages", messages)
response = views.add_students(request)
assert response.status_code == 200
示例11: request
# 需要导入模块: from django.contrib.messages.storage import fallback [as 别名]
# 或者: from django.contrib.messages.storage.fallback import FallbackStorage [as 别名]
def request(self, **request):
request["user"] = None
request = super(RequestFactory, self).request(**request)
request.user = AnonymousUser()
request.session = SessionStore()
request._messages = FallbackStorage(request)
return request
示例12: post_request
# 需要导入模块: from django.contrib.messages.storage import fallback [as 别名]
# 或者: from django.contrib.messages.storage.fallback import FallbackStorage [as 别名]
def post_request(self, post_data={}, params=None):
request = self.factory.post("/", data=post_data)
request.user = self.superuser
request._dont_enforce_csrf_checks = True
request.session = "session"
request._messages = FallbackStorage(request)
return request
示例13: __init__
# 需要导入模块: from django.contrib.messages.storage import fallback [as 别名]
# 或者: from django.contrib.messages.storage.fallback import FallbackStorage [as 别名]
def __init__(self):
super().__init__()
self._messages = FallbackStorage(self)
示例14: request
# 需要导入模块: from django.contrib.messages.storage import fallback [as 别名]
# 或者: from django.contrib.messages.storage.fallback import FallbackStorage [as 别名]
def request(self, user=None, **request):
request = super(RequestFactory, self).request(**request)
request.user = AnonymousUser()
request.session = SessionStore()
request._messages = FallbackStorage(request)
return request
示例15: test_signup_with_released_email
# 需要导入模块: from django.contrib.messages.storage import fallback [as 别名]
# 或者: from django.contrib.messages.storage.fallback import FallbackStorage [as 别名]
def test_signup_with_released_email(self):
user = UserFactory.create(username='user1',
email='user1@example.com',
phone=None,
email_verified=True,
password='sgt-pepper',
measurement='metric')
EmailAddress.objects.create(user=user, email=user.email,
verified=True)
data = {
'username': 'user1',
'email': 'user1_email_change@example.com',
'language': 'en',
'measurement': 'metric',
'password': 'sgt-pepper'
}
request = HttpRequest()
setattr(request, 'session', 'session')
self.messages = FallbackStorage(request)
setattr(request, '_messages', self.messages)
request.META['SERVER_NAME'] = 'testserver'
request.META['SERVER_PORT'] = '80'
form = forms.ProfileForm(data, request=request, instance=user)
form.save()
assert EmailAddress.objects.filter(
email="user1@example.com").exists() is False
with pytest.raises(IntegrityError):
user = UserFactory.create(username='user2',
email='user1@example.com')