def test_extra_viewer_groups(self): ai = AlgorithmImageFactory() image = ImageFactory() groups = (GroupFactory(), GroupFactory(), GroupFactory()) jobs = create_algorithm_jobs(algorithm_image=ai, images=[image], extra_viewer_groups=groups) for g in groups: assert jobs[0].viewer_groups.filter(pk=g.pk).exists()
def test_extra_viewer_groups(self): ai = AlgorithmImageFactory() civ = ComponentInterfaceValueFactory( interface=ai.algorithm.inputs.get()) groups = (GroupFactory(), GroupFactory(), GroupFactory()) jobs = create_algorithm_jobs(algorithm_image=ai, civ_sets=[{civ}], extra_viewer_groups=groups) for g in groups: assert jobs[0].viewer_groups.filter(pk=g.pk).exists()
def test_m2m_bulk_update(self): """ Bulk update on a m2m field evicts cache for related models. """ group2 = GroupFactory.create(name='group2') MembershipFactory(person=self.person, group=group2, date_joined=datetime.date(2009, 1, 1)).save() person2 = PersonFactory.create(name='person2') MembershipFactory(person=person2, group=self.group, date_joined=datetime.date(2009, 1, 1)).save() self.assertEquals( Person.objects.get(id=self.person.id).groups.order_by( 'membership__date_joined').all()[0].name, 'group1') self.assertEquals( Group.objects.get(id=self.group.id).members.order_by( 'membership__date_joined').all()[0].name, 'person1') Membership.objects.filter(group_id=group2.id).update( date_joined=datetime.date(2007, 1, 1)) self.assertEquals( Person.objects.get(id=self.person.id).groups.order_by( 'membership__date_joined').all()[0].name, 'group2') Membership.objects.filter( group_id=self.group.id, person_id=person2.id).update(date_joined=datetime.date(2006, 1, 1)) self.assertEquals( Group.objects.get(id=self.group.id).members.order_by( 'membership__date_joined').all()[0].name, 'person2')
def test_group_serializers(self): group = GroupFactory() expected = { "members": list(group.members.all()), "name": group.name, "public": group.public, "slug": group.slug, } serializer = GroupSerializer(group) assert serializer.data == expected
def handle(self, *args, **options): call_command("reset_db", "--noinput") call_command("migrate") library = LibraryFactory() UserFactory(username="******", email="*****@*****.**", password="******", is_superuser=True) users = UserFactory.create_batch(2, is_staff=False) GroupFactory.create_batch(5) for author in AuthorFactory.create_batch(10): for book in BookFactory.create_batch(5, author=author, library=library): BookLoanFactory(book=book, borrower=choice(users)) self.stdout.write("All Data reset")
def test_manager_by_permissions(logged_user, donor, secondary_donor): ContentType.objects.first() content_type = ContentType.objects.get(model='donor', app_label='report_metadata') perm = Permission.objects.get(content_type=content_type, codename='view_donor') group = GroupFactory(permissions=(perm, )) UserRoleFactory(user=logged_user, donor=donor, group=group, secondary_donor=secondary_donor) assert UserRole.objects.by_permissions( 'report_metadata.view_donor').count() == 1 assert UserRole.objects.by_permissions( ['report_metadata.view_donor', 'roles.add_userrole']).count() == 0
def test_m2m_bulk_update(self): """ Bulk update on a m2m field evicts cache for related models. """ group2 = GroupFactory.create(name='group2') MembershipFactory(person=self.person, group=group2, date_joined = datetime.date(2009, 1, 1)).save() person2 = PersonFactory.create(name='person2') MembershipFactory(person=person2, group=self.group, date_joined=datetime.date(2009, 1, 1)).save() self.assertEquals(Person.objects.get(id=self.person.id).groups.order_by('membership__date_joined').all()[0].name, 'group1') self.assertEquals(Group.objects.get(id=self.group.id).members.order_by('membership__date_joined').all()[0].name, 'person1') Membership.objects.filter(group_id=group2.id).update(date_joined=datetime.date(2007, 1, 1)) self.assertEquals(Person.objects.get(id=self.person.id).groups.order_by('membership__date_joined').all()[0].name, 'group2') Membership.objects.filter(group_id=self.group.id, person_id=person2.id).update(date_joined=datetime.date(2006, 1, 1)) self.assertEquals(Group.objects.get(id=self.group.id).members.order_by('membership__date_joined').all()[0].name, 'person2')
def helpdesker(helpdesker_conf): import openhelpdesk.defaults from tests.factories import HelpdeskerF, GroupFactory from mezzanine.utils.sites import current_site_id helpdesker_conf = getattr(openhelpdesk.defaults, helpdesker_conf, None) if not helpdesker_conf: return None user = HelpdeskerF( username=helpdesker_conf[0].rstrip('s'), groups=[GroupFactory(name=helpdesker_conf[0], permissions=list(helpdesker_conf[1]))]) # import pdb # pdb.set_trace() if user.sitepermissions.sites.count() == 0: user.sitepermissions.sites.add(current_site_id()) # site_perm, created = user.sitepermissions.get_or_create(user=user) return user
def test_group_addition(self, reverse): job = AlgorithmJobFactory() group = GroupFactory() civ_in, civ_out = ( ComponentInterfaceValueFactory(image=ImageFactory()), ComponentInterfaceValueFactory(image=ImageFactory()), ) job.inputs.add(civ_in) job.outputs.add(civ_out) assert "view_job" not in get_perms(group, job) assert "view_image" not in get_perms(group, civ_in.image) assert "view_image" not in get_perms(group, civ_out.image) if reverse: group.job_set.add(job) else: job.viewer_groups.add(group) assert "view_job" in get_perms(group, job) assert "view_image" in get_perms(group, civ_in.image) assert "view_image" in get_perms(group, civ_out.image)
def helpdesker(helpdesker_conf): import openhelpdesk.defaults from tests.factories import HelpdeskerF, GroupFactory, OrganizationSettingF from mezzanine.utils.sites import current_site_id helpdesker_conf = getattr(openhelpdesk.defaults, helpdesker_conf, None) if not helpdesker_conf: return None username = helpdesker_conf[0].rstrip('s') user = HelpdeskerF( username=username, email='{}@{}'.format(username, TEST_EMAIL_DOMAIN), groups=[GroupFactory(name=helpdesker_conf[0], permissions=list(helpdesker_conf[1]))]) if user.sitepermissions.sites.count() == 0: user.sitepermissions.sites.add(current_site_id()) org_set = OrganizationSettingF(title='Gotham City', email_domain=TEST_EMAIL_DOMAIN) # site_perm, created = user.sitepermissions.get_or_create(user=user) return user
def test_m2m_add_group(self): group2 = GroupFactory.create() p = Person.objects.get(id=self.person.id) self.assertEqual(len(p.groups.all()), 1) MembershipFactory(person=self.person, group=group2).save() self.assertEqual(len(p.groups.all()), 2)
def setUp(self): self.person = PersonFactory.create(name='person1') self.group = GroupFactory.create(name='group1') MembershipFactory(person=self.person, group=self.group,date_joined = datetime.date(2008, 1, 1)).save()
def test_assign_to_unicef_group_ok(): GroupFactory(name='UNICEF User') user = get_user_model().objects.create(username='******', email='*****@*****.**') assert user.groups.count() == 1 assert user.groups.first().name == 'UNICEF User'
def setUp(self): self.person = PersonFactory.create(name='person1') self.group = GroupFactory.create(name='group1') MembershipFactory(person=self.person, group=self.group, date_joined=datetime.date(2008, 1, 1)).save()