本文整理汇总了Python中kawaz.core.personas.tests.factories.PersonaFactory类的典型用法代码示例。如果您正苦于以下问题:Python PersonaFactory类的具体用法?Python PersonaFactory怎么用?Python PersonaFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PersonaFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AnnouncementAddPermissionTestCase
class AnnouncementAddPermissionTestCase(TestCase):
def setUp(self):
self.nerv = PersonaFactory(role='nerv')
self.user = PersonaFactory()
self.wille = PersonaFactory(role='wille')
self.anonymous = AnonymousUser()
def test_staffs_have_add_announcement_perm(self):
"""
スタッフはお知らせを作成する権限を持つ
"""
self.assertTrue(self.nerv.has_perm(
'announcements.add_announcement'))
def test_users_dont_have_add_announcement_perm(self):
"""
ログインユーザーはお知らせを作成する権限を持たない
"""
self.assertFalse(self.user.has_perm(
'announcements.add_announcement'))
def test_wille_dont_have_add_announcement_perm(self):
"""
Willeユーザーはお知らせを作成する権限を持たない
"""
self.assertFalse(self.wille.has_perm(
'announcements.add_announcement'))
def test_anonymous_dont_have_add_announcement_perm(self):
"""
非ログインユーザーはお知らせを作成する権限を持たない
"""
self.assertFalse(self.anonymous.has_perm(
'announcements.add_announcement'))
示例2: ProfileEditPermissionTestCase
class ProfileEditPermissionTestCase(TestCase):
def setUp(self):
self.user = PersonaFactory()
self.anonymous = AnonymousUser()
self.profile = ProfileFactory()
def test_owner_can_change_profile(self):
'''Tests owner has change permission of Profile'''
self.assertTrue(self.profile.user.has_perm('profiles.change_profile', obj=self.profile))
def test_others_cannot_change_profile(self):
'''Tests others don't have change permission of Profile'''
self.assertFalse(self.user.has_perm('profiles.change_profile', obj=self.profile))
def test_anonymous_cannot_change_profile(self):
'''Tests anonymous don't have change permission of Profile'''
self.assertFalse(self.anonymous.has_perm('profiles.change_profile', obj=self.profile))
def test_owner_cannot_delete_profile(self):
'''Tests owner don't have delete permission of Profile'''
self.assertFalse(self.profile.user.has_perm('profiles.delete_profile', obj=self.profile))
def test_others_cannot_delete_profile(self):
'''Tests others don't have delete permission of Profile'''
self.assertFalse(self.user.has_perm('profiles.delete_profile', obj=self.profile))
def test_anonymous_cannot_delete_profile(self):
'''Tests anonymous don't have delete permission of Profile'''
self.assertFalse(self.anonymous.has_perm('profiles.delete_profile', obj=self.profile))
示例3: setUp
def setUp(self):
self.user = PersonaFactory()
self.user.set_password('password')
self.user.save()
self.wille = PersonaFactory(role='wille')
self.wille.set_password('password')
self.wille.save()
示例4: AccountEditPermissionTestCase
class AccountEditPermissionTestCase(TestCase):
def setUp(self):
self.user = PersonaFactory()
self.anonymous = AnonymousUser()
self.account = AccountFactory()
def test_owner_cannot_change_account(self):
'''Tests owners don't have change permission of Account'''
self.assertFalse(self.account.user.has_perm('profiles.change_account', obj=self.account))
def test_others_cannot_change_account(self):
'''Tests others don't have change permission of Account'''
self.assertFalse(self.user.has_perm('profiles.change_account', obj=self.account))
def test_anonymous_cannot_change_account(self):
'''Tests anonymous don't have change permission of Account'''
self.assertFalse(self.anonymous.has_perm('profiles.change_account', obj=self.account))
def test_owner_can_delete_account(self):
'''Tests owners have delete permission of Account'''
self.assertTrue(self.account.user.has_perm('profiles.delete_account', obj=self.account))
def test_others_cannot_delete_account(self):
'''Tests others don't have delete permission of Account'''
self.assertFalse(self.user.has_perm('profiles.delete_account', obj=self.account))
def test_anonymous_cannot_delete_account(self):
'''Tests anonymous don't have delete permission of Account'''
self.assertFalse(self.anonymous.has_perm('profiles.delete_account', obj=self.account))
示例5: setUp
def setUp(self):
self.user = PersonaFactory(username='author_kawaztan')
self.user.set_password('password')
self.other = PersonaFactory(username='black_kawaztan')
self.user.save()
self.other.save()
self.entry = EntryFactory(title='かわずたんだよ☆', author=self.user)
示例6: ProjectJoinViewTestCase
class ProjectJoinViewTestCase(TestCase):
def setUp(self):
self.project = ProjectFactory()
self.user = PersonaFactory()
self.user.set_password('password')
self.user.save()
def test_anonymous_cannnot_join_project(self):
'''
Tests anonymous users attempt to access to ProjectJoinViewTestCase with GET method,
redirects to Login page.
'''
r = self.client.get('/projects/1/join/')
self.assertRedirects(r, '{0}?next={1}'.format(settings.LOGIN_URL, '/projects/1/join/'))
def test_get_method_is_not_allowed(self):
'''
Tests authorized attempt to access to ProjectJoinViewTestCase with GET method,
it returns 405
'''
self.assertTrue(self.client.login(username=self.user, password='password'))
r = self.client.get('/projects/1/join/')
self.assertEqual(r.status_code, 405)
def test_user_can_join_project_via_project_join_view(self):
'''
Tests user can join to project via ProjectJoinView
then redirects to project permalinks
'''
self.assertTrue(self.client.login(username=self.user, password='password'))
r = self.client.post('/projects/1/join/')
self.assertRedirects(r, '/projects/{}/'.format(self.project.slug))
self.assertEqual(self.project.members.count(), 2)
self.assertTrue(self.user in self.project.members.all())
示例7: AnnouncementAddPermissionTestCase
class AnnouncementAddPermissionTestCase(TestCase):
def setUp(self):
self.nerv = PersonaFactory(role='nerv')
self.user = PersonaFactory()
self.wille = PersonaFactory(role='wille')
self.anonymous = AnonymousUser()
def test_staffs_have_add_announcement_permission(self):
'''
Tests staffs have permission to add announcements
'''
self.assertTrue(self.nerv.has_perm('announcements.add_announcement'))
def test_users_dont_have_add_announcement_permission(self):
'''
Tests users do not have permission to add announcements
'''
self.assertFalse(self.user.has_perm('announcements.add_announcement'))
def test_wille_dont_have_add_announcement_permission(self):
'''
Tests wille users do not have permission to add announcements
'''
self.assertFalse(self.wille.has_perm('announcements.add_announcement'))
def test_anonymous_dont_have_add_announcement_permission(self):
'''
Tests anonymous users do not have permission to add announcements
'''
self.assertFalse(self.anonymous.has_perm('announcements.add_announcement'))
示例8: EntryDetailViewTestCase
class EntryDetailViewTestCase(TestCase):
def setUp(self):
self.user = PersonaFactory()
self.user.set_password('password')
self.user.save()
def test_anonymous_user_can_view_public_entry(self):
'''Tests anonymous user can view public entry'''
entry = EntryFactory()
r = self.client.get(entry.get_absolute_url())
self.assertTemplateUsed(r, 'blogs/entry_detail.html')
self.assertEqual(r.context_data['object'], entry)
def test_authorized_user_can_view_public_entry(self):
'''Tests authorized user can view public entry'''
entry = EntryFactory()
self.assertTrue(self.client.login(username=self.user, password='password'))
r = self.client.get(entry.get_absolute_url())
self.assertTemplateUsed(r, 'blogs/entry_detail.html')
self.assertEqual(r.context_data['object'], entry)
def test_anonymous_user_can_not_view_protected_entry(self):
'''Tests anonymous user can not view protected entry'''
entry = EntryFactory(pub_state='protected')
r = self.client.get(entry.get_absolute_url())
self.assertRedirects(r, '{0}?next={1}'.format(settings.LOGIN_URL, entry.get_absolute_url()))
def test_authorized_user_can_view_protected_entry(self):
'''Tests authorized user can view public entry'''
entry = EntryFactory(pub_state='protected')
self.assertTrue(self.client.login(username=self.user, password='password'))
r = self.client.get(entry.get_absolute_url())
self.assertTemplateUsed(r, 'blogs/entry_detail.html')
self.assertEqual(r.context_data['object'], entry)
def test_anonymous_user_can_not_view_draft_entry(self):
'''Tests anonymous user can not view draft entry'''
entry = EntryFactory(pub_state='draft')
r = self.client.get(entry.get_absolute_url())
self.assertRedirects(r, '{0}?next={1}'.format(settings.LOGIN_URL, entry.get_absolute_url()))
def test_others_can_not_view_draft_entry(self):
'''
Tests others can not view draft entry
User will redirect to '/entries/1/update/'
'''
entry = EntryFactory(pub_state='draft')
self.assertTrue(self.client.login(username=self.user, password='password'))
r = self.client.get(entry.get_absolute_url())
self.assertRedirects(r, settings.LOGIN_URL + '?next=/blogs/{}/1/update/'.format(entry.author.username))
def test_organizer_can_view_draft_entry(self):
'''Tests organizer can view draft entry on update view'''
entry = EntryFactory(pub_state='draft', author=self.user)
self.assertTrue(self.client.login(username=self.user, password='password'))
r = self.client.get(entry.get_absolute_url())
self.assertTemplateUsed(r, 'blogs/entry_form.html')
self.assertEqual(r.context_data['object'], entry)
示例9: test_member_cannot_join_project
def test_member_cannot_join_project(self):
'''Tests already member user cannot join to projects'''
user = PersonaFactory()
self.project.join(user)
# django-permissionのキャッシュ対応
user = Persona.objects.get(pk=user.pk)
self.assertFalse(user.has_perm('projects.join_project', self.project))
示例10: setUp
def setUp(self):
self.user = PersonaFactory()
self.user.set_password('password')
self.other = PersonaFactory()
self.other.set_password('password')
self.user.save()
self.other.save()
self.event = EventFactory(title='変更前のイベントです',
organizer=self.user)
示例11: EventListViewTestCase
class EventListViewTestCase(TestCase):
def setUp(self):
arguments_list = (
(-3, -2, {'pub_state':'public'}), # 2000/9/1 ~ 2000/9/2
(1, 2, {'pub_state':'public'}), # 2000/9/5 ~ 2000/9/6
(-2, -1, {'pub_state':'protected'}), # 2000/9/3 ~ 2000/9/4
(0, 1, {'pub_state':'protected'}), # 2000/9/4 ~ 2000/9/5
(-3, -2, {'pub_state':'draft'}), # 2000/9/2 ~ 2000/9/3
(1, 2, {'pub_state':'draft'}), # 2000/9/5 ~ 2000/9/6
)
self.events = [event_factory_with_relative(*args)
for args in arguments_list]
self.user = PersonaFactory()
self.user.set_password('password')
self.user.save()
def test_anonymous_can_view_only_public_events(self):
'''
Tests anonymous user can view public Events only.
The protected events are not displayed.
'''
user = AnonymousUser()
r = self.client.get('/events/')
self.assertTemplateUsed('events/event_list.html')
self.assertTrue('object_list', r.context_data)
list = r.context_data['object_list']
self.assertEqual(list.count(), 1, 'object_list has one event')
self.assertEqual(list[0], self.events[1], '2000/9/5 ~ 6 public')
def test_authenticated_can_view_all_publish_events(self):
'''
Tests authenticated user can view all published events.
'''
self.assertTrue(self.client.login(username=self.user,
password='password'))
r = self.client.get('/events/')
self.assertTemplateUsed('events/event_list.html')
self.assertTrue('object_list', r.context_data)
list = r.context_data['object_list']
self.assertEqual(list.count(), 2, 'object_list has two events')
self.assertEqual(list[0], self.events[3], '2000/9/5 ~ 6 protected')
self.assertEqual(list[1], self.events[1], '2000/9/5 ~ 6 public')
def test_list_with_categories(self):
"""
イベントリストでCategoryのfilterが有効になっている
"""
category = CategoryFactory()
event1 = EventFactory(category=category)
event2 = EventFactory()
self.assertTrue(self.client.login(username=self.user,
password='password'))
r = self.client.get('/events/?category={}'.format(category.pk))
self.assertTemplateUsed(r, 'events/event_list.html')
self.assertEqual(r.context['filter'].qs.count(), 1)
self.assertTrue(event1 in r.context['filter'].qs)
示例12: setUp
def setUp(self):
self.announcements = (
AnnouncementFactory(),
AnnouncementFactory(pub_state='protected'),
AnnouncementFactory(pub_state='draft'),
)
self.user = PersonaFactory()
self.user.set_password('password')
self.user.save()
self.wille = PersonaFactory(role='wille')
self.wille.set_password('password')
self.wille.save()
示例13: setUp
def setUp(self):
self.entries = (
EntryFactory(),
EntryFactory(pub_state='protected'),
EntryFactory(pub_state='draft'),
)
self.user = PersonaFactory()
self.user.set_password('password')
self.user.save()
self.wille = PersonaFactory(role='wille')
self.wille.set_password('password')
self.wille.save()
示例14: EntryAuthorMonthArchiveViewTestCase
class EntryAuthorMonthArchiveViewTestCase(TestCase):
def setUp(self):
self.user = PersonaFactory()
self.user.set_password('password')
self.user.save()
self.wille = PersonaFactory(role='wille')
self.wille.set_password('password')
self.wille.save()
self.entries = (
EntryFactory(),
EntryFactory(author=self.user),
EntryFactory(pub_state='protected'),
EntryFactory(pub_state='protected', author=self.user),
EntryFactory(pub_state='draft'),
)
def test_anonymous_can_view_only_public_entries_of_the_author(self):
'''
Tests anonymous user can view public Entry written by specific author in the month only.
The protected entries are not displayed.
'''
user = AnonymousUser()
entry = self.entries[0]
lt = get_local_time(entry.published_at)
r = self.client.get('/blogs/{0}/{1}/{2}/'.format(self.user.username, lt.year, lt.month))
self.assertTemplateUsed('blogs/entry_archive_month.html')
self.assertTrue('object_list' in r.context_data)
list = r.context_data['object_list']
self.assertEqual(list.count(), 1, 'object_list has one entry')
self.assertEqual(list[0], self.entries[1])
def test_wille_can_view_only_public_entries_of_the_author(self):
'''
Tests wille user can view public Entry written by specific author in the month only.
The protected entries are not displayed.
'''
self.assertTrue(self.client.login(username=self.wille, password='password'))
entry = self.entries[0]
lt = get_local_time(entry.published_at)
r = self.client.get('/blogs/{0}/{1}/{2}/'.format(self.user.username, lt.year, lt.month))
self.assertTemplateUsed('blogs/entry_archive_month.html')
self.assertTrue('object_list' in r.context_data)
list = r.context_data['object_list']
self.assertEqual(list.count(), 1, 'object_list has one entry')
self.assertEqual(list[0], self.entries[1])
def test_authenticated_can_view_all_publish_entries_of_the_author(self):
'''
Tests authenticated user can view all published entries written by specific author in the month.
'''
entry = self.entries[0]
self.assertTrue(self.client.login(username=self.user, password='password'))
lt = get_local_time(entry.published_at)
r = self.client.get('/blogs/{0}/{1}/{2}/'.format(self.user.username, lt.year, lt.month))
self.assertTemplateUsed('blogs/entry_archive_month.html')
self.assertTrue('object_list' in r.context_data)
list = r.context_data['object_list']
self.assertEqual(list.count(), 2, 'object_list has two entries')
self.assertEqual(list[0], self.entries[3], 'protected')
self.assertEqual(list[1], self.entries[1], 'public')
示例15: ProductDeletePermissionTestCase
class ProductDeletePermissionTestCase(TestCase):
def setUp(self):
self.product = ProductFactory()
self.user = PersonaFactory()
self.wille = PersonaFactory(role='wille')
self.anonymous = AnonymousUser()
def test_anonymous_dont_have_delete_permission(self):
'''
Test anonymous users do not have delete product permission
'''
self.assertFalse(self.anonymous.has_perm('products.delete_product'))
def test_wille_dont_have_delete_permission(self):
'''
Test wille users do not have delete product permission
'''
self.assertFalse(self.wille.has_perm('products.delete_product'))
def test_general_user_have_delete_permission(self):
'''
Test general user have delete product permission
'''
self.assertTrue(self.user.has_perm('products.delete_product'))
def test_anonymous_dont_have_delete_permission_with_object(self):
'''
Test anonymous users do not have delete product permission
'''
self.assertFalse(self.anonymous.has_perm('products.delete_product', self.product))
def test_wille_dont_have_delete_permission_with_object(self):
'''
Test wille users do not have delete product permission
'''
self.assertFalse(self.wille.has_perm('products.delete_product', self.product))
def test_other_user_dont_have_delete_permission_with_object(self):
'''
Test other user don't have delete product permission
'''
self.assertFalse(self.user.has_perm('products.delete_product', self.product))
def test_administrators_have_delete_permission_with_object(self):
'''
Test administrators have delete product permission
'''
self.product.administrators.add(self.user)
self.assertTrue(self.user.has_perm('products.delete_product', self.product))