allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [19/26] git commit: [#7656] ticket:648 Add tests for user search
Date Fri, 19 Sep 2014 20:04:33 GMT
[#7656] ticket:648 Add tests for user search


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/de6b7753
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/de6b7753
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/de6b7753

Branch: refs/heads/master
Commit: de6b775338ab101239be4067b780f89ee6a3ce33
Parents: 2ff64b8
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Tue Sep 9 16:54:56 2014 +0300
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Fri Sep 19 19:35:41 2014 +0000

----------------------------------------------------------------------
 .../allura/tests/functional/test_site_admin.py  | 58 +++++++++++++++++++-
 Allura/allura/tests/unit/test_solr.py           | 13 ++++-
 2 files changed, 68 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/de6b7753/Allura/allura/tests/functional/test_site_admin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_site_admin.py b/Allura/allura/tests/functional/test_site_admin.py
index 9503b7e..c8b3bad 100644
--- a/Allura/allura/tests/functional/test_site_admin.py
+++ b/Allura/allura/tests/functional/test_site_admin.py
@@ -233,10 +233,11 @@ class TestProjectsSearch(TestController):
     def setUp(self):
         super(TestProjectsSearch, self).setUp()
         # Create project that matches TEST_HIT id
-        p = M.Project.query.get(_id=ObjectId('53ccf6e8100d2b0741746e9f'))
+        _id = ObjectId('53ccf6e8100d2b0741746e9f')
+        p = M.Project.query.get(_id=_id)
         if not p:
             M.Project(
-                _id=ObjectId('53ccf6e8100d2b0741746e9f'),
+                _id=_id,
                 neighborhood_id=M.Neighborhood.query.get(url_prefix='/u/')._id,
                 shortname='test-project',
             )
@@ -263,6 +264,59 @@ class TestProjectsSearch(TestController):
                            'private', 'url', 'Details'])
 
 
+class TestUsersSearch(TestController):
+
+    TEST_HIT = MagicMock(hits=1, docs=[{
+        '_version_': 1478773871277506560,
+        'disabled_b': False,
+        'display_name_t': 'Darth Vader',
+        'id': 'allura/model/auth/User#540efdf2100d2b1483155d39',
+        'last_access_login_date_dt': '2014-09-09T13:17:40.176Z',
+        'last_access_login_ip_s': '10.0.2.2',
+        'last_access_login_ua_t': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML,
like Gecko) Chrome/37.0.2062.94 Safari/537.36',
+        'last_access_session_date_dt': '2014-09-09T13:17:40.33Z',
+        'last_access_session_ip_s': '10.0.2.2',
+        'last_access_session_ua_t': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML,
like Gecko) Chrome/37.0.2062.94 Safari/537.36',
+        'last_password_updated_dt': '2014-09-09T13:17:38.857Z',
+        'localization_s': 'None/None',
+        'sex_s': 'Unknown',
+        'title': ['User darth'],
+        'type_s': 'User',
+        'url_s': '/u/darth/',
+        'user_registration_date_dt': '2014-09-09T13:17:38Z',
+        'username_s': 'darth'}])
+
+    def setUp(self):
+        super(TestUsersSearch, self).setUp()
+        # Create user that matches TEST_HIT id
+        _id = ObjectId('540efdf2100d2b1483155d39')
+        u = M.User.query.get(_id=_id)
+        if not u:
+            M.User(_id=_id, username='darth')
+            ThreadLocalORMSession().flush_all()
+
+    @patch('allura.controllers.site_admin.search')
+    def test_default_fields(self, search):
+        search.site_admin_search.return_value = self.TEST_HIT
+        r = self.app.get('/nf/admin/search_users?q=fake&f=username')
+        options = [o['value'] for o in r.html.findAll('option')]
+        assert_equal(options, ['username', 'display_name', '__custom__'])
+        ths = [th.text for th in r.html.findAll('th')]
+        assert_equal(ths, ['Username', 'Display name', 'Email', 'Registered',
+                           'Disabled?', 'Details'])
+
+    @patch('allura.controllers.site_admin.search')
+    def test_additional_fields(self, search):
+        search.site_admin_search.return_value = self.TEST_HIT
+        with h.push_config(config, **{'search.user.additional_fields': 'email_addresses,
url'}):
+            r = self.app.get('/nf/admin/search_users?q=fake&f=username')
+        options = [o['value'] for o in r.html.findAll('option')]
+        assert_equal(options, ['username', 'display_name', 'email_addresses', 'url', '__custom__'])
+        ths = [th.text for th in r.html.findAll('th')]
+        assert_equal(ths, ['Username', 'Display name', 'Email', 'Registered',
+                           'Disabled?', 'email_addresses', 'url', 'Details'])
+
+
 @task
 def test_task(*args, **kw):
     """test_task doc string"""

http://git-wip-us.apache.org/repos/asf/allura/blob/de6b7753/Allura/allura/tests/unit/test_solr.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/unit/test_solr.py b/Allura/allura/tests/unit/test_solr.py
index 8b237cc..dfe71c7 100644
--- a/Allura/allura/tests/unit/test_solr.py
+++ b/Allura/allura/tests/unit/test_solr.py
@@ -94,7 +94,7 @@ class TestSolr(unittest.TestCase):
     @mock.patch('allura.lib.search.search')
     def test_site_admin_search(self, search):
         from allura.lib.search import site_admin_search
-        from allura.model import Project
+        from allura.model import Project, User
         fq = ['type_s:Project']
         site_admin_search(Project, 'test', 'shortname', rows=25)
         search.assert_called_once_with(
@@ -105,6 +105,17 @@ class TestSolr(unittest.TestCase):
         search.assert_called_once_with(
             'shortname_s:test || shortname_s:test2', fq=fq, ignore_errors=False)
 
+        fq = ['type_s:User']
+        search.reset_mock()
+        site_admin_search(User, 'test-user', 'username', rows=25)
+        search.assert_called_once_with(
+            'username_s:"test-user"', fq=fq, ignore_errors=False, rows=25)
+
+        search.reset_mock()
+        site_admin_search(User, 'username:admin1 || username:root', '__custom__')
+        search.assert_called_once_with(
+            'username_s:admin1 || username_s:root', fq=fq, ignore_errors=False)
+
 
 class TestSearchIndexable(unittest.TestCase):
 


Mime
View raw message