def test_case_reduce(self): 'Test ``the case_reduce`` static method' g = GroupInfo(MagicMock(), MagicMock(), MagicMock()) t = 'Tonight on Ethel the Frog we look at Violence The violence of British Gangland' k = t.split() r = g.case_reduce(k) # --=mpj17=-- The second The, and violence are missing self.assertEqual(r, ['Tonight', 'on', 'Ethel', 'the', 'Frog', 'we', 'look', 'at', 'Violence', 'of', 'British', 'Gangland', ])
def test_get_max_people_user_not_author(self, m_p_p, m_uI): 'Test the the list of people is fine if the user is not in the lits' m_p_p.return_value = [] m_uI().id = 'example' g = GroupInfo(MagicMock(), MagicMock(), MagicMock()) ids = list(range(0, g.maxAuthors)) g.get_max_people(ids) m_p_p.assert_called_once_with(list(range(0, g.maxAuthors)))
def test_get_max_people_author(self, m_p_p, m_uI): 'Test the user is removed from the list of people' m_p_p.return_value = [] m_uI().id = 0 g = GroupInfo(MagicMock(), MagicMock(), MagicMock()) ids = list(range(0, g.maxAuthors)) g.get_max_people(ids) m_p_p.assert_called_once_with(list(range(1, g.maxAuthors)))
def test_prefer_photos_anon(self, m_cO): 'Ensure we do not return Anonymous as a person with a photo' m_cO.side_effect = partial(self.get_user_info, anonymous=True) g = GroupInfo(MagicMock(), MagicMock(), MagicMock()) g.groupInfo = MagicMock() # Normally the group-info is passed in from the page namespace ids = list(range(0, g.maxAuthors)) r = g.prefer_photos(ids) self.assertEqual([], r) self.assertEqual(len(ids), m_cO.call_count)
def test_prefer_photos_anon(self, m_cO): 'Ensure we do not return Anonymous as a person with a photo' m_cO.side_effect = partial(self.get_user_info, anonymous=True) g = GroupInfo(MagicMock(), MagicMock(), MagicMock()) g.groupInfo = MagicMock( ) # Normally the group-info is passed in from the page namespace ids = list(range(0, g.maxAuthors)) r = g.prefer_photos(ids) self.assertEqual([], r) self.assertEqual(len(ids), m_cO.call_count)
def test_prefer_photos_no_image(self, m_g_i_f, m_cO): 'Ensure we cope if no one has an image' m_g_i_f.return_value = None m_cO.side_effect = partial(self.get_user_info, anonymous=False) g = GroupInfo(MagicMock(), MagicMock(), MagicMock()) g.groupInfo = MagicMock() # Normally the group-info is passed in from the page namespace ids = list(range(0, g.maxAuthors)) r = g.prefer_photos(ids) self.assertEqual(len(ids), m_cO.call_count) self.assertEqual(len(ids), m_g_i_f.call_count) self.assertEqual(ids, [u.id for u in r])
def test_prefer_photos_no_image(self, m_g_i_f, m_cO): 'Ensure we cope if no one has an image' m_g_i_f.return_value = None m_cO.side_effect = partial(self.get_user_info, anonymous=False) g = GroupInfo(MagicMock(), MagicMock(), MagicMock()) g.groupInfo = MagicMock( ) # Normally the group-info is passed in from the page namespace ids = list(range(0, g.maxAuthors)) r = g.prefer_photos(ids) self.assertEqual(len(ids), m_cO.call_count) self.assertEqual(len(ids), m_g_i_f.call_count) self.assertEqual(ids, [u.id for u in r])
def test_prefer_photos(self, m_g_i_f, m_cO): 'Ensure we prefer it if someone has an image' m_g_i_f.side_effect = [None, 'image', None, 'image', 'image'] m_cO.side_effect = partial(self.get_user_info, anonymous=False) g = GroupInfo(MagicMock(), MagicMock(), MagicMock()) g.groupInfo = MagicMock() # Normally the group-info is passed in from the page namespace ids = list(range(0, 5)) r = g.prefer_photos(ids) self.assertEqual(len(ids), m_cO.call_count) self.assertEqual(len(ids), m_g_i_f.call_count) # --=mpj17=-- 0 and 2 are last because they lack an image self.assertEqual([1, 3, 4, 0, 2], [u.id for u in r])
def test_prefer_photos(self, m_g_i_f, m_cO): 'Ensure we prefer it if someone has an image' m_g_i_f.side_effect = [None, 'image', None, 'image', 'image'] m_cO.side_effect = partial(self.get_user_info, anonymous=False) g = GroupInfo(MagicMock(), MagicMock(), MagicMock()) g.groupInfo = MagicMock( ) # Normally the group-info is passed in from the page namespace ids = list(range(0, 5)) r = g.prefer_photos(ids) self.assertEqual(len(ids), m_cO.call_count) self.assertEqual(len(ids), m_g_i_f.call_count) # --=mpj17=-- 0 and 2 are last because they lack an image self.assertEqual([1, 3, 4, 0, 2], [u.id for u in r])
def test_specificMembers(self, m_g_m_p, m_fM): m_g_m_p.side_effect = lambda x: x m_fM().fullMemberIds = set(['a', 'b', 'c']) # This should be converted to a list g = GroupInfo(MagicMock(), MagicMock(), MagicMock()) r = g.specificMembers self.assertIsInstance(r, list) self.assertEqual(3, len(r))
def test_one_is_the_lonliest_number(self, m_uI, m_aI): 'Test the ``userIsOnlyAuthor`` property' m_uI().id = 'example' m_aI.return_value = [ 'example', ] g = GroupInfo(MagicMock(), MagicMock(), MagicMock()) r = g.userIsOnlyAuthor self.assertTrue(r)
def test_privacyTooStrict(self, m_fM, m_gV, m_iA): 'Test that the privacy is too strict for large secret groups if we are the admin' m_iA.return_value = True m_gV().isSecret = True m_fM.return_value = list(range(0, 24)) g = GroupInfo(MagicMock(), MagicMock(), MagicMock()) r = g.privacyTooStrict self.assertTrue(r)
def test_privacyTooStrict_small(self, m_fM, m_gV, m_iA): 'Test that the privacy is never too strict if we are a small group' m_iA.return_value = True m_gV().isSecret = True m_fM.return_value = list(range(0, 2)) g = GroupInfo(MagicMock(), MagicMock(), MagicMock()) r = g.privacyTooStrict self.assertFalse(r)
def test_privacyTooStrict_not_admin(self, m_fM, m_gV, m_iA): 'Test that the privacy is never too strict if we are a normal member' m_iA.return_value = False m_gV().isSecret = True m_fM.return_value = list(range(0, 24)) g = GroupInfo(MagicMock(), MagicMock(), MagicMock()) r = g.privacyTooStrict self.assertFalse(r)
def test_reader(self, m_uI, m_aI): 'Test the ``userIsOnlyAuthor`` property if the user only read' m_uI().id = 'example' m_aI.return_value = [ 'dirk', 'dinsdale', ] g = GroupInfo(MagicMock(), MagicMock(), MagicMock()) r = g.userIsOnlyAuthor self.assertFalse(r)
def test_friends(self, m_uI, m_aI): 'Test the ``userIsOnlyAuthor`` property if the user was one of the many authors' m_uI().id = 'dirk' m_aI.return_value = [ 'dirk', 'dinsdale', ] g = GroupInfo(MagicMock(), MagicMock(), MagicMock()) r = g.userIsOnlyAuthor self.assertFalse(r)
def test_case_reduce(self): 'Test ``the case_reduce`` static method' g = GroupInfo(MagicMock(), MagicMock(), MagicMock()) t = 'Tonight on Ethel the Frog we look at Violence The violence of British Gangland' k = t.split() r = g.case_reduce(k) # --=mpj17=-- The second The, and violence are missing self.assertEqual(r, [ 'Tonight', 'on', 'Ethel', 'the', 'Frog', 'we', 'look', 'at', 'Violence', 'of', 'British', 'Gangland', ])