1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-31 15:21:13 +03:00

Fix project migration when project has exactly one org

This commit is contained in:
Akita Noek 2016-04-11 11:44:17 -04:00
parent 5f8e7bbf55
commit 74d86859f1
2 changed files with 43 additions and 2 deletions

View File

@ -274,13 +274,14 @@ def migrate_projects(apps, schema_editor):
original_project_name = project.name
project_orgs = project.deprecated_organizations.distinct().all()
if len(project_orgs) > 1:
if len(project_orgs) >= 1:
first_org = None
for org in project_orgs:
if first_org is None:
# For the first org, re-use our existing Project object, so don't do the below duplication effort
first_org = org
project.name = smart_text(u'{} - {}'.format(first_org.name, original_project_name))
if len(project_orgs) > 1:
project.name = smart_text(u'{} - {}'.format(first_org.name, original_project_name))
project.organization = first_org
project.save()
else:

View File

@ -91,6 +91,46 @@ def test_project_migration():
assert o2.projects.all()[0].jobtemplates.count() == 1
assert o3.projects.all()[0].jobtemplates.count() == 0
@pytest.mark.django_db
def test_single_org_project_migration(organization):
project = Project.objects.create(name='my project',
description="description",
organization=None)
organization.deprecated_projects.add(project)
assert project.organization is None
rbac.migrate_projects(apps, None)
project = Project.objects.get(id=project.id)
assert project.organization.id == organization.id
@pytest.mark.django_db
def test_no_org_project_migration(organization):
project = Project.objects.create(name='my project',
description="description",
organization=None)
assert project.organization is None
rbac.migrate_projects(apps, None)
assert project.organization is None
@pytest.mark.django_db
def test_multi_org_project_migration():
org1 = Organization.objects.create(name="org1", description="org1 desc")
org2 = Organization.objects.create(name="org2", description="org2 desc")
project = Project.objects.create(name='my project',
description="description",
organization=None)
assert Project.objects.all().count() == 1
assert Project.objects.filter(organization=org1).count() == 0
assert Project.objects.filter(organization=org2).count() == 0
project.deprecated_organizations.add(org1)
project.deprecated_organizations.add(org2)
assert project.organization is None
rbac.migrate_projects(apps, None)
assert Project.objects.filter(organization=org1).count() == 1
assert Project.objects.filter(organization=org2).count() == 1
@pytest.mark.django_db
def test_project_user_project(user_project, project, user):
u = user('owner')