def testFindUser(self): query = find_user('gray') self.assertEqual(set([self.u1, self.u2]), set(query)) query = find_user('just') self.assertEqual(set([self.u1]), set(query)) query = find_user('uro') self.assertEqual(set([self.u3]), set(query)) query = find_user('user') self.assertEqual(set([self.u1, self.u2, self.u3]), set(query))
def search_users(request, query): """Query against user database and returns possible matches""" results = [{'first_name': u.first_name, 'last_name': u.last_name, 'username': u.username} for u in find_user(query)] return HttpResponse(json.dumps(results), mimetype='application/json')