From f2e65f0d1a9e6ddbc586cd7e891d83266f269e8f Mon Sep 17 00:00:00 2001
From: Ethan Nguyen <etnguyen03@hotmail.com>
Date: Fri, 23 Apr 2021 10:50:03 -0400
Subject: [PATCH] feat(destinations): add international school import

---
 .../management/commands/import_ceeb.py        | 25 +++++++++++++------
 tjdests/apps/destinations/tests.py            | 16 +++++++++++-
 2 files changed, 33 insertions(+), 8 deletions(-)

diff --git a/tjdests/apps/destinations/management/commands/import_ceeb.py b/tjdests/apps/destinations/management/commands/import_ceeb.py
index e6a13f6..8154ef2 100644
--- a/tjdests/apps/destinations/management/commands/import_ceeb.py
+++ b/tjdests/apps/destinations/management/commands/import_ceeb.py
@@ -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(
diff --git a/tjdests/apps/destinations/tests.py b/tjdests/apps/destinations/tests.py
index 47d218a..8bb6228 100644
--- a/tjdests/apps/destinations/tests.py
+++ b/tjdests/apps/destinations/tests.py
@@ -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())