def create_factories(self): self.login = '******' self.password = '******' self.admin = UserFactory(login=self.login, password=self.password) admin_group = AdminPropertyGroupFactory() MembershipFactory.create(user=self.admin, group=admin_group) self.config = ConfigFactory()
def create_factories(self): self.user = UserWithHostFactory.create() self.network_access_group = PropertyGroupFactory.create( name="Member", granted={'network_access'}, ) self.payment_in_default_group = PropertyGroupFactory.create( name="Blocked (finance)", granted={'payment_in_default'}, denied={'network_access'}, ) self.traffic_limit_exceeded_group = PropertyGroupFactory.create( name="Blocked (traffic)", granted={'traffic_limit_exceeded'}, denied={'network_access'}, ) # the user's room needs to be connected to provide `nasipaddress` and `nasportid` self.switch = SwitchFactory.create(host__owner=self.user) PatchPortFactory.create_batch(2, patched=True, switch_port__switch=self.switch, # This needs to be the HOSTS room! room=self.user.hosts[0].room) MembershipFactory.create(user=self.user, group=self.network_access_group, begins_at=datetime.now() + timedelta(-1), ends_at=datetime.now() + timedelta(1)) session.session.execute(hades.radius_property.insert(values=[ ('payment_in_default',), ('traffic_limit_exceeded',), ]))
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 create_user(self, traffic_groups): with self.session.begin(subtransactions=True): user = UserFactory() if traffic_groups is None: traffic_groups = tuple() for group in traffic_groups: MembershipFactory.create(group=group, user=user) return user
def test_no_alternative_dns(self): cache_group = PropertyGroupFactory.create(name="Cache User", granted={'cache_access'}) MembershipFactory.create(user=self.user, group=cache_group, begins_at=datetime.now() + timedelta(-1), ends_at=datetime.now() + timedelta(1)) self.assertEqual(session.session.query(hades.alternative_dns.table).count(), 0)
def test_no_alternative_dns(self): cache_group = PropertyGroupFactory.create(name="Cache User", granted={'cache_access'}) MembershipFactory.create(user=self.user, group=cache_group, begins_at=datetime.now() + timedelta(-1), ends_at=datetime.now() + timedelta(1)) self.assertEqual( session.session.query(hades.alternative_dns.table).count(), 0)
def test_alternative_dns(self): # Nobody is cache user by default self.assertEqual(session.session.query(hades.alternative_dns.table).count(), 0) # add cache group cache_group = PropertyGroupFactory.create(name="Cache User", granted={'cache_access'}) MembershipFactory.create(user=self.user, group=cache_group, begins_at=datetime.now() + timedelta(-1), ends_at=datetime.now() + timedelta(1)) rows = session.session.query(hades.alternative_dns.table).all() ip = self.user.hosts[0].ips[0] self.assertEqual(rows, [(str(ip.address),)])
def test_alternative_dns(self): # Nobody is cache user by default self.assertEqual( session.session.query(hades.alternative_dns.table).count(), 0) # add cache group cache_group = PropertyGroupFactory.create(name="Cache User", granted={'cache_access'}) MembershipFactory.create(user=self.user, group=cache_group, begins_at=datetime.now() + timedelta(-1), ends_at=datetime.now() + timedelta(1)) rows = session.session.query(hades.alternative_dns.table).all() ip = self.user.hosts[0].ips[0] self.assertEqual(rows, [(str(ip.address), )])
def create_factories(self): # We want a user who lives somewhere with a membership! super().create_factories() self.processor = UserFactory.create() self.user = UserWithHostFactory.create() self.membership = MembershipFactory.create(user=self.user, group=self.config.member_group) self.other_room = RoomFactory.create()
def create_factories(self): super().create_factories() u1, u2 = UserFactory.create_batch(2, with_unix_account=True) inconsistent = UserFactory.create(with_unix_account=True, email=None) p_dummy = PropertyGroupFactory.create(name='group_without_grants') pg_member = PropertyGroupFactory.create( name='member', granted={'mail', 'ldap_login_enabled'}) UserWithMembershipFactory.create(membership__group=p_dummy, with_unix_account=True) for user in [u1, u2, inconsistent]: MembershipFactory.create(group=pg_member, user=user) MembershipFactory.create( user=inconsistent, group=PropertyGroupFactory.create( name='some_weird_group', granted={ 'mail' }, # weird, because grants mail, but not ldap_login_enabled ), )
def create_factories(self): self.user = UserWithHostFactory.create() self.network_access_group = PropertyGroupFactory.create( name="Member", granted={'network_access'}, ) self.payment_in_default_group = PropertyGroupFactory.create( name="Blocked (finance)", granted={'payment_in_default'}, denied={'network_access'}, ) self.traffic_limit_exceeded_group = PropertyGroupFactory.create( name="Blocked (traffic)", granted={'traffic_limit_exceeded'}, denied={'network_access'}, ) # the user's room needs to be connected to provide `nasipaddress` and `nasportid` self.switch = SwitchFactory.create(host__owner=self.user) PatchPortFactory.create_batch( 2, patched=True, switch_port__switch=self.switch, # This needs to be the HOSTS room! room=self.user.hosts[0].room) MembershipFactory.create(user=self.user, group=self.network_access_group, begins_at=datetime.now() + timedelta(-1), ends_at=datetime.now() + timedelta(1)) session.session.execute( hades.radius_property.insert(values=[ ('payment_in_default', ), ('traffic_limit_exceeded', ), ]))
def create_factories(self): ConfigFactory.create() self.user = UserFactory.create() self.user_membership = MembershipFactory.create( active_during=closedopen(session.utcnow() - timedelta(weeks=52), None), user=self.user, group=config.member_group) last_month_last = session.utcnow().date().replace(day=1) - timedelta(1) self.membership_fee_current = MembershipFeeFactory.create() self.membership_fee_last = MembershipFeeFactory.create( begins_on=last_month_last.replace(day=1), ends_on=last_month_last)
def payment_in_default_membership(self, now, class_session, user, payment_in_default_group): return MembershipFactory.create(user=user, group=payment_in_default_group, begins_at=now + timedelta(-1), ends_at=now + timedelta(1))
def membership(module_session, user, network_access_group, now): return MembershipFactory.create(user=user, group=network_access_group, active_during=closedopen( now + timedelta(-1), now + timedelta(1)))
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 test_m2m_add_person(self): person2 = PersonFactory.create() g = Group.objects.get(id=self.group.id) self.assertEqual(len(g.members.all()), 1) MembershipFactory(person=person2, group=self.group).save() self.assertEqual(len(g.members.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_str(membership_factory: factories.MembershipFactory) -> None: """Test that the string representation returns a valid str.""" membership = membership_factory.build( tech_group__name="Python", user__email="*****@*****.**" ) assert str(membership) == "[email protected] is a member of Python"
def create_factories(self): super().create_factories() MembershipFactory.create(user=self.user, group=self.payment_in_default_group, begins_at=datetime.now() + timedelta(-1), ends_at=datetime.now() + timedelta(1))
def create_factories(self): super().create_factories() self.user = UserWithHostFactory.create() MembershipFactory.create(user=self.user, group=self.config.member_group) self.test_user_id = self.user.id