示例#1
0
 def test_paired_not_included(self):
     # pick two friends and pair them
     matches = _matches_for_safe_state_profile(self.user.profile)
     self.assertEqual(len(matches), 2)
     friend1 = matches[0].profile
     friend2 = self.user.profile.friends.exclude(id=friend1.id)[0]
     friend1.paired_with = friend2
     matches = _matches_for_safe_state_profile(self.user.profile)
     self.assertEqual(len(matches), 1)
     self.assertNotIn(friend1, _profiles(matches))
示例#2
0
 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)
示例#3
0
 def test_states(self):
     matches = _matches_for_safe_state_profile(self.user.profile)
     self.assertTrue(matches)
     swing_states = State.objects.filter(
         tipping_point_rank__gt=0, safe_rank=-1).values_list(
             'name', flat=True)
     self.assertTrue(
         all(match.profile.state in swing_states for match in matches))
示例#4
0
 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)))
示例#5
0
 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)))
示例#6
0
 def test_include_random_matches_when_true(self):
     self.user.profile.allow_random = True
     self.user.profile.save()
     matches = _matches_for_safe_state_profile(self.user.profile)
     self.assertEqual(len(matches), 4)
     self.assertEqual(_profiles(matches), self.expected_with_random)
示例#7
0
 def test_no_random_matches_when_false(self):
     self.user.profile.allow_random = False
     self.user.profile.save()
     matches = _matches_for_safe_state_profile(self.user.profile)
     self.assertEqual(len(matches), 2)
     self.assertEqual(_profiles(matches), self.expected_no_random)
示例#8
0
 def test_foaf(self):
     matches = _matches_for_safe_state_profile(
         self.user.profile, direct=False, foaf=True)
     self.assertEqual(len(matches), 5)
     self.assertEqual(_profiles(matches), self.foaf_expected_matches)
     self.assertFalse(any(match.is_direct for match in matches))
示例#9
0
 def test_direct(self):
     matches = _matches_for_safe_state_profile(
         self.user.profile, direct=True, foaf=False)
     self.assertEqual(len(matches), 2)
     self.assertEqual(_profiles(matches), self.direct_expected_matches)
     self.assertTrue(all(match.is_direct for match in matches))