Fix typo in backfill_orgs_and_org_courses dry-run call (#25859)

Also, add test to confirm fix of typo.

TNL-7774
This commit is contained in:
Kyle McCormick
2020-12-11 11:13:35 -05:00
committed by GitHub
parent 1584d9ab76
commit f5134e1201
2 changed files with 28 additions and 17 deletions

View File

@@ -82,7 +82,7 @@ class Command(BaseCommand):
({"short_name": orgslug}, courseid)
for orgslug, courseid in sorted(orgslug_courseid_pairs)
]
if not confirm_changes(options, orgs, orgslug_courseid_pairs):
if not confirm_changes(options, orgs, org_courseid_pairs):
print("No changes applied.")
return
print("Applying changes...")
@@ -91,7 +91,7 @@ class Command(BaseCommand):
print("Changes applied successfully.")
def confirm_changes(options, orgs, orgslug_courseid_pairs):
def confirm_changes(options, orgs, org_courseid_pairs):
"""
Should we apply the changes to the database?
@@ -112,7 +112,7 @@ def confirm_changes(options, orgs, orgslug_courseid_pairs):
if options.get('apply'):
return True
organizations_api.bulk_add_organizations(orgs, dry_run=True)
organizations_api.bulk_add_organization_courses(orgslug_courseid_pairs, dry_run=True)
organizations_api.bulk_add_organization_courses(org_courseid_pairs, dry_run=True)
if options.get('dry'):
return False
answer = ""

View File

@@ -38,7 +38,8 @@ class BackfillOrgsAndOrgCoursesTest(SharedModuleStoreTestCase):
`course_overviews`, `modulestore`, and `organizations`, respectively.
"""
def test_end_to_end(self):
@ddt.data("--dry", "--apply")
def test_end_to_end(self, run_type):
"""
Test the happy path of the backfill command without any mocking.
"""
@@ -86,20 +87,30 @@ class BackfillOrgsAndOrgCoursesTest(SharedModuleStoreTestCase):
assert len(get_organization_courses(get_organization_by_short_name('org_B'))) == 0
# Run the backfill.
call_command("backfill_orgs_and_org_courses", "--apply")
call_command("backfill_orgs_and_org_courses", run_type)
# Confirm ending condition:
# All five orgs present. Each org a has expected number of org-course linkages.
assert set(
org["short_name"] for org in get_organizations()
) == {
"org_A", "org_B", "org_C", "org_D", "org_E"
}
assert len(get_organization_courses(get_organization_by_short_name('org_A'))) == 2
assert len(get_organization_courses(get_organization_by_short_name('org_B'))) == 0
assert len(get_organization_courses(get_organization_by_short_name('org_C'))) == 3
assert len(get_organization_courses(get_organization_by_short_name('org_D'))) == 1
assert len(get_organization_courses(get_organization_by_short_name('org_E'))) == 0
if run_type == "--dry":
# Confirm ending conditions are the same as the starting conditions.
assert set(
org["short_name"] for org in get_organizations()
) == {
"org_A", "org_B"
}
assert len(get_organization_courses(get_organization_by_short_name('org_A'))) == 1
assert len(get_organization_courses(get_organization_by_short_name('org_B'))) == 0
else:
# Confirm ending condition:
# All five orgs present. Each org a has expected number of org-course linkages.
assert set(
org["short_name"] for org in get_organizations()
) == {
"org_A", "org_B", "org_C", "org_D", "org_E"
}
assert len(get_organization_courses(get_organization_by_short_name('org_A'))) == 2
assert len(get_organization_courses(get_organization_by_short_name('org_B'))) == 0
assert len(get_organization_courses(get_organization_by_short_name('org_C'))) == 3
assert len(get_organization_courses(get_organization_by_short_name('org_D'))) == 1
assert len(get_organization_courses(get_organization_by_short_name('org_E'))) == 0
@ddt.data(
{