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 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 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)
Beispiel #4
0
    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 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)
Beispiel #6
0
    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 setUp(self):
        bus_org_type = OrganizationType.objects.get(name='Business');
        cs_org_type = OrganizationType.objects.get(name='Computer Science');

        self.baseURL = 'http://*****:*****@test.com');
        self.user.set_password('1234');
        self.user.save();


    	self.c = Client();


        Organization(name="Test Club", description="Club Description", contact_email="*****@*****.**", organization_type=bus_org_type).save();
        self.club = Organization.objects.get(name="Test Club");

        self.uto = UserToOrganization(user=self.user, organization=self.club, admin=True).save();
        self.c.login(username='******', password='******');
class AddEventFunctionalTests(TestCase):

	# Test cases:
    # -- Valid Event: succeed
    # -- Valid Event, no description: succeed
    # -- Valid Event, no location: succeed
    # -- Valid Event, name = 128 chars: succeed
    # -- Valid Event, email = 128 chars: succeed

    def setUp(self):
        bus_org_type = OrganizationType.objects.get(name='Business');
        cs_org_type = OrganizationType.objects.get(name='Computer Science');

        self.baseURL = 'http://*****:*****@test.com');
        self.user.set_password('1234');
        self.user.save();


    	self.c = Client();


        Organization(name="Test Club", description="Club Description", contact_email="*****@*****.**", organization_type=bus_org_type).save();
        self.club = Organization.objects.get(name="Test Club");

        self.uto = UserToOrganization(user=self.user, organization=self.club, admin=True).save();
        self.c.login(username='******', password='******');

    def tearDown(self):
        self.c.logout();

    def testValidEvent1(self):
        startTime = '9/24/2040 5:03:29 PM'
        endTime = '9/24/2050 5:03:29 PM'

        form_data = {
            'name': 'Test Event',
            'description': 'Event Description',
            'organization': 1,
            'contact_email': '*****@*****.**',
            'start_time': str(startTime),
            'end_time': str(endTime),
            'location': 'Berkeley',
        };

        response = self.c.post(self.baseURL+'/events/new', form_data);
        
        test_event = Event.objects.get(name="Test Event");

        self.assertTrue(test_event.name == 'Test Event');
        self.assertTrue(test_event.description == 'Event Description');
        self.assertTrue(test_event.contact_email == '*****@*****.**');
        self.assertTrue(test_event.location == 'Berkeley');

    def testValidEvent2(self):
        startTime = '9/24/2040 5:03:29 PM'
        endTime = '9/24/2050 5:03:29 PM'

        form_data = {
            'name': 'Test Event',
            'contact_email': '*****@*****.**',
            'start_time': str(startTime),
            'end_time': str(endTime),
            'organization': self.club.id,
            'location': 'Berkeley'
        };

        response = self.c.post(self.baseURL+'/events/new', form_data);

        test_event = Event.objects.get(name="Test Event");

        self.assertTrue(test_event.name == 'Test Event');
        self.assertTrue(test_event.location == 'Berkeley');
        self.assertTrue(test_event.contact_email == '*****@*****.**');
    
    def testValidEvent3(self):
        startTime = '9/24/2040 5:03:29 PM'
        endTime = '9/24/2050 5:03:29 PM'

        form_data = {
            'name': 'Test Event',
            'description': 'Event Description',
            'contact_email': '*****@*****.**',
            'start_time': str(startTime),
            'end_time': str(endTime),
            'organization': self.club.id,
        };

        response = self.c.post(self.baseURL+'/events/new', form_data);

        test_event = Event.objects.get(name="Test Event");

        self.assertTrue(test_event.name == 'Test Event');
        self.assertTrue(test_event.description == 'Event Description');
        self.assertTrue(test_event.contact_email == '*****@*****.**');

    def testValidEvent4(self):
        startTime = '9/24/2040 5:03:29 PM'
        endTime = '9/24/2050 5:03:29 PM'

        form_data = {
            'name': 'a'*128,
            'description': 'Event Description',
            'contact_email': '*****@*****.**',
            'start_time': str(startTime),
            'end_time': str(endTime),
            'organization': self.club.id,
        };

        response = self.c.post(self.baseURL+'/events/new', form_data);

        test_event = Event.objects.get(name="a"*128);

        self.assertTrue(test_event.name == 'a'*128);
        self.assertTrue(test_event.description == 'Event Description');
        self.assertTrue(test_event.contact_email == '*****@*****.**');

    def testValidEvent5(self):
        startTime = '9/24/2040 5:03:29 PM'
        endTime = '9/24/2050 5:03:29 PM'

        email_128 = ("a"*119) + "@test.com";

        self.assertTrue(len(email_128) == 128);

        form_data = {
            'name': 'Test Event',
            'description': 'Event Description',
            'contact_email': email_128,
            'start_time': str(startTime),
            'end_time': str(endTime),
            'organization': self.club.id,
        };

        response = self.c.post(self.baseURL+'/events/new', form_data);

        test_event = Event.objects.get(name="Test Event");

        self.assertTrue(test_event.name == 'Test Event');
        self.assertTrue(test_event.description == 'Event Description');
        self.assertTrue(test_event.contact_email == email_128);

    def testAddEventasNonAdmin(self):
        self.uto = UserToOrganization.objects.get(user=self.user, organization=self.club);
        self.uto.admin = False;
        self.uto.save();

        startTime = '9/24/2040 5:03:29 PM'
        endTime = '9/24/2050 5:03:29 PM'

        form_data = {
            'name': 'Test Event',
            'description': 'Event Description',
            'organization': 1,
            'contact_email': '*****@*****.**',
            'start_time': str(startTime),
            'end_time': str(endTime),
            'location': 'Berkeley',
        };

        response = self.c.post(self.baseURL+'/events/new', form_data);

        self.assertTrue("Select a valid choice. That choice is not one of the available choices." in response.content);

        error = False;
        try:
            Event.objects.get(name="Test Event");
        except:
            error = True;

        self.assertTrue(error);
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);
Beispiel #10
0
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);
Beispiel #11
0
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()