def test_search(self): """Make sure users can actually find things on the site.""" # Create test user user1 = create_account('user1', '*****@*****.**', 'Password') # Ensure that the user can be found self.assertEqual(len(search('user1').items), 0) self.assertEqual(search('user1').total, 0) # Users will not appear unless they are active. activate(user1) self.assertEqual(len(search('user1').items), 1) self.assertEqual(search('user1').total, 1) # Ensure partial match self.assertEqual(len(search('use').items), 1) self.assertEqual(search('use').total, 1) # Ensure nothing return if no user self.assertEqual(len(search('user2').items), 0) self.assertEqual(search('user2').total, 0) # Ensure no partial if incorrect self.assertEqual(len(search('bob').items), 0) self.assertEqual(search('bob').total, 0) # Create a second test user and a post with a hashtag and # ensure both show in the results. user2 = create_account('user2', '*****@*****.**', 'Password') activate(user2) # Create the post as user1 as we are going to delete user2 create_post(user1, 'user1', '#user2') # Ensure the new user can be found self.assertEqual(len(search('user2').items), 2) self.assertEqual(search('user2').total, 2) # Ensure partial match returns both test1/2 users self.assertEqual(len(search('use').items), 3) self.assertEqual(search('use').total, 3) # Delete the account user2 and try searching again # Only the hashtag should show delete_account(user2) self.assertEqual(search('user2').total, 1)
def test_advanced_search(self): """Cover using the `@` and `#` modifiers to limit the search type.""" user1 = create_account('user1', '*****@*****.**', 'Password') user2 = create_account('user2', '*****@*****.**', 'Password') # We have to activate the accounts to appear in the search activate(user1) activate(user2) create_post(user1, 'user1', '#pjuu #user2') create_post(user2, 'user2', '#pjuu #user1') for i in range(1, 101): create_post(user1, 'user1', '#pagination{}'.format(i)) # No user should appear because they are not active! self.assertEqual(search('user').total, 4) self.assertEqual(search('user1').total, 2) self.assertEqual(search('user2').total, 2) # Try come basic search terms self.assertEqual(search('user').total, 4) self.assertEqual(search('user1').total, 2) self.assertEqual(search('user2').total, 2) self.assertEqual(search('pjuu').total, 2) # Users only self.assertEqual(search('@user').total, 2) self.assertEqual(search('@user1').total, 1) # erroneous spacing doesn't matter self.assertEqual(search('@ us').total, 2) # Posts only self.assertEqual(search('#user').total, 2) self.assertEqual(search('#user1').total, 1) self.assertEqual(search('#pjuu').total, 2) # Test pagination in search self.assertEqual(len(search('#pagination', 1, 50).items), 50) self.assertEqual(len(search('#pagination', 2, 50).items), 50)
def test_search(self): """ Make sure users can actually find each other. This will need a lot more work once we add in a proper search facility rather than just the Redis KEYS command """ # Create test user create_account('user1', '*****@*****.**', 'Password') # Ensure that the user can be found self.assertEqual(len(search('user1').items), 1) self.assertEqual(search('user1').total, 1) # Ensure partial match self.assertEqual(len(search('use').items), 1) self.assertEqual(search('use').total, 1) # Ensure nothing return if no user self.assertEqual(len(search('user2').items), 0) self.assertEqual(search('user2').total, 0) # Ensure no partial if incorrect self.assertEqual(len(search('bob').items), 0) self.assertEqual(search('bob').total, 0) # Create a second test user user2 = create_account('user2', '*****@*****.**', 'Password') # Ensure the new user can be found self.assertEqual(len(search('user2').items), 1) self.assertEqual(search('user2').total, 1) # Ensure partial match returns both test1/2 users self.assertEqual(len(search('use').items), 2) self.assertEqual(search('use').total, 2) # Delete the account test 2 and try searching again # Adding in this test as it has stung us before delete_account(user2) self.assertEqual(search('test2').total, 0)