def _update_registered_status_of_all(user_id, fb_friends):
    user = User.objects.get(id=user_id)
    profiles_to_update = []
    for fb_friend in fb_friends:
        f = Friendship.objects.filter(user=user, fb_uid=str(fb_friend["uid"])).all()[:1]
        if len(f) == 0:
            continue
        f = f[0]
        if not f.votizen_id:
            profiles_to_update.append(FacebookProfile(fb_friend))
    fetch_voters_from_fb_profiles(profiles_to_update)
示例#2
0
def _update_registered_status_of_all(user_id, fb_friends):
    user = User.objects.get(id=user_id)
    profiles_to_update = []
    for fb_friend in fb_friends:
        f = Friendship.objects.filter(user=user,
                                      fb_uid=str(fb_friend["uid"])).all()[:1]
        if len(f) == 0:
            continue
        f = f[0]
        if not f.votizen_id:
            profiles_to_update.append(FacebookProfile(fb_friend))
    fetch_voters_from_fb_profiles(profiles_to_update)
def _make_main_batches(user_id, access_token, fb_friends, found_uids):
    user = User.objects.get(id=user_id)
    user.update_friends_fetch()
    user.save()
    facebook_profiles = []
    for fb_friend in fb_friends:
        uid = str(fb_friend["uid"])
        if uid in found_uids:
            continue
        facebook_profiles.append(FacebookProfile(fb_friend))
        if Friendship.objects.filter(user=user, fb_uid=uid).count() > 0:
            continue
        profile = FacebookProfile(fb_friend)
        if not Friendship.objects.filter(user=user, fb_uid=uid).exists():
            f = Friendship.create_from_fb_profile(user, profile)
            f.save()
    fetch_voters_from_fb_profiles(facebook_profiles)
示例#4
0
def _make_main_batches(user_id, access_token, fb_friends, found_uids):
    user = User.objects.get(id=user_id)
    user.update_friends_fetch()
    user.save()
    facebook_profiles = []
    for fb_friend in fb_friends:
        uid = str(fb_friend["uid"])
        if uid in found_uids:
            continue
        facebook_profiles.append(FacebookProfile(fb_friend))
        if Friendship.objects.filter(user=user, fb_uid=uid).count() > 0:
            continue
        profile = FacebookProfile(fb_friend)
        if not Friendship.objects.filter(user=user, fb_uid=uid).exists():
            f = Friendship.create_from_fb_profile(user, profile)
            f.save()
    fetch_voters_from_fb_profiles(facebook_profiles)
示例#5
0
    def test_preexisting_voter_record(self):
        v = VoterRecord(fb_uid="uid0", votizen_id="a", registered=True)
        v.save()
        counter = [0]
        requests = []

        def batch_post(request):
            requests.append(request)
            counter[0] += 1
            return 200, _votizen_response(RESPONSE_MISS, RESPONSE_MISS)

        voterapi._batch_post = batch_post
        voters = voterapi.fetch_voters_from_fb_profiles(_fake_profiles(3))
        self.assertEquals(2, len(requests))
        self.assertEquals(3, len(voters))
        self.assertEquals(1, len([v for v in voters if v.registered]))
        self._assert_uids_present(voters)
示例#6
0
 def test_preexisting_voter_record(self):
     v = VoterRecord(
         fb_uid="uid0",
         votizen_id="a",
         registered=True)
     v.save()
     counter = [0]
     requests = []
     def batch_post(request):
         requests.append(request)
         counter[0] += 1
         return 200, _votizen_response(RESPONSE_MISS, RESPONSE_MISS)
     voterapi._batch_post = batch_post
     voters = voterapi.fetch_voters_from_fb_profiles(_fake_profiles(3))
     self.assertEquals(2, len(requests))
     self.assertEquals(3, len(voters))
     self.assertEquals(1, len([v for v in voters if v.registered]))
     self._assert_uids_present(voters)
示例#7
0
 def test_fail_on_second_request(self):
     counter = [0]
     requests = []
     def batch_post(request):
         requests.append(request)
         counter[0] += 1
         if counter[0] == 1:
             return 200, _votizen_response(RESPONSE_HIT, RESPONSE_MISS, RESPONSE_MISS)
         elif counter[0] == 2:
             return 200, _votizen_response(RESPONSE_MISS, RESPONSE_ERROR)
         else:
             return 200, _votizen_response(RESPONSE_HIT)
     voterapi._batch_post = batch_post
     voters = voterapi.fetch_voters_from_fb_profiles(_fake_profiles(3))
     self.assertEquals(3, len(requests))
     self.assertEquals(3, len(voters))
     self.assertTrue(_includes_addresses(requests[2]))
     self.assertEquals(2, len([v for v in voters if v.registered]))
     self._assert_uids_present(voters)
示例#8
0
    def test_fail_on_second_request(self):
        counter = [0]
        requests = []

        def batch_post(request):
            requests.append(request)
            counter[0] += 1
            if counter[0] == 1:
                return 200, _votizen_response(RESPONSE_HIT, RESPONSE_MISS,
                                              RESPONSE_MISS)
            elif counter[0] == 2:
                return 200, _votizen_response(RESPONSE_MISS, RESPONSE_ERROR)
            else:
                return 200, _votizen_response(RESPONSE_HIT)

        voterapi._batch_post = batch_post
        voters = voterapi.fetch_voters_from_fb_profiles(_fake_profiles(3))
        self.assertEquals(3, len(requests))
        self.assertEquals(3, len(voters))
        self.assertTrue(_includes_addresses(requests[2]))
        self.assertEquals(2, len([v for v in voters if v.registered]))
        self._assert_uids_present(voters)