feat(destinations): add international school import

This commit is contained in:
Ethan Nguyen 2021-04-23 10:50:03 -04:00
parent 317a8e0a21
commit f2e65f0d1a
No known key found for this signature in database
GPG Key ID: B4CA5339AF911920
2 changed files with 33 additions and 8 deletions

View File

@ -21,13 +21,24 @@ class Command(BaseCommand):
reader = csv.DictReader(file)
for line in reader:
result = College.objects.update_or_create(
ceeb_code=line["CEEB"],
defaults={
"name": line["College Name"],
"location": f"{line['City']}, {line['State']}",
},
)
# International colleges are treated specially because
# they do not have CEEB codes.
if line["CEEB"] == "INTL":
result = College.objects.update_or_create(
ceeb_code=line["CEEB"],
name=line["College Name"],
defaults={
"location": f"{line['City']}, {line['State']}",
},
)
else:
result = College.objects.update_or_create(
ceeb_code=line["CEEB"],
defaults={
"name": line["College Name"],
"location": f"{line['City']}, {line['State']}",
},
)
if result[1]:
self.stdout.write(

View File

@ -285,7 +285,8 @@ class DestinationsTest(TJDestsTestCase):
file_contents = (
"CEEB,College Name,City,State\n"
"1234,Test University,Alexandria,VA\n"
"1235,University of Test,Arlington,VA"
"1235,University of Test,Arlington,VA\n"
"INTL,University of Abroad,ExampleCity,RANDOMCOUNTRY"
)
with patch(
"tjdests.apps.destinations.management.commands.import_ceeb.open",
@ -307,8 +308,19 @@ class DestinationsTest(TJDestsTestCase):
ceeb_code="1235", name="University of Test", location="Arlington, VA"
).count(),
)
self.assertEqual(1, College.objects.filter(ceeb_code="INTL", name="University of Abroad", location="ExampleCity, RANDOMCOUNTRY").count())
# Doing it again should have no duplicates
# But let's add a few more...
file_contents = (
"CEEB,College Name,City,State\n"
"1234,Test University,Alexandria,VA\n"
"1235,University of Test,Arlington,VA\n"
"INTL,University of Abroad,ExampleCity,RANDOMCOUNTRY\n"
"INTL,University of Abroad in CityTwo,CityTwo,RANDOMCOUNTRY\n"
)
with patch(
"tjdests.apps.destinations.management.commands.import_ceeb.open",
mock_open(read_data=file_contents),
@ -329,3 +341,5 @@ class DestinationsTest(TJDestsTestCase):
ceeb_code="1235", name="University of Test", location="Arlington, VA"
).count(),
)
self.assertEqual(1, College.objects.filter(ceeb_code="INTL", name="University of Abroad", location="ExampleCity, RANDOMCOUNTRY").count())
self.assertEqual(1, College.objects.filter(ceeb_code="INTL", name="University of Abroad in CityTwo", location="CityTwo, RANDOMCOUNTRY").count())