def test_objects_for_user(self): c1 = ClubFactory() ClubFactory() u = UserFactory() c1.admins.add(u) clubs = Club.objects.for_user(u) assert clubs.count() == 1 assert list(clubs) == [c1] u = UserFactory() clubs = Club.objects.for_user(u) assert clubs.count() == 0
def test_objects_for_user(self): d1 = DepartmentFactory() DepartmentFactory() u = UserFactory() d1.admins.add(u) departments = Department.objects.for_user(u) assert departments.count() == 1 assert list(departments) == [d1] u = UserFactory() departments = Department.objects.for_user(u) assert departments.count() == 0
def test_objects_for_super_user(self): d1 = DepartmentFactory() DepartmentFactory() u = UserFactory(is_superuser=True) d1.admins.add(u) departments = Department.objects.for_user(u) assert departments.count() == Department.objects.all().count()
def test_objects_for_super_user(self): c1 = ClubFactory() ClubFactory() u = UserFactory(is_superuser=True) c1.admins.add(u) clubs = Club.objects.for_user(u) assert clubs.count() == Club.objects.all().count()
def test_objects_for_department_admin(self): c = ClubFactory() d = DepartmentFactory() d.clubs.add(c) u = UserFactory() d.admins.add(u) clubs = Club.objects.for_user(u) assert clubs.count() == 1 assert list(clubs) == [c]
def test_make_mailing_address(self, api_client): u = UserFactory() a = AddressFactory(user=u) res = api_client.post( '/v1/member/{}/address/{}/make_mailing_address/'.format( u.membership_number, a.type)) assert res.status_code == 204 u.profile.refresh_from_db() assert u.profile.mailing_address == a
def test_login_failed(self, gc_client): gc_client.logout() u = UserFactory(password='******') res = gc_client.post('/login/', data={ 'username': u.username, 'password': '******' }) assert res.status_code == 200 assert 'Invalid username or password.' in res.content.decode()
def test_update_on_put(self, api_client): u = UserFactory() ProfileFactory(user=u, subscribe_score=False) res = api_client.put('/v1/member/{}/'.format(u.membership_number), format='json', data={ 'username': u.username, 'membership_number': 'NEW123', 'email': u.email, 'profile': { 'subscribe_score': True, }, }) assert res.status_code == 200 assert res.data['membership_number'] == 'NEW123' assert res.data['profile']['subscribe_score'] is True u.refresh_from_db() u.profile.refresh_from_db() assert u.membership_number == 'NEW123' assert u.profile.subscribe_score
def test_logging_in(self, gc_client): gc_client.logout() u = UserFactory(password='******') res = gc_client.post('/login/?next=/step-1/', data={ 'username': u.username, 'password': '******' }) assert res.status_code == 302 assert res.url == '/step-1/' res = gc_client.get('/login/') assert res.status_code == 302
def test_it_works(self): u = UserFactory() serializer = UserSerializer(u) assert serializer.data == { 'id': u.id, 'membership_number': u.membership_number, 'username': u.username, 'email': u.email, 'first_name': u.first_name, 'last_name': u.last_name, 'is_active': u.is_active, 'category': u.category.id if u.category else None, 'clubcorp': u.clubcorp.id if u.clubcorp else None, 'clubcorp_number': u.clubcorp_number, 'customer_id': u.customer_id, 'home_club': u.home_club.id if u.home_club else None, 'home_club_alternate_1': u.home_club_alternate_1.id if u.home_club_alternate_1 else None, 'home_club_alternate_2': u.home_club_alternate_2.id if u.home_club_alternate_2 else None, 'is_staff': u.is_staff, 'middle_name': u.middle_name, 'option_club': u.option_club.id if u.option_club else None, 'preferred_language': u.preferred_language, 'status': u.status, 'type': u.type.id if u.type else None, 'profile': { 'joined': Whatever(), 'title': u.profile.title, 'dob': Whatever(), 'gender': u.profile.gender, 'employer': u.profile.employer, 'position': u.profile.position, 'statement_cycle_id': u.profile.statement_cycle_id, 'show_in_roster': u.profile.show_in_roster, 'prepaid_cart': u.profile.prepaid_cart, 'email_dues_notice': u.profile.email_dues_notice, 'email_statement': u.profile.email_statement, 'subscribe_score': u.profile.subscribe_score, 'subscribe_clublink_info': u.profile.subscribe_clublink_info, 'subscribe_club_info': u.profile.subscribe_club_info, } }
def test_membership_number_unique(self): UserFactory(membership_number='ABC123') with pytest.raises(IntegrityError): UserFactory(membership_number='ABC123')
def test_invalid_password(self): UserFactory(username='******', password='******') form = LoginForm({'username': '******', 'password': '******'}) assert not form.is_valid()
def test_it_works(self, api_client): u = UserFactory(membership_number='123') res = api_client.get('/v1/member/{}/address/'.format( u.membership_number)) assert res.status_code == 200 assert res.data == MemberAddressSerializer(u.addresses, many=True).data
def test_lookup_field(self, api_client): u = UserFactory() res = api_client.get('/v1/member/{}/'.format(u.membership_number)) assert res.status_code == 200 assert res.data == MemberSerializer(u).data
def test_permissions(self, api_client): api_client.logout() u = UserFactory(password='******') api_client.login(username=u.username, passwd='testpass') res = api_client.get('/v1/member/') assert res.status_code == 403
def test_delete_user_category(self): category = UserCategoryFactory() user = UserFactory(category=category) category.delete() assert User.objects.filter(pk=user.pk).exists()
def test_clean(self): UserFactory(username='******', password='******') form = LoginForm({'username': '******', 'password': '******'}) assert form.is_valid()
def test_null_membership_number(self): UserFactory(membership_number=None) assert User.objects.count() == 1 UserFactory(membership_number=None) assert User.objects.count() == 2