mirror of
https://github.com/ansible/awx.git
synced 2026-02-22 21:46:00 -03:30
Misc fixes for old projects tests
This commit is contained in:
@@ -59,8 +59,8 @@ class ProjectsTest(BaseTransactionTest):
|
|||||||
self.organizations[1].projects.add(project)
|
self.organizations[1].projects.add(project)
|
||||||
for project in self.projects[9:10]:
|
for project in self.projects[9:10]:
|
||||||
self.organizations[2].projects.add(project)
|
self.organizations[2].projects.add(project)
|
||||||
self.organizations[0].projects.add(self.projects[-1])
|
#self.organizations[0].projects.add(self.projects[-1])
|
||||||
self.organizations[9].projects.add(self.projects[-2])
|
#self.organizations[9].projects.add(self.projects[-2])
|
||||||
|
|
||||||
# get the URL for various organization records
|
# get the URL for various organization records
|
||||||
self.a_detail_url = "%s%s" % (self.collection(), self.organizations[0].pk)
|
self.a_detail_url = "%s%s" % (self.collection(), self.organizations[0].pk)
|
||||||
@@ -89,7 +89,9 @@ class ProjectsTest(BaseTransactionTest):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# create some teams in the first org
|
# create some teams in the first org
|
||||||
self.team1.projects.add(self.projects[0])
|
#self.team1.projects.add(self.projects[0])
|
||||||
|
self.projects[0].teams.add(self.team1)
|
||||||
|
#self.team1.projects.add(self.projects[0])
|
||||||
self.team2.projects.add(self.projects[1])
|
self.team2.projects.add(self.projects[1])
|
||||||
self.team2.projects.add(self.projects[2])
|
self.team2.projects.add(self.projects[2])
|
||||||
self.team2.projects.add(self.projects[3])
|
self.team2.projects.add(self.projects[3])
|
||||||
@@ -215,7 +217,7 @@ class ProjectsTest(BaseTransactionTest):
|
|||||||
self.assertEquals(results['count'], 10)
|
self.assertEquals(results['count'], 10)
|
||||||
# org admin
|
# org admin
|
||||||
results = self.get(projects, expect=200, auth=self.get_normal_credentials())
|
results = self.get(projects, expect=200, auth=self.get_normal_credentials())
|
||||||
self.assertEquals(results['count'], 9)
|
self.assertEquals(results['count'], 6)
|
||||||
# user on a team
|
# user on a team
|
||||||
results = self.get(projects, expect=200, auth=self.get_other_credentials())
|
results = self.get(projects, expect=200, auth=self.get_other_credentials())
|
||||||
self.assertEquals(results['count'], 5)
|
self.assertEquals(results['count'], 5)
|
||||||
@@ -296,31 +298,6 @@ class ProjectsTest(BaseTransactionTest):
|
|||||||
got = self.get(proj_playbooks, expect=200, auth=self.get_super_credentials())
|
got = self.get(proj_playbooks, expect=200, auth=self.get_super_credentials())
|
||||||
self.assertEqual(got, self.projects[2].playbooks)
|
self.assertEqual(got, self.projects[2].playbooks)
|
||||||
|
|
||||||
# can list member organizations for projects
|
|
||||||
proj_orgs = reverse('api:project_organizations_list', args=(self.projects[0].pk,))
|
|
||||||
# only usable as superuser
|
|
||||||
got = self.get(proj_orgs, expect=200, auth=self.get_normal_credentials())
|
|
||||||
got = self.get(proj_orgs, expect=200, auth=self.get_super_credentials())
|
|
||||||
self.get(proj_orgs, expect=403, auth=self.get_other_credentials())
|
|
||||||
self.assertEquals(got['count'], 1)
|
|
||||||
self.assertEquals(got['results'][0]['url'], reverse('api:organization_detail', args=(self.organizations[0].pk,)))
|
|
||||||
|
|
||||||
# post to create new org associated with this project.
|
|
||||||
self.post(proj_orgs, data={'name': 'New Org'}, expect=201, auth=self.get_super_credentials())
|
|
||||||
got = self.get(proj_orgs, expect=200, auth=self.get_super_credentials())
|
|
||||||
self.assertEquals(got['count'], 2)
|
|
||||||
|
|
||||||
# Verify that creatorship doesn't imply access if access is removed
|
|
||||||
a_new_proj = self.make_project(created_by=self.other_django_user, playbook_content=TEST_PLAYBOOK)
|
|
||||||
self.organizations[0].admin_role.members.add(self.other_django_user)
|
|
||||||
self.organizations[0].projects.add(a_new_proj)
|
|
||||||
proj_detail = reverse('api:project_detail', args=(a_new_proj.pk,))
|
|
||||||
self.patch(proj_detail, data=dict(description="test"), expect=200, auth=self.get_other_credentials())
|
|
||||||
self.organizations[0].deprecated_admins.remove(self.other_django_user)
|
|
||||||
self.patch(proj_detail, data=dict(description="test_now"), expect=403, auth=self.get_other_credentials())
|
|
||||||
self.delete(proj_detail, expect=403, auth=self.get_other_credentials())
|
|
||||||
a_new_proj.delete()
|
|
||||||
|
|
||||||
# =====================================================================
|
# =====================================================================
|
||||||
# TEAMS
|
# TEAMS
|
||||||
|
|
||||||
@@ -421,7 +398,7 @@ class ProjectsTest(BaseTransactionTest):
|
|||||||
|
|
||||||
team = Team.objects.filter( organization__pk=self.organizations[1].pk)[0]
|
team = Team.objects.filter( organization__pk=self.organizations[1].pk)[0]
|
||||||
team_users = reverse('api:team_users_list', args=(team.pk,))
|
team_users = reverse('api:team_users_list', args=(team.pk,))
|
||||||
for x in team.deprecated_users.all():
|
for x in team.member_role.members.all():
|
||||||
team.member_role.members.remove(x)
|
team.member_role.members.remove(x)
|
||||||
team.save()
|
team.save()
|
||||||
|
|
||||||
@@ -446,7 +423,7 @@ class ProjectsTest(BaseTransactionTest):
|
|||||||
self.post(team_users, data=dict(username='attempted_superuser_create', password='thepassword',
|
self.post(team_users, data=dict(username='attempted_superuser_create', password='thepassword',
|
||||||
is_superuser=True), expect=201, auth=self.get_super_credentials())
|
is_superuser=True), expect=201, auth=self.get_super_credentials())
|
||||||
|
|
||||||
self.assertEqual(Team.objects.get(pk=team.pk).member_role.members.count(), 5)
|
self.assertEqual(Team.objects.get(pk=team.pk).member_role.members.count(), all_users['count'] + 1)
|
||||||
|
|
||||||
# can remove users from teams
|
# can remove users from teams
|
||||||
for x in all_users['results']:
|
for x in all_users['results']:
|
||||||
@@ -454,7 +431,7 @@ class ProjectsTest(BaseTransactionTest):
|
|||||||
self.post(team_users, data=y, expect=403, auth=self.get_nobody_credentials())
|
self.post(team_users, data=y, expect=403, auth=self.get_nobody_credentials())
|
||||||
self.post(team_users, data=y, expect=204, auth=self.get_normal_credentials())
|
self.post(team_users, data=y, expect=204, auth=self.get_normal_credentials())
|
||||||
|
|
||||||
self.assertEquals(Team.objects.get(pk=team.pk).deprecated_users.count(), 1) # Leaving just the super user we created
|
self.assertEquals(Team.objects.get(pk=team.pk).member_role.members.count(), 1) # Leaving just the super user we created
|
||||||
|
|
||||||
# =====================================================================
|
# =====================================================================
|
||||||
# USER TEAMS
|
# USER TEAMS
|
||||||
@@ -465,9 +442,12 @@ class ProjectsTest(BaseTransactionTest):
|
|||||||
self.get(url, expect=401)
|
self.get(url, expect=401)
|
||||||
self.get(url, expect=401, auth=self.get_invalid_credentials())
|
self.get(url, expect=401, auth=self.get_invalid_credentials())
|
||||||
self.get(url, expect=403, auth=self.get_nobody_credentials())
|
self.get(url, expect=403, auth=self.get_nobody_credentials())
|
||||||
other.organizations.add(Organization.objects.get(pk=self.organizations[1].pk))
|
self.organizations[1].member_role.members.add(other)
|
||||||
# Normal user can only see some teams that other user is a part of,
|
# Normal user can only see some teams that other user is a part of,
|
||||||
# since normal user is not an admin of that organization.
|
# since normal user is not an admin of that organization.
|
||||||
|
my_teams1 = self.get(url, expect=200, auth=self.get_normal_credentials())
|
||||||
|
my_teams2 = self.get(url, expect=200, auth=self.get_other_credentials())
|
||||||
|
|
||||||
my_teams1 = self.get(url, expect=200, auth=self.get_normal_credentials())
|
my_teams1 = self.get(url, expect=200, auth=self.get_normal_credentials())
|
||||||
self.assertEqual(my_teams1['count'], 1)
|
self.assertEqual(my_teams1['count'], 1)
|
||||||
# Other user should be able to see all his own teams.
|
# Other user should be able to see all his own teams.
|
||||||
@@ -622,7 +602,7 @@ class ProjectsTest(BaseTransactionTest):
|
|||||||
# Test post as organization admin where team is part of org, but user
|
# Test post as organization admin where team is part of org, but user
|
||||||
# creating credential is not a member of the team. UI may pass user
|
# creating credential is not a member of the team. UI may pass user
|
||||||
# as an empty string instead of None.
|
# as an empty string instead of None.
|
||||||
normal_org = self.normal_django_user.admin_of_organizations.all()[0]
|
normal_org = self.organizations[1] # normal user is an admin of this
|
||||||
org_team = normal_org.teams.create(name='new empty team')
|
org_team = normal_org.teams.create(name='new empty team')
|
||||||
with self.current_user(self.normal_django_user):
|
with self.current_user(self.normal_django_user):
|
||||||
data = {
|
data = {
|
||||||
|
|||||||
Reference in New Issue
Block a user