def test_exclude_pending(self): self.assertEqual( set(_profiles(get_friend_matches(self.user.profile))), set()) self.foaf_proposal.delete() self.assertEqual( set(_profiles(get_friend_matches(self.user.profile))), set([self.foaf.profile]))
def test_exclude_rejected(self): self.assertEqual( set(_profiles(get_friend_matches(self.user.profile))), set()) self.friend_proposal.date_rejected = timezone.now() self.friend_proposal.save() self.assertEqual( set(_profiles(get_friend_matches(self.user.profile))), set())
def test_matches(self): """Baseline test that both friends show up in matches""" self.assertEqual( set(_profiles(get_friend_matches( self.user.profile, exclude_pending=False))), set([self.friend.profile, self.foaf.profile])) self.assertEqual( set(_profiles(get_friend_matches( self.user.profile, exclude_pending=True))), set())
def test_matches(self): matches = _matches_for_safe_state_profile(self.user.profile) self.assertEqual(len(matches), 7) self.assertEqual(_profiles(matches), self.expected_matches) self.assertEqual( _profiles(get_friend_matches(self.user.profile)), self.expected_matches)
def match(request): matches = get_friend_matches(request.user.profile) context = RequestContext( request, {'request': request, 'user': request.user, 'matches': matches}) return render_to_response('match.html', context_instance=context)
def test_has_matches(self): request = self.request.get(reverse(match_view)) request.user = self.user response = match_view(request) self.assertEqual(response.status_code, HTTP_OK) matches = get_friend_matches(self.user.profile) for match in matches: self.assertContains(response, match.profile.user.get_full_name())
def test_through_friend_shown(self): request = self.request.get(reverse(match_view)) request.user = self.user response = match_view(request) self.assertEqual(response.status_code, HTTP_OK) matches = get_friend_matches(self.user.profile) for match in matches: self.assertContains(response, match.profile.fb_name) if not match.is_direct: self.assertContains(response, "via %s" % match.through.fb_name)
def test_no_match_major_in_swing_state(self): state_safe = StateFactory.create( tipping_point_rank=1, ) user = UserFactory.create( profile__state=state_safe.name, profile__preferred_candidate=CANDIDATE_CLINTON, ) self.assertTrue( isinstance(get_friend_matches(user.profile), NoMatchNecessary))
def test_no_match_minor_in_safe_state(self): state_safe = StateFactory.create( safe_for=CANDIDATE_TRUMP, safe_rank=1, ) user = UserFactory.create( profile__state=state_safe.name, profile__preferred_candidate=CANDIDATE_JOHNSON, ) self.assertTrue( isinstance(get_friend_matches(user.profile), NoMatchNecessary))
def test_safe_state_major_candidate(self): # Now we should have three matches that show up matches = _matches_for_safe_state_profile(self.user.profile) self.assertEqual(len(matches), 2) self.assertEqual(_profiles(matches), self.expected_matches) self.assertEqual(_profiles(get_friend_matches(self.user.profile)), self.expected_matches) # And I should be in my friend's potential matches self.assertIn( self.user.profile, _profiles(_matches_for_swing_state_profile(matches[0].profile)))
def test_swing_state_minor_candidate(self): # Now we should have eight friends in safe states, but only 4 of them # are suitable for swapping matches = _matches_for_swing_state_profile(self.user.profile) self.assertEqual(len(matches), 4) self.assertEqual(_profiles(matches), self.expected_matches) self.assertEqual( _profiles(get_friend_matches(self.user.profile)), self.expected_matches) # And I should be in my friend's potential matches self.assertIn( self.user.profile, _profiles(_matches_for_safe_state_profile( matches[0].profile)))
def good_potential_matches(self): return [FriendMatchContext(fm, self) for fm in get_friend_matches(self.profile)]