def setUp(self):
        # Setup other related objects
        county = County.objects.get(name="Decatur")
        acc = Accusation(**accusation1)
        acc.save()
        race = Race(**race1)
        race.save()

        #Lynching
        self.lynching = Lynching(pca_id="22394")
        self.lynching.save()

        # Named Victim
        self.victim1 = Victim(**named_victim)
        self.victim1.save()
        self.victim1.county = county
        self.victim1.accusation.add(acc)
        self.victim1.race = race
        self.victim1.lynching = self.lynching
        self.victim1.save()

        # Unnamed Victim
        self.victim2 = Victim(**unnamed_victim)
        self.victim2.save()
        self.victim2.county = county
        self.victim2.accusation.add(acc)
        self.victim2.race = race
        self.victim2.lynching = self.lynching
        self.victim2.save()
class LynchingTest(TestCase):
    fixtures = ['demographics.json',]

    def setUp(self):
        # Setup other related objects
        county = County.objects.get(name="Decatur")
        acc = Accusation(**accusation1)
        acc.save()
        race = Race(**race1)
        race.save()

        #Lynching
        self.lynching = Lynching(pca_id="22394")
        self.lynching.save()

        # Named Victim
        self.victim1 = Victim(**named_victim)
        self.victim1.save()
        self.victim1.county = county
        self.victim1.accusation.add(acc)
        self.victim1.race = race
        self.victim1.lynching = self.lynching
        self.victim1.save()

        # Unnamed Victim
        self.victim2 = Victim(**unnamed_victim)
        self.victim2.save()
        self.victim2.county = county
        self.victim2.accusation.add(acc)
        self.victim2.race = race
        self.victim2.lynching = self.lynching
        self.victim2.save()

    def test_pretty_string(self):
        expected = "Lynching of Test Victim, Unknown test race Male in 1893"
        self.assertEqual(expected, self.lynching.pretty_string)

    def test_county_list(self):
        expected = "Decatur"
        county_names = [county.name for county in self.lynching.county_list]
        self.assertTrue(expected in county_names)

    def test_year(self):
        expected = 1893
        self.assertEqual(expected, self.lynching.year)
        self.victim2.date = date(1923, 02, 10)
        self.victim2.save()
        self.assertEqual(1923, self.lynching.year)
    def _handle_row(self, row):
        """
        Processes a single row from the input file.

        :param row:  Dict of a single raw input row.
        """
        data = {
            'name': smart_unicode(row['name'], errors='ignore'),
            'detailed_reason': smart_unicode(row['detailed_reason'], errors='ignore'),
        }
        data['lynching'], created = Lynching.objects.get_or_create(pca_id=row['event_id'])
        data['race'] = self._get_race(row['race_raw'])
        data['gender'] = self._get_gender(row['gender_raw'])
        data['county'] = self._get_county(row['county_raw'])
        data['date'] = self._handle_date(row['date_raw'])
        victim = Victim(**data)
        victim.save()
        self._handle_accusation(victim, row['accusation_raw'])
        self._insert_count += 1
class VictimTest(TestCase):

    def setUp(self):
        self.victim = Victim()
        self.victim.save()

    def test_pretty_name(self):
        # Test no name at all
        self.assertEqual("Unknown Person", self.victim.pretty_name)
        # Add gender
        self.victim.gender = 'M'
        self.victim.save()
        self.assertEqual("Unknown Person", self.victim.pretty_name)
        # Add Race, should change.
        race = Race(label="Test Race")
        self.victim.race = race
        self.victim.save()
        self.assertEqual("Unknown Test Race Male", self.victim.pretty_name)
        # Add actual name
        self.victim.name = "Test Name"
        self.victim.save()
        self.assertEqual("Test Name", self.victim.pretty_name)
 def setUp(self):
     self.victim = Victim()
     self.victim.save()