Ejemplo n.º 1
0
    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')
Ejemplo n.º 2
0
    def test_locate_targets_house_only(self):
        self.CONGRESS_CAMPAIGN.campaign_subtype = 'lower'
        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'], 'house')
Ejemplo n.º 3
0
    def test_locate_targets_gov(self):
        self.STATE_CAMPAIGN.campaign_subtype = 'exec'
        gov = locate_targets(self.mock_location, self.STATE_CAMPAIGN, cache=self.mock_cache)
        self.assertEqual(len(gov), 1)

        self.assertEqual(gov[0]['state'], 'CA')
        self.assertEqual(gov[0]['title'], 'Governor')
Ejemplo n.º 4
0
    def test_locate_targets_house_only(self):
        self.CONGRESS_CAMPAIGN.campaign_subtype = 'lower'
        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'], 'house')
Ejemplo n.º 5
0
    def test_locate_targets_multiple_states(self):
        self.CONGRESS_CAMPAIGN.campaign_subtype = 'both'
        self.CONGRESS_CAMPAIGN.target_ordering = 'lower-first'

        uids = locate_targets(self.mock_location_multiple_states, self.CONGRESS_CAMPAIGN, cache=self.mock_cache)
        self.assertEqual(len(uids), 6)

        first = self.us_data.get_uid(uids[0])[0]
        self.assertEqual(first['chamber'], 'house')
        self.assertEqual(first['state'], 'KY')

        second = self.us_data.get_uid(uids[1])[0]
        self.assertEqual(second['chamber'], 'house')
        self.assertEqual(second['state'], 'TN')

        third = self.us_data.get_uid(uids[2])[0]
        self.assertEqual(third['chamber'], 'senate')
        self.assertEqual(third['state'], 'TN')

        fourth = self.us_data.get_uid(uids[3])[0]
        self.assertEqual(fourth['chamber'], 'senate')
        self.assertEqual(fourth['state'], 'TN')

        fifth = self.us_data.get_uid(uids[4])[0]
        self.assertEqual(fifth['chamber'], 'senate')
        self.assertEqual(fifth['state'], 'KY')

        sixth = self.us_data.get_uid(uids[5])[0]
        self.assertEqual(sixth['chamber'], 'senate')
        self.assertEqual(sixth['state'], 'KY')  
Ejemplo n.º 6
0
    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')
Ejemplo n.º 7
0
    def test_locate_targets_multiple_districts(self):
        self.CONGRESS_CAMPAIGN.campaign_subtype = 'both'
        self.CONGRESS_CAMPAIGN.target_ordering = 'lower-first'

        uids = locate_targets(self.mock_location_multiple_districts,
                              self.CONGRESS_CAMPAIGN,
                              cache=self.mock_cache)
        self.assertEqual(len(uids), 4)

        first = self.us_data.get_uid(uids[0])[0]
        self.assertEqual(first['chamber'], 'house')
        self.assertEqual(first['state'], 'WI')
        self.assertEqual(first['district'], '2')

        second = self.us_data.get_uid(uids[1])[0]
        self.assertEqual(second['chamber'], 'house')
        self.assertEqual(second['state'], 'WI')
        self.assertEqual(second['district'], '3')

        third = self.us_data.get_uid(uids[2])[0]
        self.assertEqual(third['chamber'], 'senate')
        self.assertEqual(third['state'], 'WI')

        fourth = self.us_data.get_uid(uids[3])[0]
        self.assertEqual(third['chamber'], 'senate')
        self.assertEqual(fourth['state'], 'WI')
Ejemplo n.º 8
0
    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')
Ejemplo n.º 9
0
    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')
Ejemplo n.º 10
0
    def test_locate_targets_multiple_states(self):
        self.CONGRESS_CAMPAIGN.campaign_subtype = 'both'
        self.CONGRESS_CAMPAIGN.target_ordering = 'lower-first'

        uids = locate_targets(self.mock_location_multiple_states,
                              self.CONGRESS_CAMPAIGN,
                              cache=self.mock_cache)
        self.assertEqual(len(uids), 6)

        first = self.us_data.get_uid(uids[0])[0]
        self.assertEqual(first['chamber'], 'house')
        self.assertEqual(first['state'], 'KY')

        second = self.us_data.get_uid(uids[1])[0]
        self.assertEqual(second['chamber'], 'house')
        self.assertEqual(second['state'], 'TN')

        third = self.us_data.get_uid(uids[2])[0]
        self.assertEqual(third['chamber'], 'senate')
        self.assertIn(third['state'], ['TN', 'KY'])
        # use assert in, because these don't seem to come in consistenx order

        fourth = self.us_data.get_uid(uids[3])[0]
        self.assertEqual(fourth['chamber'], 'senate')
        self.assertIn(third['state'], ['TN', 'KY'])

        fifth = self.us_data.get_uid(uids[4])[0]
        self.assertEqual(fifth['chamber'], 'senate')
        self.assertIn(third['state'], ['TN', 'KY'])

        sixth = self.us_data.get_uid(uids[5])[0]
        self.assertEqual(sixth['chamber'], 'senate')
        self.assertIn(third['state'], ['TN', 'KY'])
Ejemplo n.º 11
0
    def test_locate_targets_incorrect_state(self):
        self.STATE_CAMPAIGN.campaign_state = 'CA'

        other_location = Location('Boston, MA', (42.355662,-71.065483),
            {'state':'MA','zipcode':'02111'})
        
        uids = locate_targets(other_location, self.STATE_CAMPAIGN, cache=self.mock_cache)
        self.assertEqual(len(uids), 0)
Ejemplo n.º 12
0
    def test_locate_targets_upper_only(self):
        self.STATE_CAMPAIGN.campaign_subtype = 'upper'
        uids = locate_targets(self.mock_location, self.STATE_CAMPAIGN, cache=self.mock_cache)
        self.assertEqual(len(uids), 1)

        senator = self.us_data.get_uid(uids[0])
        self.assertEqual(senator['chamber'], 'upper')
        self.assertEqual(senator['state'].upper(), 'CA')
Ejemplo n.º 13
0
    def test_locate_targets_incorrect_state(self):
        self.STATE_CAMPAIGN.campaign_state = 'CA'

        other_location = Location('Boston, MA', (42.355662,-71.065483),
            {'components':{'state':'MA','zipcode':'02111'}})
        
        uids = locate_targets(other_location, self.STATE_CAMPAIGN, cache=self.mock_cache)
        self.assertEqual(len(uids), 0)
Ejemplo n.º 14
0
    def test_locate_targets_upper_only(self):
        self.STATE_CAMPAIGN.campaign_subtype = 'upper'
        uids = locate_targets(self.mock_location, self.STATE_CAMPAIGN, cache=self.mock_cache)
        self.assertEqual(len(uids), 1)

        senator = self.us_data.get_uid(uids[0])
        self.assertEqual(senator['chamber'], 'upper')
        self.assertEqual(senator['state'].upper(), 'CA')
        self.assertEqual(senator['active'], True)
Ejemplo n.º 15
0
 def test_locate_targets_gov(self):
     self.STATE_CAMPAIGN.campaign_subtype = 'exec'
     uids = locate_targets(self.mock_location, self.STATE_CAMPAIGN, cache=self.mock_cache)
     self.assertEqual(len(uids), 1)
     
     gov = self.us_data.get_uid(uids[0])
     self.assertEqual(gov[0]['state'], 'CA')
     self.assertEqual(gov[0]['state_name'], 'California')
     self.assertEqual(gov[0]['title'], 'Governor')
Ejemplo n.º 16
0
    def test_locate_targets_gov(self):
        self.STATE_CAMPAIGN.campaign_subtype = 'exec'
        gov = locate_targets(self.mock_location,
                             self.STATE_CAMPAIGN,
                             cache=self.mock_cache)
        self.assertEqual(len(gov), 1)

        self.assertEqual(gov[0]['state'], 'CA')
        self.assertEqual(gov[0]['title'], 'Governor')
Ejemplo n.º 17
0
    def test_locate_targets_lower_only(self):
        self.STATE_CAMPAIGN.campaign_subtype = 'lower'
        uids = locate_targets(self.mock_location, self.STATE_CAMPAIGN, cache=self.mock_cache)
        self.assertEqual(len(uids), 1)

        house_rep = self.us_data.get_uid(uids[0])
        self.assertEqual(house_rep['chamber'], 'lower')
        self.assertEqual(house_rep['state'].upper(), 'CA')
        self.assertEqual(house_rep['active'], True)
Ejemplo n.º 18
0
    def test_locate_targets(self):
        keys = locate_targets(self.mock_location,
                              self.PARLIAMENT_CAMPAIGN,
                              cache=self.mock_cache)
        # returns a list of target boundary keys
        self.assertEqual(len(keys), 1)

        mp = self.ca_data.cache_get(keys[0])
        self.assertEqual(mp['elected_office'], 'MP')
        self.assertEqual(mp['representative_set_name'], 'House of Commons')
Ejemplo n.º 19
0
    def test_locate_targets_special_only_outside_location(self):
        self.CONGRESS_CAMPAIGN.campaign_subtype = 'upper'

        (special_target, cached) = Target.get_or_cache_key('us:bioguide:S000033', cache=self.mock_cache) # Bernie
        self.CONGRESS_CAMPAIGN.target_set = [special_target,]
        self.CONGRESS_CAMPAIGN.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)
Ejemplo n.º 20
0
    def test_locate_targets_special_only_outside_location(self):
        self.CONGRESS_CAMPAIGN.campaign_subtype = 'upper'

        (special_target, cached) = Target.get_or_cache_key('us:bioguide:S000033', cache=self.mock_cache) # Bernie
        self.CONGRESS_CAMPAIGN.target_set = [special_target,]
        self.CONGRESS_CAMPAIGN.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)
Ejemplo n.º 21
0
 def test_locate_targets_province_quebec(self):
     keys = locate_targets(self.mock_location,
                           self.PROVINCE_CAMPAIGN,
                           cache=self.mock_cache)
     self.assertEqual(len(keys), 1)
     mha = self.ca_data.cache_get(keys[0])
     self.assertEqual(mha['elected_office'], 'MNA')
     # compare on the url, not the representative_set_name, to avoid unicode comparison issues
     self.assertEqual(mha['related']['representative_set_url'],
                      '/representative-sets/quebec-assemblee-nationale/')
Ejemplo n.º 22
0
    def test_locate_targets_ordered_upper_first(self):
        self.STATE_CAMPAIGN.campaign_subtype = 'both'
        self.STATE_CAMPAIGN.target_ordering = 'upper-first'
        uids = locate_targets(self.mock_location, self.STATE_CAMPAIGN, cache=self.mock_cache)
        self.assertEqual(len(uids), 2)

        first = self.us_data.get_uid(uids[0])
        self.assertEqual(first['chamber'], 'upper')

        second = self.us_data.get_uid(uids[1])
        self.assertEqual(second['chamber'], 'lower')
Ejemplo n.º 23
0
    def test_locate_targets_senate_only(self):
        self.CONGRESS_CAMPAIGN.campaign_subtype = 'upper'

        uids = locate_targets(self.mock_location, self.CONGRESS_CAMPAIGN, cache=self.mock_cache)
        self.assertEqual(len(uids), 2)

        first = self.us_data.get_uid(uids[0])[0]
        self.assertEqual(first['chamber'], 'senate')

        second = self.us_data.get_uid(uids[1])[0]
        self.assertEqual(second['chamber'], 'senate')
Ejemplo n.º 24
0
    def test_locate_targets_ordered_upper_first(self):
        self.STATE_CAMPAIGN.campaign_subtype = 'both'
        self.STATE_CAMPAIGN.target_ordering = 'upper-first'
        uids = locate_targets(self.mock_location, self.STATE_CAMPAIGN, cache=self.mock_cache)
        self.assertEqual(len(uids), 2)

        first = self.us_data.get_uid(uids[0])
        self.assertEqual(first['chamber'], 'upper')

        second = self.us_data.get_uid(uids[1])
        self.assertEqual(second['chamber'], 'lower')
Ejemplo n.º 25
0
    def test_locate_targets_senate_only(self):
        self.CONGRESS_CAMPAIGN.campaign_subtype = 'upper'

        uids = locate_targets(self.mock_location, self.CONGRESS_CAMPAIGN, cache=self.mock_cache)
        self.assertEqual(len(uids), 2)

        first = self.us_data.get_uid(uids[0])[0]
        self.assertEqual(first['chamber'], 'senate')

        second = self.us_data.get_uid(uids[1])[0]
        self.assertEqual(second['chamber'], 'senate')
Ejemplo n.º 26
0
    def test_locate_targets(self):
        uids = locate_targets(self.mock_location, self.STATE_CAMPAIGN, cache=self.mock_cache)
        # returns a list of uids (openstates leg_id)
        self.assertEqual(len(uids), 2)

        house_rep = self.us_data.get_uid(uids[0])
        self.assertEqual(house_rep['chamber'], 'lower')
        self.assertEqual(house_rep['state'].upper(), 'CA')

        senator = self.us_data.get_uid(uids[1])
        self.assertEqual(senator['chamber'], 'upper')
        self.assertEqual(senator['state'].upper(), 'CA')
Ejemplo n.º 27
0
    def test_locate_targets_unicameral_state(self):
        self.STATE_CAMPAIGN.campaign_state = 'NE'
        self.STATE_CAMPAIGN.campaign_subtype = 'both'
        self.STATE_CAMPAIGN.target_ordering = 'lower-first'

        other_location = Location('Lincoln, NE', (40.80798, -96.69968),
            {'state':'NE','zipcode':'68508'})
        
        uids = locate_targets(other_location, self.STATE_CAMPAIGN, cache=self.mock_cache)
        self.assertEqual(len(uids), 1)

        first = self.us_data.get_uid(uids[0])
        self.assertEqual(first['chamber'], 'legislature')
Ejemplo n.º 28
0
    def test_locate_targets_special_only_in_location(self):
        self.CONGRESS_CAMPAIGN.campaign_subtype = 'upper'

        (special_target, cached) = Target.get_or_cache_key('us:bioguide:W000817', cache=self.mock_cache) # Warren
        self.CONGRESS_CAMPAIGN.target_set = [special_target,]
        self.CONGRESS_CAMPAIGN.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')
Ejemplo n.º 29
0
    def test_locate_targets(self):
        uids = locate_targets(self.mock_location, self.STATE_CAMPAIGN, cache=self.mock_cache)
        # returns a list of uids (openstates leg_id)
        self.assertEqual(len(uids), 2)

        house_rep = self.us_data.get_uid(uids[0])
        self.assertEqual(house_rep['chamber'], 'lower')
        self.assertEqual(house_rep['state'].upper(), 'CA')
        self.assertEqual(house_rep['active'], True)

        senator = self.us_data.get_uid(uids[1])
        self.assertEqual(senator['chamber'], 'upper')
        self.assertEqual(senator['state'].upper(), 'CA')
        self.assertEqual(senator['active'], True)
Ejemplo n.º 30
0
    def test_locate_targets_special_only_in_location_district_office(self):
        self.CONGRESS_CAMPAIGN.campaign_subtype = 'upper'

        (special_target, cached) = Target.get_or_cache_key('us:bioguide:W000817-woburn', cache=self.mock_cache) # Warren
        self.CONGRESS_CAMPAIGN.target_set = [special_target,]
        self.CONGRESS_CAMPAIGN.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')
Ejemplo n.º 31
0
    def test_locate_targets_both_ordered_republicans_only(self):
        self.CONGRESS_CAMPAIGN.campaign_subtype = 'both'
        self.CONGRESS_CAMPAIGN.target_ordering = 'republicans-only'

        uids = locate_targets(self.mock_location_split_parties,
                              self.CONGRESS_CAMPAIGN,
                              cache=self.mock_cache)
        self.assertEqual(len(uids), 2)

        first = self.us_data.get_uid(uids[0])[0]
        self.assertEqual(first['party'], 'Republican')

        second = self.us_data.get_uid(uids[1])[0]
        self.assertEqual(first['party'], 'Republican')
Ejemplo n.º 32
0
    def test_locate_targets_both_ordered_senate_first(self):
        self.CONGRESS_CAMPAIGN.campaign_subtype = 'both'
        self.CONGRESS_CAMPAIGN.target_ordering = 'upper-first'

        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')

        second = self.us_data.get_uid(uids[1])[0]
        self.assertEqual(second['chamber'], 'senate')

        third = self.us_data.get_uid(uids[2])[0]
        self.assertEqual(third['chamber'], 'house')
Ejemplo n.º 33
0
    def test_locate_targets_both_ordered_senate_first(self):
        self.CONGRESS_CAMPAIGN.campaign_subtype = 'both'
        self.CONGRESS_CAMPAIGN.target_ordering = 'upper-first'

        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')

        second = self.us_data.get_uid(uids[1])[0]
        self.assertEqual(second['chamber'], 'senate')

        third = self.us_data.get_uid(uids[2])[0]
        self.assertEqual(third['chamber'], 'house')
Ejemplo n.º 34
0
    def test_locate_targets(self):
        uids = locate_targets(self.mock_location, self.CONGRESS_CAMPAIGN, cache=self.mock_cache)
        # returns a list of target uids
        self.assertEqual(len(uids), 3)

        house_rep = self.us_data.get_uid(uids[0])[0]
        self.assertEqual(house_rep['chamber'], 'house')
        self.assertEqual(house_rep['state'], 'MA')

        senator_0 = self.us_data.get_uid(uids[1])[0]
        self.assertEqual(senator_0['chamber'], 'senate')
        self.assertEqual(senator_0['state'], 'MA')

        senator_1 = self.us_data.get_uid(uids[2])[0]
        self.assertEqual(senator_1['chamber'], 'senate')
        self.assertEqual(senator_1['state'], 'MA')
Ejemplo n.º 35
0
    def test_locate_targets(self):
        uids = locate_targets(self.mock_location, self.CONGRESS_CAMPAIGN, cache=self.mock_cache)
        # returns a list of target uids
        self.assertEqual(len(uids), 3)

        house_rep = self.us_data.get_uid(uids[0])[0]
        self.assertEqual(house_rep['chamber'], 'house')
        self.assertEqual(house_rep['state'], 'MA')

        senator_0 = self.us_data.get_uid(uids[1])[0]
        self.assertEqual(senator_0['chamber'], 'senate')
        self.assertEqual(senator_0['state'], 'MA')

        senator_1 = self.us_data.get_uid(uids[2])[0]
        self.assertEqual(senator_1['chamber'], 'senate')
        self.assertEqual(senator_1['state'], 'MA')
Ejemplo n.º 36
0
    def test_locate_targets_both_ordered_democrats_first(self):
        self.CONGRESS_CAMPAIGN.campaign_subtype = 'both'
        self.CONGRESS_CAMPAIGN.target_ordering = 'democrats-first'

        uids = locate_targets(self.mock_location_split_parties,
                              self.CONGRESS_CAMPAIGN,
                              cache=self.mock_cache)
        self.assertEqual(len(uids), 3)

        first = self.us_data.get_uid(uids[0])[0]
        self.assertEqual(first['party'], 'Democrat')

        second = self.us_data.get_uid(uids[1])[0]
        self.assertEqual(second['party'], 'Democrat')

        third = self.us_data.get_uid(uids[2])[0]
        self.assertEqual(third['party'], 'Republican')
Ejemplo n.º 37
0
    def test_locate_targets_special_only_in_location(self):
        self.CONGRESS_CAMPAIGN.campaign_subtype = 'upper'

        (special_target,
         created) = Target.get_or_create('us:bioguide:W000817',
                                         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')
Ejemplo n.º 38
0
    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')
Ejemplo n.º 39
0
    def test_locate_targets_special_last(self):
        self.CONGRESS_CAMPAIGN.campaign_subtype = 'upper'

        (special_target, cached) = Target.get_or_cache_key('us:bioguide:S000033', cache=self.mock_cache) # Bernie
        self.CONGRESS_CAMPAIGN.target_set = [special_target,]
        self.CONGRESS_CAMPAIGN.include_special = 'last'

        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')
Ejemplo n.º 40
0
    def test_locate_targets_special_multiple_last(self):
        self.CONGRESS_CAMPAIGN.campaign_subtype = 'lower'

        (special_target_one, cached_one) = Target.get_or_cache_key('us:bioguide:P000197', cache=self.mock_cache) # Pelosi
        (special_target_two, cached_two) = Target.get_or_cache_key('us:bioguide:R000570', cache=self.mock_cache) # Ryan
        self.CONGRESS_CAMPAIGN.target_set = [special_target_one, special_target_two]
        self.CONGRESS_CAMPAIGN.include_special = 'last'

        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')