mirror of
https://github.com/etnguyen03/tjdests.git
synced 2025-04-20 09:40:16 -04:00
feat(destinations): add international school import
This commit is contained in:
parent
317a8e0a21
commit
f2e65f0d1a
|
@ -21,13 +21,24 @@ class Command(BaseCommand):
|
||||||
reader = csv.DictReader(file)
|
reader = csv.DictReader(file)
|
||||||
|
|
||||||
for line in reader:
|
for line in reader:
|
||||||
result = College.objects.update_or_create(
|
# International colleges are treated specially because
|
||||||
ceeb_code=line["CEEB"],
|
# they do not have CEEB codes.
|
||||||
defaults={
|
if line["CEEB"] == "INTL":
|
||||||
"name": line["College Name"],
|
result = College.objects.update_or_create(
|
||||||
"location": f"{line['City']}, {line['State']}",
|
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]:
|
if result[1]:
|
||||||
self.stdout.write(
|
self.stdout.write(
|
||||||
|
|
|
@ -285,7 +285,8 @@ class DestinationsTest(TJDestsTestCase):
|
||||||
file_contents = (
|
file_contents = (
|
||||||
"CEEB,College Name,City,State\n"
|
"CEEB,College Name,City,State\n"
|
||||||
"1234,Test University,Alexandria,VA\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(
|
with patch(
|
||||||
"tjdests.apps.destinations.management.commands.import_ceeb.open",
|
"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"
|
ceeb_code="1235", name="University of Test", location="Arlington, VA"
|
||||||
).count(),
|
).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
|
# 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(
|
with patch(
|
||||||
"tjdests.apps.destinations.management.commands.import_ceeb.open",
|
"tjdests.apps.destinations.management.commands.import_ceeb.open",
|
||||||
mock_open(read_data=file_contents),
|
mock_open(read_data=file_contents),
|
||||||
|
@ -329,3 +341,5 @@ class DestinationsTest(TJDestsTestCase):
|
||||||
ceeb_code="1235", name="University of Test", location="Arlington, VA"
|
ceeb_code="1235", name="University of Test", location="Arlington, VA"
|
||||||
).count(),
|
).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())
|
||||||
|
|
Loading…
Reference in New Issue
Block a user