From 3fd92aef35301bdec63d3ba118291af29ecd2022 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Wed, 2 Nov 2016 16:22:35 -0400 Subject: [PATCH] Fix entity search API to not IndexError --- data/model/user.py | 2 +- test/test_api_usage.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/data/model/user.py b/data/model/user.py index 14069ce32..20d5c4ea9 100644 --- a/data/model/user.py +++ b/data/model/user.py @@ -514,7 +514,7 @@ def get_matching_users(username_prefix, robot_namespace=None, organization=None, direct_user_query = (direct_user_query | (robot_search & (User.robot == True))) query = (User - .select(User.username, User.email, User.robot) + .select(User.id, User.username, User.email, User.robot) .group_by(User.username, User.email, User.robot) .where(direct_user_query)) diff --git a/test/test_api_usage.py b/test/test_api_usage.py index 6790961b6..5c64a830a 100644 --- a/test/test_api_usage.py +++ b/test/test_api_usage.py @@ -776,6 +776,21 @@ class TestConductSearch(ApiTestCase): class TestGetMatchingEntities(ApiTestCase): + def test_simple_lookup(self): + self.login(ADMIN_ACCESS_USER) + + json = self.getJsonResponse(EntitySearch, + params=dict(prefix=ADMIN_ACCESS_USER, namespace=ORGANIZATION, + includeTeams='true')) + self.assertEquals(1, len(json['results'])) + + def test_simple_lookup_noorg(self): + self.login(ADMIN_ACCESS_USER) + + json = self.getJsonResponse(EntitySearch, + params=dict(prefix=ADMIN_ACCESS_USER)) + self.assertEquals(1, len(json['results'])) + def test_unicode_search(self): self.login(ADMIN_ACCESS_USER)