Example #1
0
 def test_no_score(self):
     models.StateNameVoter.items.create(
         state_lname_fname="PA_APP_GERRY",
         persuasion_score='1.2',
     )
     bulk_impute([self.user], 'gotv_score')
     tools.assert_is_none(self.user.gotv_score)
Example #2
0
    def filter_edges(self, edges, cache_match=False):
        from targetshare.integration import civis

        if self.feature_type.code == self.feature_type.CIVIS_VOTER:
            # Civis matching:
            if cache_match:
                filter_ = civis.client.civis_cached_filter
            else:
                filter_ = civis.client.civis_filter

            return filter_(edges, self.feature, self.operator, self.value)

        if self.feature_type.code == self.feature_type.EF_VOTER:
            unscored_secondaries = (edge.secondary for edge in edges
                                    if not hasattr(edge.secondary, self.feature))
            # FIXME: Though, through inspection, the above ensures that we
            # don't re-match for the same feature, if for some reason we ever
            # wanted to filter on multiple different voter scores, we'd be
            # matching more than once, unnecessarily.
            first = tuple(itertools.islice(unscored_secondaries, 1))
            if first:
                # Pre-cache relevant feature scores via gerry
                unscored_secondaries = itertools.chain(first, unscored_secondaries)
                gerry.bulk_impute(unscored_secondaries, self.feature)

        # Standard min/max/eq/in filters:
        return [edge for edge in edges if self.operate_standard(edge.secondary)]
Example #3
0
 def test_fallback(self):
     models.StateNameVoter.items.create(
         state_lname_fname="PA_APP_GERRY",
         gotv_score='0.2',
         persuasion_score='1.2',
     )
     bulk_impute([self.user], 'gotv_score')
     tools.eq_(self.user.gotv_score, Decimal('0.2'))
Example #4
0
 def test_same_signature_matches(self):
     models.StateNameVoter.items.create(
         state_lname_fname="PA_APP_GERRY",
         gotv_score='0.2',
         persuasion_score='1.2',
     )
     users = [User(id=id) for id in xrange(2)]
     bulk_impute(users, 'gotv_score')
     tools.eq_([user.gotv_score for user in users], [Decimal('0.2')] * 2)
Example #5
0
 def test_accented(self):
     models.StateNameVoter.items.create(
         state_lname_fname="PA_APP_GERRI",
         gotv_score='0.2',
         persuasion_score='1.2',
     )
     self.user.fname = u'Gèrri'
     self.user.lname = u'Äpp'
     bulk_impute([self.user], 'gotv_score')
     tools.eq_(self.user.gotv_score, Decimal('0.2'))
Example #6
0
 def test_priority(self):
     models.StateNameVoter.items.create(
         state_lname_fname="PA_APP_GERRY",
         gotv_score='0.2',
         persuasion_score='1.2',
     )
     models.StateCityNameVoter.items.create(
         state_city_lname_fname="PA_PHILADELPHIA_APP_GERRY",
         gotv_score='0.4',
         persuasion_score='4.2',
     )
     bulk_impute([self.user], 'gotv_score')
     tools.eq_(self.user.gotv_score, Decimal('0.4'))
Example #7
0
 def test_unsupported_feature(self):
     with tools.assert_raises(ValueError) as context:
         bulk_impute([self.user], 'gerry_score')
     tools.assert_in("Unsupported feature", str(context.exception))
Example #8
0
 def test_bad_state(self):
     self.user.state = 'garbage'
     bulk_impute([self.user], 'gotv_score')
     tools.assert_is_none(self.user.gotv_score)
Example #9
0
 def test_no_state(self):
     self.user.state = None
     bulk_impute([self.user], 'gotv_score')
     tools.assert_is_none(self.user.gotv_score)
Example #10
0
 def test_no_match(self):
     bulk_impute([self.user], 'gotv_score')
     tools.assert_is_none(self.user.gotv_score)