def test_private_team_is_not_open_to_public(self): team = Team(name="Team Awesome", private=True) team.save() response = self.client.get(reverse('team-detail', kwargs={'pk':team.pk})) self.assertEqual(response.status_code, 403)
def test_can_create_new_team(self): original_count = Team.objects.all().count() team = Team(name="Team Awesome") team.save() sleep(1) self.assertEqual(Team.objects.all().count(), original_count+1)
def test_can_create_new_team(self): original_count = Team.objects.all().count() team = Team(name="Team Awesome") team.save() sleep(1) self.assertEqual(Team.objects.all().count(), original_count + 1)
def test_default_team_hides_objects(self): import django_teams.models django_teams.models.CurrentUser = User.objects.get(pk=1) Team.objects.all().delete() Ownership.objects.all().delete() TeamStatus.objects.all().delete() team1 = Team(name="Team Mtn Dew") team1.save() team1.add_user(django_teams.models.CurrentUser, team_role=20) team2 = Team(name="Team ROFLCAT") team2.save() team2.add_user(django_teams.models.CurrentUser, team_role=20) site1 = Site.objects.get(pk=2) Ownership.grant_ownership(team1, site1) site2 = Site.objects.get(pk=3) Ownership.grant_ownership(team2, site2) django_teams.models.CurrentTeam = team2 override_manager(Site) site_test = Site.objects.get(pk=3) self.assertEqual(site_test, site2) self.assertEqual(Site.objects.all().count(), 1) self.assertEqual(Site.objects.all()[0].id, 3) self.assertEqual(Site.objects.all()[0], site2) django_teams.models.CurrentUser = None django_teams.models.CurrentTeam = None
def test_can_get_list_of_object_types(self): team = Team(name="Team Awesome") team.save() user = User.objects.get(pk=1) Ownership.grant_ownership(team, user) self.assertIn(User, team.owned_object_types())
def test_private_team_is_not_open_to_public(self): team = Team(name="Team Awesome", private=True) team.save() response = self.client.get( reverse('team-detail', kwargs={'pk': team.pk})) self.assertEqual(response.status_code, 403)
def test_can_approve_user(self): team = Team(name="Team Alpha") team.save() self.user = User.objects.create_user(username='******', password='******') ts = TeamStatus(team=team, user=self.user, role=1) ts.save() ts.approve() self.assertEqual(ts.role, 10)
def test_display_post(self): user = User.objects.create(username='******', password='******') user.save() team = Team(name='team10') team.save() ts = TeamStatus.objects.create(team=team, user=user, role=20) response = self.client.get(reverse('team-list')) self.assertContains(response, str(ts.team)) self.assertContains(response, str(ts.user))
def test_page_contains_all_teams(self): Team(name="Team Awesome").save() Team(name="Team Silly").save() Team(name="Hamburger").save() self.assertTrue(Team.objects.all().count() > 0) response = self.client.get(reverse('team-list')) for team in Team.objects.all(): self.assertContains(response, team.__unicode__())
def test_can_add_user_to_team(self): team = Team(name="Team Awesome") team.save() user = User.objects.get(pk=1) original_count = team.users.all().count() team.add_user(user) sleep(1) self.assertEqual(team.users.all().count(), original_count+1)
def test_can_tell_admin_info_page(self): """Verify that we can access the update info page """ team = Team(name="Team Awesome") team.save() user = User.objects.get(pk=1) team.add_user(user, team_role=20) self.client.login(username='******', password='******') response = self.client.get(reverse('team-info-edit', kwargs={'pk':team.pk})) self.client.logout()
def test_restricted_related_managers(self): # If we override the user, we should have no access to any groups import django_teams.models django_teams.models.CurrentUser = User.objects.get(pk=1) team1 = Team(name="Team Mtn Dew") team1.save() team1.add_user(django_teams.models.CurrentUser, team_role=20) Ownership.grant_ownership(team1, django_teams.models.CurrentUser) override_manager(User) self.assertEqual(User.objects.all().count(), 1) self.assertEqual(django_teams.models.CurrentUser.groups.all().count(), 0)
def test_can_get_list_of_object_types(self): team = Team(name="Team Awesome") team.save() user = User.objects.get(pk=1) Ownership.grant_ownership(team, user) owned_object_types = [] ownership_set = Ownership.objects.select_related('team').filter( team=team) for ownership in ownership_set.iterator(): if ownership.content_type.model_class() not in owned_object_types: owned_object_types += [ownership.content_type.model_class()] self.assertIn(User, owned_object_types)
def test_can_tell_admin_page(self): """Verify text asserting that this is the admin page """ team = Team(name="Team Awesome") team.save() user = User.objects.get(pk=1) team.add_user(user, team_role=20) self.client.login(username='******', password='******') response = self.client.get(reverse('team-edit', kwargs={'pk':team.pk})) self.client.logout() self.assertContains(response, str(team)) self.assertContains(response, "admin")
def test_can_get_owned_objects(self): team = Team(name="Team Awesome") team.save() user = User.objects.get(pk=1) Ownership.grant_ownership(team, user) contenttype = ContentType.objects.get_for_model(User) owned_objects = [] ownership_set = Ownership.objects.select_related( 'team', 'content_type').filter(team=team, content_type=contenttype) for ownership in ownership_set.iterator(): owned_objects += [ownership.content_object] self.assertIn(user, owned_objects)
def test_non_leader_cant_access_page(self): """Non-admin users should not be able to access this page at all """ team = Team(name="Team Awesome") team.save() user = User.objects.get(pk=1) team.add_user(user, team_role=10) self.client.login(username='******', password='******') response = self.client.get(reverse('team-edit', kwargs={'pk':team.pk})) self.assertEqual(response.status_code, 403) self.client.logout()
def test_can_gain_access(self): import django_teams.models django_teams.models.CurrentUser = User.objects.get(pk=1) self.assertEqual(Site.objects.all().count(), 3) site = Site.objects.get(pk=1) override_manager(Site) # Try granting the user access to one site team = Team(name="Team awesome") team.save() team.add_user(django_teams.models.CurrentUser, team_role=20) Ownership.grant_ownership(team, site) self.assertEqual(Site.objects.all().count(), 1)
def test_can_get_team_owners(self): team = Team(name="Team Awesome") team.save() user = User.objects.get(pk=1) team.add_user(user, team_role=20) self.assertIn(user, team.owners())
def test_cant_approve_user_with_no_invite(self): team = Team(name="Team Awesome") team.save() user = User.objects.get(pk=1) ts_count = TeamStatus.objects.filter(user=user, team=team).count() self.assertEqual(ts_count, 0) # Should throw error DNE try: team.approve_user(user) except ObjectDoesNotExist as dne: pass ts_count = TeamStatus.objects.filter(user=user, team=team).count() self.assertEqual(ts_count, 0)
def test_can_get_approved_objects(self): team = Team(name="Team Awesome") team.save() ownership1 = Ownership(team=team, approved=True, object_id=1, content_type_id=1) ownership1.save() ownership2 = Ownership(team=team, approved=True, object_id=2, content_type_id=2) ownership2.save() ownership3 = Ownership(team=team, approved=False, object_id=3, content_type_id=3) ownership3.save() approved_objects = team.approved_objects() self.assertIn(ownership1, approved_objects) self.assertIn(ownership2, approved_objects) self.assertNotIn(ownership3, approved_objects)
def test_can_get_team_owners(self): team = Team(name="Team Awesome") team.save() user = User.objects.get(pk=1) team.add_user(user, team_role=20) owners = team.users.filter(teamstatus__role=20) self.assertIn(user, owners)
def test_can_add_user_to_team(self): team = Team(name="Team Awesome") team.save() user = User.objects.get(pk=1) original_count = team.users.all().count() team.add_user(user) sleep(1) self.assertEqual(team.users.all().count(), original_count + 1)
def test_can_tell_admin_page(self): """Verify text asserting that this is the admin page """ team = Team(name="Team Awesome") team.save() user = User.objects.get(pk=1) team.add_user(user, team_role=20) self.client.login(username='******', password='******') response = self.client.get(reverse('team-edit', kwargs={'pk': team.pk})) self.client.logout() self.assertContains(response, team.__unicode__()) self.assertContains(response, "admin")
def test_can_approve_user(self): team = Team(name="Team Awesome") team.save() user = User.objects.get(pk=1) original_count = team.users.all().count() team.add_user(user) sleep(1) self.assertEqual(team.users.all().count(), original_count + 1) ts = TeamStatus.objects.filter(user=user, team=team).reverse()[0] self.assertEqual(ts.role, 1) team.approve_user(user) ts = TeamStatus.objects.filter(user=user, team=team).reverse()[0] self.assertEqual(ts.role, 10)
def test_non_leader_cant_access_page(self): """Non-admin users should not be able to access this page at all """ team = Team(name="Team Awesome") team.save() user = User.objects.get(pk=1) team.add_user(user, team_role=10) self.client.login(username='******', password='******') response = self.client.get(reverse('team-edit', kwargs={'pk': team.pk})) self.assertEqual(response.status_code, 403) self.client.logout()
def test_can_approve_user(self): team = Team(name="Team Awesome") team.save() user = User.objects.get(pk=1) original_count = team.users.all().count() team.add_user(user) sleep(1) self.assertEqual(team.users.all().count(), original_count+1) ts = TeamStatus.objects.filter(user=user, team=team).reverse()[0] self.assertEqual(ts.role, 1) team.approve_user(user) ts = TeamStatus.objects.filter(user=user, team=team).reverse()[0] self.assertEqual(ts.role, 10)
def test_cant_approve_user_with_no_invite(self): team = Team(name="Team Awesome") team.save() user = User.objects.get(pk=1) ts_count = TeamStatus.objects.filter(user=user, team=team).count() self.assertEqual(ts_count, 0) # Should throw error DNE try: team.approve_user(user) except ObjectDoesNotExist: pass ts_count = TeamStatus.objects.filter(user=user, team=team).count() self.assertEqual(ts_count, 0)
def test_can_get_absolute_url(self): team = Team(name="Team Awesome") team.save() self.assertEqual(team.get_absolute_url(), '/teams/%d/' % team.pk)