class EventProfileTests(TestCase): client = Client() def setUp(self): self.baseURL = "http://*****:*****@test.com") self.user.set_password("1234") self.user.save() self.org1 = Organization( name="test org 1", contact_email="*****@*****.**", organization_type=OrganizationType.objects.get(id=1) ) self.org1.save() self.event = Event( name="test event", description="event description", organization=self.org1, contact_email="*****@*****.**", start_time=timezone.now(), end_time=timezone.now(), location="Berkeley", ) self.event.save() def testViewEventNotLoggedIn(self): """ Tests that we can view the details of a valid event when not logged in """ response = self.client.get(self.baseURL + "/events/" + str(self.event.id)) self.assertTrue(self.event.name in response.content) self.assertTrue(self.event.description in response.content) self.assertTrue(self.event.organization.name in response.content) self.assertTrue(self.event.contact_email in response.content) self.assertTrue(self.event.location in response.content) def testViewEventLoggedIn(self): """ Tests that we can view the details of a valid event when logged in """ self.client.login(username="******", password="******") response = self.client.get(self.baseURL + "/events/" + str(self.event.id)) self.assertTrue(self.event.name in response.content) self.assertTrue(self.event.description in response.content) self.assertTrue(self.event.organization.name in response.content) self.assertTrue(self.event.contact_email in response.content) self.assertTrue(self.event.location in response.content) def tearDown(self): self.client.logout()
class clubProfileTests(TestCase): client = Client(); def setUp(self): self.baseURL = 'http://*****:*****@test.com'); self.user.set_password('1234'); self.user.save(); self.user2 = User(username='******', password='******', email='*****@*****.**'); self.user2.set_password('1234'); self.user2.save(); self.user3 = User(username='******', password='******', email='*****@*****.**'); self.user3.set_password('1234'); self.user3.save(); self.org1 = Organization(name='test org 1', contact_email='*****@*****.**', organization_type=OrganizationType.objects.get(id=1)); self.org2 = Organization(name='test org 2', contact_email='*****@*****.**', organization_type=OrganizationType.objects.get(id=2)); self.org3 = Organization(name='test org 3', contact_email='*****@*****.**', organization_type=OrganizationType.objects.get(id=1)); self.org1.save(); self.org2.save(); self.org3.save(); self.uto1 = UserToOrganization(user=self.user, organization=self.org1).save(); self.uto2 = UserToOrganization(user=self.user2, organization=self.org1, admin=True).save(); def testViewClubNotLoggedIn(self): response = self.client.get(self.baseURL + '/clubs/1'); self.assertTrue(self.org1.name in response.content); self.assertTrue(self.org1.contact_email in response.content); self.assertTrue(self.org1.organization_type.name in response.content); self.assertTrue("Join Club" in response.content); self.assertFalse("Manage" in response.content); def testViewClubLoggedInNotMember(self): self.client.login(username='******', password='******'); response = self.client.get(self.baseURL + '/clubs/1'); self.assertTrue(self.org1.name in response.content); self.assertTrue(self.org1.contact_email in response.content); self.assertTrue(self.org1.organization_type.name in response.content); self.assertTrue("Join Club" in response.content); self.assertFalse("Manage" in response.content); def testViewClubLoggedInMember(self): self.client.login(username='******', password='******'); response = self.client.get(self.baseURL + '/clubs/1'); self.assertTrue(self.org1.name in response.content); self.assertTrue(self.org1.contact_email in response.content); self.assertTrue(self.org1.organization_type.name in response.content); self.assertTrue("You are a member of this club." in response.content); self.assertFalse("Manage" in response.content); def testViewClubLoggedInAdmin(self): self.client.login(username='******', password='******'); response = self.client.get(self.baseURL + '/clubs/1'); self.assertTrue(self.org1.name in response.content); self.assertTrue(self.org1.contact_email in response.content); self.assertTrue(self.org1.organization_type.name in response.content); self.assertTrue("You are a member and admin of this club." in response.content); self.assertTrue("Manage" in response.content); def tearDown(self): self.client.logout();
class UserToEventMappingTests(TestCase): def setUp(self): self.user = User(username='******', password='******', email='*****@*****.**'); self.user.save(); self.org = Organization(name='test org', contact_email='*****@*****.**', organization_type=OrganizationType.objects.get(id=1)); self.org.save(); self.event = Event(name='test 1', contact_email='*****@*****.**', organization=self.org, start_time=timezone.now(), end_time=timezone.now()); self.event2 = Event(name='test 2', contact_email='*****@*****.**', organization=self.org, start_time=timezone.now(), end_time=timezone.now()); self.event3 = Event(name='test 3', contact_email='*****@*****.**', organization=self.org, start_time=timezone.now(), end_time=timezone.now()); self.event.save(); self.event2.save(); self.event3.save(); def testAddValidUserToEventMapping_NoAdmin(self): UserToEvent(user=self.user, event=self.event).save(); ute = UserToEvent.objects.filter(user=self.user); ute = ute[0]; self.assertTrue(ute.user == self.user); self.assertTrue(ute.event == self.event); self.assertFalse(ute.admin); def testAddValidUserToEventMapping_Admin(self): UserToEvent(user=self.user, event=self.event, admin=True).save(); ute = UserToEvent.objects.filter(user=self.user); ute = ute[0]; self.assertTrue(ute.user == self.user); self.assertTrue(ute.event == self.event); self.assertTrue(ute.admin); def testAddValidUserToEventMapping_ManyEvents(self): UserToEvent(user=self.user, event=self.event, admin=True).save(); UserToEvent(user=self.user, event=self.event2).save(); UserToEvent(user=self.user, event=self.event3, admin=True).save(); ute = UserToEvent.objects.filter(user=self.user); ute1 = ute[0]; ute2 = ute[1]; ute3 = ute[2]; self.assertTrue(ute1.user == self.user); self.assertTrue(ute1.event == self.event); self.assertTrue(ute1.admin); self.assertTrue(ute2.user == self.user); self.assertTrue(ute2.event == self.event2); self.assertFalse(ute2.admin); self.assertTrue(ute3.user == self.user); self.assertTrue(ute3.event == self.event3); self.assertTrue(ute3.admin); def testAddValidUserToEventMapping_GetEventsForUser(self): UserToEvent(user=self.user, event=self.event, admin=True).save(); UserToEvent(user=self.user, event=self.event2).save(); UserToEvent(user=self.user, event=self.event3, admin=True).save(); ute = UserToEvent.getEventsForUser(self.user); event_result1 = ute[0]; event_result2 = ute[1]; event_result3 = ute[2]; self.assertTrue(event_result1 == self.event); self.assertTrue(event_result2 == self.event2); self.assertTrue(event_result3 == self.event3); def testInvalidUserToEvent_NoUser(self): try: UserToEvent(event=self.event).save(); except IntegrityError: return True; def testInvalidUserToEvent_NoEvent(self): try: UserToEvent(user=self.user).save(); except IntegrityError: return True; def testInvalidUserToEvent_Duplicate(self): try: UserToEvent(user=self.user, event=self.event).save(); UserToEvent(user=self.user, event=self.event).save(); except IntegrityError: return True;
class UserToOrganizationMappingTests(TestCase): def setUp(self): self.user = User(username='******', password='******', email='*****@*****.**'); self.user.save(); self.org = Organization(name='test org', contact_email='*****@*****.**', organization_type=OrganizationType.objects.get(id=1)); self.org2 = Organization(name='test org 2', contact_email='*****@*****.**', organization_type=OrganizationType.objects.get(id=2)); self.org3 = Organization(name='test org 3', contact_email='*****@*****.**', organization_type=OrganizationType.objects.get(id=1)); self.org.save(); self.org2.save(); self.org3.save(); self.event = Event(name='test 1', contact_email='*****@*****.**', organization=self.org, start_time=timezone.now(), end_time=timezone.now()); self.event.save(); def testAddValidUserToOrganizationMapping_NoAdmin(self): UserToOrganization(user=self.user, organization=self.org).save(); uto = UserToOrganization.objects.filter(user=self.user); uto = uto[0]; self.assertTrue(uto.user == self.user); self.assertTrue(uto.organization == self.org); self.assertFalse(uto.admin); def testAddValidUserToOrganizationMapping_Admin(self): UserToOrganization(user=self.user, organization=self.org, admin=True).save(); uto = UserToOrganization.objects.filter(user=self.user); uto = uto[0]; self.assertTrue(uto.user == self.user); self.assertTrue(uto.organization == self.org); self.assertTrue(uto.admin); def testAddValidUserToEventMapping_ManyOrganizations(self): UserToOrganization(user=self.user, organization=self.org, admin=True).save(); UserToOrganization(user=self.user, organization=self.org2).save(); UserToOrganization(user=self.user, organization=self.org3, admin=True).save(); uto = UserToOrganization.objects.filter(user=self.user); uto1 = uto[0]; uto2 = uto[1]; uto3 = uto[2]; self.assertTrue(uto1.user == self.user); self.assertTrue(uto1.organization == self.org); self.assertTrue(uto1.admin); self.assertTrue(uto2.user == self.user); self.assertTrue(uto2.organization == self.org2); self.assertFalse(uto2.admin); self.assertTrue(uto3.user == self.user); self.assertTrue(uto3.organization == self.org3); self.assertTrue(uto3.admin); def testAddValidUserToEventMapping_GetOrganizationsForUser(self): UserToOrganization(user=self.user, organization=self.org, admin=True).save(); UserToOrganization(user=self.user, organization=self.org2).save(); UserToOrganization(user=self.user, organization=self.org3, admin=True).save(); uto = UserToOrganization.getOrganizationsForUser(self.user); org_result1 = uto[0]; org_result2 = uto[1]; org_result3 = uto[2]; self.assertTrue(org_result1 == self.org); self.assertTrue(org_result2 == self.org2); self.assertTrue(org_result3 == self.org3); def testInvalidUserToOrganization_NoUser(self): try: UserToOrganization(organization=self.org).save(); except IntegrityError: return True; def testInvalidUserToOrganization_NoOrganization(self): try: UserToOrganization(user=self.user).save(); except IntegrityError: return True; def testInvalidUserToOrganization_Duplicate(self): try: UserToOrganization(user=self.user, organization=self.org).save(); UserToOrganization(user=self.user, organization=self.org).save(); except IntegrityError: return True;
class UserDashboardTests(TestCase): client = Client(); def setUp(self): self.baseURL = 'http://*****:*****@test.com'); self.user.set_password('1234'); self.user.save(); self.org1 = Organization(name='test org 1', contact_email='*****@*****.**', organization_type=OrganizationType.objects.get(id=1)); self.org2 = Organization(name='test org 2', contact_email='*****@*****.**', organization_type=OrganizationType.objects.get(id=2)); self.org3 = Organization(name='test org 3', contact_email='*****@*****.**', organization_type=OrganizationType.objects.get(id=1)); self.org1.save(); self.org2.save(); self.org3.save(); self.event1 = Event(name='test 1', contact_email='*****@*****.**', organization=self.org1, start_time=timezone.now(), end_time=timezone.now()); self.event2 = Event(name='test 2', contact_email='*****@*****.**', organization=self.org2, start_time=timezone.now(), end_time=timezone.now()); self.event3 = Event(name='test 3', contact_email='*****@*****.**', organization=self.org3, start_time=timezone.now(), end_time=timezone.now()); self.event1.save(); self.event2.save(); self.event3.save(); self.uto1 = UserToOrganization(user=self.user, organization=self.org1); self.uto2 = UserToOrganization(user=self.user, organization=self.org2); self.uto3 = UserToOrganization(user=self.user, organization=self.org3); self.ute1 = UserToEvent(user=self.user, event=self.event1); self.ute2 = UserToEvent(user=self.user, event=self.event2); self.ute3 = UserToEvent(user=self.user, event=self.event3); self.client.login(username='******', password='******'); def tearDown(self): self.client.logout(); def testValidDashboard_ShowClubEvents(self): self.uto1.save(); self.uto2.save(); self.uto3.save(); response = self.client.get(self.baseURL + '/user'); self.assertTrue(self.event1.name in response.content); self.assertTrue('test 1' in response.content); self.assertTrue('test 2' in response.content); self.assertTrue('test 3' in response.content); def testValidDashboard_ShowSubscribedEvents(self): self.ute1.save(); self.ute2.save(); self.ute3.save(); response = self.client.get(self.baseURL + '/user'); self.assertTrue('test 1' in response.content); self.assertTrue('test 2' in response.content); self.assertTrue('test 3' in response.content); def testValidDashboard_ShowTwoSubscribedEvents(self): self.ute1.save(); self.ute2.save(); response = self.client.get(self.baseURL + '/user'); self.assertTrue('test 1' in response.content); self.assertTrue('test 2' in response.content); def testValidDashboard_ShowOneSubscribedEvents(self): self.ute1.save(); response = self.client.get(self.baseURL + '/user'); self.assertTrue('test 1' in response.content);
class UserProfileTests(TestCase): client = Client(); def setUp(self): self.baseURL = 'http://*****:*****@test.com'); self.user.set_password('1234'); self.user.save(); self.org1 = Organization(name='test org 1', contact_email='*****@*****.**', organization_type=OrganizationType.objects.get(id=1)); self.org2 = Organization(name='test org 2', contact_email='*****@*****.**', organization_type=OrganizationType.objects.get(id=2)); self.org3 = Organization(name='test org 3', contact_email='*****@*****.**', organization_type=OrganizationType.objects.get(id=1)); self.org1.save(); self.org2.save(); self.org3.save(); self.event1 = Event(name='test 1', contact_email='*****@*****.**', organization=self.org1, start_time=timezone.now(), end_time=timezone.now()); self.event2 = Event(name='test 2', contact_email='*****@*****.**', organization=self.org2, start_time=timezone.now(), end_time=timezone.now()); self.event3 = Event(name='test 3', contact_email='*****@*****.**', organization=self.org3, start_time=timezone.now(), end_time=timezone.now()); self.event1.save(); self.event2.save(); self.event3.save(); self.uto1 = UserToOrganization(user=self.user, organization=self.org1); self.uto2 = UserToOrganization(user=self.user, organization=self.org2); self.uto3 = UserToOrganization(user=self.user, organization=self.org3); self.ute1 = UserToEvent(user=self.user, event=self.event1); self.ute2 = UserToEvent(user=self.user, event=self.event2); self.ute3 = UserToEvent(user=self.user, event=self.event3); self.client.login(username='******', password='******'); def tearDown(self): self.client.logout(); def testValidProfile_OneEvent(self): self.ute1.save(); response = self.client.get(self.baseURL + '/user/%d' % self.user.id); self.assertTrue(self.event1.name in response.content); self.assertTrue('href="/events/1"' in response.content); self.assertTrue('href="mailto:[email protected]"' in response.content); self.assertTrue(self.event2.name not in response.content); self.assertTrue('href="/events/2"' not in response.content); self.assertTrue('href="mailto:[email protected]"' not in response.content); self.assertTrue(self.event3.name not in response.content); self.assertTrue('href="/events/3"' not in response.content); self.assertTrue('href="mailto:[email protected]"' not in response.content); def testValidProfile_TwoEvents1(self): self.ute1.save(); self.ute2.save(); response = self.client.get(self.baseURL + '/user/%d' % self.user.id); self.assertTrue(self.event1.name in response.content); self.assertTrue('href="/events/1"' in response.content); self.assertTrue('href="mailto:[email protected]"' in response.content); self.assertTrue(self.event2.name in response.content); self.assertTrue('href="/events/2"' in response.content); self.assertTrue('href="mailto:[email protected]"' in response.content); self.assertTrue(self.event3.name not in response.content); self.assertTrue('href="/events/3"' not in response.content); self.assertTrue('href="mailto:[email protected]"' not in response.content); def testValidProfile_TwoEvents2(self): self.ute1.save(); self.ute3.save(); response = self.client.get(self.baseURL + '/user/%d' % self.user.id); self.assertTrue(self.event1.name in response.content); self.assertTrue('href="/events/1"' in response.content); self.assertTrue('href="mailto:[email protected]"' in response.content); self.assertTrue(self.event2.name not in response.content); self.assertTrue('href="/events/2"' not in response.content); self.assertTrue('href="mailto:[email protected]"' not in response.content); self.assertTrue(self.event3.name in response.content); self.assertTrue('href="/events/3"' in response.content); self.assertTrue('href="mailto:[email protected]"' in response.content); def testValidProfile_ThreeEvents(self): self.ute1.save(); self.ute2.save(); self.ute3.save(); response = self.client.get(self.baseURL + '/user/%d' % self.user.id); self.assertTrue(self.event1.name in response.content); self.assertTrue('href="/events/1"' in response.content); self.assertTrue('href="mailto:[email protected]"' in response.content); self.assertTrue(self.event2.name in response.content); self.assertTrue('href="/events/2"' in response.content); self.assertTrue('href="mailto:[email protected]"' in response.content); self.assertTrue(self.event3.name in response.content); self.assertTrue('href="/events/3"' in response.content); self.assertTrue('href="mailto:[email protected]"' in response.content); def testValidProfile_OneOrg(self): self.uto1.save(); response = self.client.get(self.baseURL + '/user/%d' % self.user.id); self.assertTrue(self.org1.name in response.content); self.assertTrue('href="/clubs/1"' in response.content); self.assertTrue('href="mailto:[email protected]"' in response.content); self.assertTrue(self.org2.name not in response.content); self.assertTrue('href="/clubs/2"' not in response.content); self.assertTrue('href="mailto:[email protected]"' not in response.content); self.assertTrue(self.org3.name not in response.content); self.assertTrue('href="/clubs/3"' not in response.content); self.assertTrue('href="mailto:[email protected]"' not in response.content); def testValidProfile_TwoOrgs1(self): self.uto1.save(); self.uto2.save(); response = self.client.get(self.baseURL + '/user/%d' % self.user.id); self.assertTrue(self.org1.name in response.content); self.assertTrue('href="/clubs/1"' in response.content); self.assertTrue('href="mailto:[email protected]"' in response.content); self.assertTrue(self.org2.name in response.content); self.assertTrue('href="/clubs/2"' in response.content); self.assertTrue('href="mailto:[email protected]"' in response.content); self.assertTrue(self.org3.name not in response.content); self.assertTrue('href="/clubs/3"' not in response.content); self.assertTrue('href="mailto:[email protected]"' not in response.content); def testValidProfile_TwoOrgs2(self): self.uto1.save(); self.uto3.save(); response = self.client.get(self.baseURL + '/user/%d' % self.user.id); self.assertTrue(self.org1.name in response.content); self.assertTrue('href="/clubs/1"' in response.content); self.assertTrue('href="mailto:[email protected]"' in response.content); self.assertTrue(self.org2.name not in response.content); self.assertTrue('href="/clubs/2"' not in response.content); self.assertTrue('href="mailto:[email protected]"' not in response.content); self.assertTrue(self.org3.name in response.content); self.assertTrue('href="/clubs/3"' in response.content); self.assertTrue('href="mailto:[email protected]"' in response.content); def testValidProfile_ThreeOrgs(self): self.uto1.save(); self.uto2.save(); self.uto3.save(); response = self.client.get(self.baseURL + '/user/%d' % self.user.id); self.assertTrue(self.org1.name in response.content); self.assertTrue('href="/clubs/1"' in response.content); self.assertTrue('href="mailto:[email protected]"' in response.content); self.assertTrue(self.org2.name in response.content); self.assertTrue('href="/clubs/2"' in response.content); self.assertTrue('href="mailto:[email protected]"' in response.content); self.assertTrue(self.org3.name in response.content); self.assertTrue('href="/clubs/3"' in response.content); self.assertTrue('href="mailto:[email protected]"' in response.content);
class ManageMembersPageTests(TestCase): client = Client(); def setUp(self): self.baseURL = 'http://*****:*****@test.com'); self.user.set_password('1234'); self.user.save(); self.user2 = User(username='******', password='******', email='*****@*****.**'); self.user2.set_password('1234'); self.user2.save(); self.user3 = User(username='******', password='******', email='*****@*****.**'); self.user3.set_password('1234'); self.user3.save(); self.org1 = Organization(name='test org 1', contact_email='*****@*****.**', organization_type=OrganizationType.objects.get(id=1)); self.org2 = Organization(name='test org 2', contact_email='*****@*****.**', organization_type=OrganizationType.objects.get(id=2)); self.org3 = Organization(name='test org 3', contact_email='*****@*****.**', organization_type=OrganizationType.objects.get(id=1)); self.org1.save(); self.org2.save(); self.org3.save(); self.uto1 = UserToOrganization(user=self.user, organization=self.org1); self.uto1.save(); def testViewManageNotLoggedIn(self): response = self.client.get(self.baseURL + '/clubs/1/manage_members'); self.assertFalse(self.org1.name in response.content); self.assertFalse(self.user.username in response.content); self.assertFalse("promote-button" in response.content); self.assertFalse("demote-button" in response.content); def testViewManageLoggedInNonAdmin(self): self.client.login(username='******', password='******'); response = self.client.get(self.baseURL + '/clubs/1/manage_members'); self.assertTrue(self.org1.name in response.content); self.assertTrue(self.user.username in response.content); self.assertFalse("promote-button" in response.content); self.assertFalse("demote-button" in response.content); def testViewManageLoggedInAdmin(self): self.uto1 = UserToOrganization.objects.get(user=self.user, organization=self.org1); self.uto1.admin = True; self.uto1.save(); self.client.login(username='******', password='******'); response = self.client.get(self.baseURL + '/clubs/1/manage_members'); self.assertTrue(self.org1.name in response.content); self.assertTrue(self.user.username in response.content); self.assertFalse("promote-button" in response.content); self.assertTrue("demote-button" in response.content); def testViewManageLoggedInAdminWithNonAdminMember(self): self.uto1 = UserToOrganization.objects.get(user=self.user, organization=self.org1); self.uto1.admin = True; self.uto1.save(); self.client.login(username='******', password='******'); self.uto2 = UserToOrganization(user=self.user2, organization=self.org1).save(); response = self.client.get(self.baseURL + '/clubs/1/manage_members'); self.assertTrue(self.org1.name in response.content); self.assertTrue(self.user2.username in response.content); self.assertTrue(self.user.username in response.content); self.assertTrue("promote-button" in response.content); self.assertTrue("demote-button" in response.content); def tearDown(self): self.client.logout();
class AdminTests(TestCase): client = Client() def setUp(self): self.baseURL = "http://*****:*****@test.com") self.user.set_password("1234") self.user.save() self.user2 = User(username="******", password="******", email="*****@*****.**") self.user2.set_password("12345") self.user2.save() self.org1 = Organization( name="test org 1", contact_email="*****@*****.**", organization_type=OrganizationType.objects.get(id=1) ) self.org1.save() def testClubCreatorAddedasAdmin(self): """ Tests that the club creator is automatically added as a member to the club and is an admin. """ self.client.login(username="******", password="******") form_data = { "name": "Test Club", "description": "Club Description", "contact_email": "*****@*****.**", "organization_type": 1, } response = self.client.post(self.baseURL + "/clubs/new", form_data) test_club = Organization.objects.get(name="Test Club") test_user = User.objects.get(username="******") self.assertEquals(test_user, UserToOrganization.objects.get(user=test_user, organization=test_club).user) self.assertEquals( test_club, UserToOrganization.objects.get(user=test_user, organization=test_club).organization ) self.assertTrue(UserToOrganization.objects.get(user=test_user, organization=test_club).admin) def testPromoteMembersAsAdmin(self): """ Tests that an admin of a club can promote members to admin and members are promoted to admins. """ # make user an admin self.uto1 = UserToOrganization(user=self.user, organization=self.org1, admin=True) self.uto1.save() # add user2 to club (not as admin) self.uto2 = UserToOrganization(user=self.user2, organization=self.org1) self.uto2.save() # login as user (admin) self.client.login(username="******", password="******") # uto_id is connected to user2, the user we want to promote data = {"org_id": self.org1.id, "uto_id": self.uto2.id} # send data to promote response = self.client.post(self.baseURL + "/user/promote", data) # get the club and user we want to verify directly from db test_club = Organization.objects.get(name="test org 1") test_user = User.objects.get(username="******") # check that the uto is of user2 and org1 self.assertEquals(test_user, UserToOrganization.objects.get(user=test_user, organization=test_club).user) self.assertEquals( test_club, UserToOrganization.objects.get(user=test_user, organization=test_club).organization ) # check that user2 is now an admin self.assertTrue(UserToOrganization.objects.get(user=test_user, organization=test_club).admin) def testPromoteMembersNotAsAdmin(self): """ Tests that a regular member cannot promote other members as admins """ # add user to club (not as admin) self.uto1 = UserToOrganization(user=self.user, organization=self.org1) self.uto1.save() # add user2 to club (not as admin) self.uto2 = UserToOrganization(user=self.user2, organization=self.org1) self.uto2.save() # login as user self.client.login(username="******", password="******") # uto_id is connected to user2, the user we want to promote data = {"org_id": self.org1.id, "uto_id": self.uto2.id} # user tries to promote response = self.client.post(self.baseURL + "/user/promote", data) # get the club and user we want to verify directly from db test_club = Organization.objects.get(name="test org 1") test_user = User.objects.get(username="******") # check that the uto is of user2 and org1 self.assertEquals(test_user, UserToOrganization.objects.get(user=test_user, organization=test_club).user) self.assertEquals( test_club, UserToOrganization.objects.get(user=test_user, organization=test_club).organization ) # check that user2 is NOT an admin self.assertFalse(UserToOrganization.objects.get(user=test_user, organization=test_club).admin) def testDemoteMembersAsAdmin(self): """ Tests that an admin of a club can demote other admins and the selected admins are demoted to members. """ # make user an admin self.uto1 = UserToOrganization(user=self.user, organization=self.org1, admin=True) self.uto1.save() # add user2 to club self.uto2 = UserToOrganization(user=self.user2, organization=self.org1, admin=True) self.uto2.save() # login as user (admin) self.client.login(username="******", password="******") # uto_id is connected to user2, the user we want to demote data = {"org_id": self.org1.id, "uto_id": self.uto2.id} # send data to demote response = self.client.post(self.baseURL + "/user/demote", data) # get the club and user we want to verify directly from db test_club = Organization.objects.get(name="test org 1") test_user = User.objects.get(username="******") # check that the uto is of user2 and org1 self.assertEquals(test_user, UserToOrganization.objects.get(user=test_user, organization=test_club).user) self.assertEquals( test_club, UserToOrganization.objects.get(user=test_user, organization=test_club).organization ) # check that user2 is now not an admin self.assertFalse(UserToOrganization.objects.get(user=test_user, organization=test_club).admin) def testDemoteMembersNotAsAdmin(self): """ Tests that a regular member cannot deomote admins to regular members. """ # add user to club (not as admin) self.uto1 = UserToOrganization(user=self.user, organization=self.org1) self.uto1.save() # add user2 to club self.uto2 = UserToOrganization(user=self.user2, organization=self.org1, admin=True) self.uto2.save() # login as user self.client.login(username="******", password="******") # uto_id is connected to user2, the user we want to demote data = {"org_id": self.org1.id, "uto_id": self.uto2.id} # user tries to demote response = self.client.post(self.baseURL + "/user/demote", data) # get the club and user we want to verify directly from db test_club = Organization.objects.get(name="test org 1") test_user = User.objects.get(username="******") # check that the uto is of user2 and org1 self.assertEquals(test_user, UserToOrganization.objects.get(user=test_user, organization=test_club).user) self.assertEquals( test_club, UserToOrganization.objects.get(user=test_user, organization=test_club).organization ) # check that user2 is still an admin self.assertTrue(UserToOrganization.objects.get(user=test_user, organization=test_club).admin) def testDemoteLastAdmin(self): """ Tests that an admin of a club cannot demote the last/only admin of the club. """ # make user the only admin self.uto1 = UserToOrganization(user=self.user, organization=self.org1, admin=True) self.uto1.save() # login as user (admin) self.client.login(username="******", password="******") # uto_id is connected to user with uto1, the user we want to demote data = {"org_id": self.org1.id, "uto_id": self.uto1.id} # send data to demote response = self.client.post(self.baseURL + "/user/demote", data) # get the club and user we want to verify directly from db test_club = Organization.objects.get(name="test org 1") test_user = User.objects.get(username="******") # check that the uto is of user of uto1 and org1 self.assertEquals(test_user, UserToOrganization.objects.get(user=test_user, organization=test_club).user) self.assertEquals( test_club, UserToOrganization.objects.get(user=test_user, organization=test_club).organization ) # check that user is still an admin self.assertTrue(UserToOrganization.objects.get(user=test_user, organization=test_club).admin) def tearDown(self): self.client.logout()