def test_locate_targets_special_multiple_only(self): self.CONGRESS_CAMPAIGN.campaign_subtype = 'lower' (special_target_one, created_one) = Target.get_or_create('us:bioguide:P000197', cache=self.mock_cache) # Pelosi (special_target_two, created_two) = Target.get_or_create('us:bioguide:R000570', cache=self.mock_cache) # Ryan (special_target_three, created_three) = Target.get_or_create( 'us:bioguide:C001037', cache=self.mock_cache) # Capuano self.CONGRESS_CAMPAIGN.target_set = [ special_target_one, special_target_two, special_target_three ] self.CONGRESS_CAMPAIGN.include_special = INCLUDE_SPECIAL_ONLY uids = locate_targets(self.mock_location, self.CONGRESS_CAMPAIGN, cache=self.mock_cache) self.assertEqual(len(uids), 1) # should only get overlap between special and location # in this case, just Capuano first = self.us_data.get_uid(uids[0])[0] self.assertEqual(first['chamber'], 'house') self.assertEqual(first['state'], 'MA')
def test_locate_targets_special_multiple_first(self): self.CONGRESS_CAMPAIGN.campaign_subtype = 'lower' (special_target_one, created_one) = Target.get_or_create('us:bioguide:P000197', cache=self.mock_cache) # Pelosi (special_target_two, created_two) = Target.get_or_create('us:bioguide:R000570', cache=self.mock_cache) # Ryan (special_target_three, created_three) = Target.get_or_create( 'us:bioguide:C001037', cache=self.mock_cache) # Capuano self.CONGRESS_CAMPAIGN.target_set = [ special_target_one, special_target_two, special_target_three ] self.CONGRESS_CAMPAIGN.include_special = INCLUDE_SPECIAL_FIRST uids = locate_targets(self.mock_location, self.CONGRESS_CAMPAIGN, cache=self.mock_cache) self.assertEqual(len(uids), 3) # should get targets in order, with location match first first = self.us_data.get_uid(uids[0])[0] self.assertEqual(first['chamber'], 'house') self.assertEqual(first['state'], 'MA') second = self.us_data.get_uid(uids[1])[0] self.assertEqual(second['chamber'], 'house') self.assertEqual(second['state'], 'CA') third = self.us_data.get_uid(uids[2])[0] self.assertEqual(third['chamber'], 'house') self.assertEqual(third['state'], 'WI')
def test_locate_targets_special_multiple_after(self): self.CONGRESS_CAMPAIGN.campaign_subtype = 'lower' (special_target_one, created_one) = Target.get_or_create('us:bioguide:P000197', cache=self.mock_cache) # Pelosi (special_target_two, created_two) = Target.get_or_create('us:bioguide:R000570', cache=self.mock_cache) # Ryan self.CONGRESS_CAMPAIGN.target_set = [ special_target_one, special_target_two ] self.CONGRESS_CAMPAIGN.include_special = INCLUDE_SPECIAL_AFTER uids = locate_targets(self.mock_location, self.CONGRESS_CAMPAIGN, cache=self.mock_cache) self.assertEqual(len(uids), 3) first = self.us_data.get_uid(uids[0])[0] self.assertEqual(first['chamber'], 'house') self.assertEqual(first['state'], 'MA') second = self.us_data.get_uid(uids[1])[0] self.assertEqual(second['chamber'], 'house') self.assertEqual(second['last_name'], 'Pelosi') self.assertEqual(second['state'], 'CA') third = self.us_data.get_uid(uids[2])[0] self.assertEqual(third['chamber'], 'house') self.assertEqual(third['last_name'], 'Ryan') self.assertEqual(third['state'], 'WI')
def test_locate_targets_special_after(self): self.CONGRESS_CAMPAIGN.campaign_subtype = 'upper' (special_target, created) = Target.get_or_create('us:bioguide:S000033', cache=self.mock_cache) # Bernie self.CONGRESS_CAMPAIGN.target_set = [ special_target, ] self.CONGRESS_CAMPAIGN.include_special = INCLUDE_SPECIAL_AFTER uids = locate_targets(self.mock_location, self.CONGRESS_CAMPAIGN, cache=self.mock_cache) self.assertEqual(len(uids), 3) first = self.us_data.get_uid(uids[0])[0] self.assertEqual(first['chamber'], 'senate') self.assertEqual(first['state'], 'MA') second = self.us_data.get_uid(uids[1])[0] self.assertEqual(second['chamber'], 'senate') self.assertEqual(second['state'], 'MA') third = self.us_data.get_uid(uids[2])[0] self.assertEqual(third['chamber'], 'senate') self.assertEqual(third['state'], 'VT') self.assertEqual(third['last_name'], 'Sanders')
def test_locate_targets_special_only_outside_location(self): self.CONGRESS_CAMPAIGN.campaign_subtype = 'upper' (special_target, created) = Target.get_or_create('us:bioguide:S000033', cache=self.mock_cache) # Bernie self.CONGRESS_CAMPAIGN.target_set = [ special_target, ] self.CONGRESS_CAMPAIGN.include_special = INCLUDE_SPECIAL_ONLY # mock_location is outside of special targets uids = locate_targets(self.mock_location, self.CONGRESS_CAMPAIGN, cache=self.mock_cache) self.assertEqual(len(uids), 0)
def test_locate_targets_special_only_in_location_district_office(self): self.CONGRESS_CAMPAIGN.campaign_subtype = 'upper' (special_target, created) = Target.get_or_create('us:bioguide:W000817-woburn', cache=self.mock_cache) # Warren self.CONGRESS_CAMPAIGN.target_set = [ special_target, ] self.CONGRESS_CAMPAIGN.include_special = INCLUDE_SPECIAL_ONLY uids = locate_targets(self.mock_location, self.CONGRESS_CAMPAIGN, cache=self.mock_cache) self.assertEqual(len(uids), 1) first = self.us_data.get_uid(uids[0])[0] self.assertEqual(first['chamber'], 'senate') self.assertEqual(first['last_name'], 'Warren') self.assertEqual(first['state'], 'MA')
def test_locate_targets_special_only_in_location_house_district_offices_multiple( self): self.CONGRESS_CAMPAIGN.campaign_subtype = 'lower' (special_target, created) = Target.get_or_create( 'us:bioguide:J000294-brooklyn-1', cache=self.mock_cache) # Hakeem Jeffries self.CONGRESS_CAMPAIGN.target_set = [ special_target, ] self.CONGRESS_CAMPAIGN.include_special = INCLUDE_SPECIAL_ONLY uids = locate_targets(self.mock_location_multiple_offices, self.CONGRESS_CAMPAIGN, cache=self.mock_cache) self.assertEqual(len(uids), 1) first = self.us_data.get_uid(uids[0])[0] self.assertEqual(first['chamber'], 'house') self.assertEqual(first['last_name'], 'Jeffries') self.assertEqual(first['state'], 'NY')