allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [09/38] git commit: [#4019] ticket:481 Add some unit tests
Date Wed, 30 Apr 2014 18:15:41 GMT
[#4019] ticket:481 Add some unit tests


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

Branch: refs/heads/master
Commit: 21e03c0df14d80cb240a0e5e41dbfd89a6abeca9
Parents: 7a39ef8
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Fri Dec 20 12:58:38 2013 +0200
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Wed Apr 30 15:55:10 2014 +0000

----------------------------------------------------------------------
 .../forgetracker/tests/unit/test_search.py      | 58 ++++++++++++++++++++
 .../tests/unit/test_ticket_model.py             | 22 ++++++++
 2 files changed, 80 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/21e03c0d/ForgeTracker/forgetracker/tests/unit/test_search.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tests/unit/test_search.py b/ForgeTracker/forgetracker/tests/unit/test_search.py
new file mode 100644
index 0000000..9a2fafa
--- /dev/null
+++ b/ForgeTracker/forgetracker/tests/unit/test_search.py
@@ -0,0 +1,58 @@
+#       Licensed to the Apache Software Foundation (ASF) under one
+#       or more contributor license agreements.  See the NOTICE file
+#       distributed with this work for additional information
+#       regarding copyright ownership.  The ASF licenses this file
+#       to you under the Apache License, Version 2.0 (the
+#       "License"); you may not use this file except in compliance
+#       with the License.  You may obtain a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#       Unless required by applicable law or agreed to in writing,
+#       software distributed under the License is distributed on an
+#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#       KIND, either express or implied.  See the License for the
+#       specific language governing permissions and limitations
+#       under the License.
+
+import mock
+from nose.tools import assert_equal
+from forgetracker.search import get_facets, query_filter_choices
+
+
+def hit_mock():
+    hit = mock.Mock()
+    hit.facets = {'facet_fields': {'_milestone_s': ['1.0', 3, '2.0', 2],
+                                   'assigned_to_s': ['admin1', 1],
+                                   'reported_by_s': ['admin1', 5],
+                                   'status_s': ['closed', 1, 'open', 3, 'unread', 1]}}
+    reformated = {'_milestone': [('1.0', 3), ('2.0', 2)],
+                'assigned_to': [('admin1', 1)],
+                'reported_by': [('admin1', 5)],
+                'status': [('closed', 1), ('open', 3), ('unread', 1)]}
+    return hit, reformated
+
+
+def test_get_facets():
+    hit,expected = hit_mock()
+    assert_equal(get_facets(hit), expected)
+
+
+@mock.patch('forgetracker.search.search')
+@mock.patch('forgetracker.search.c')
+def test_query_filter_choices(c, search):
+    hit, expected = hit_mock()
+    search.return_value = hit
+    result = query_filter_choices()
+    params = {'short_timeout': True,
+              'fq': ['project_id_s:%s' % c.project._id,
+                     'mount_point_s:%s' % c.app.config.options.mount_point],
+              'rows': 0,
+              'facet': 'true',
+              'facet.field': ['_milestone_s', 'status_s',
+                              'assigned_to_s', 'reported_by_s'],
+              'facet.limit': -1,
+              'facet.sort': 'index',
+              'facet.mincount': 1}
+    search.assert_called_once_with(None, **params)
+    assert_equal(result, expected)

http://git-wip-us.apache.org/repos/asf/allura/blob/21e03c0d/ForgeTracker/forgetracker/tests/unit/test_ticket_model.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tests/unit/test_ticket_model.py b/ForgeTracker/forgetracker/tests/unit/test_ticket_model.py
index f9f4bcb..0f45210 100644
--- a/ForgeTracker/forgetracker/tests/unit/test_ticket_model.py
+++ b/ForgeTracker/forgetracker/tests/unit/test_ticket_model.py
@@ -19,6 +19,7 @@ from pylons import tmpl_context as c
 from datetime import datetime
 import urllib2
 
+import mock
 from ming.orm.ormsession import ThreadLocalORMSession
 from ming.orm import session
 from ming import schema
@@ -310,3 +311,24 @@ class TestTicketModel(TrackerTestWithModel):
         assert_in('votes_up', json_keys)  # VotableArtifact
         assert_in('ticket_num', json_keys)  # Ticket
         assert ticket.__json__()['assigned_to'] is None
+
+    @mock.patch('forgetracker.model.ticket.tsearch')
+    @mock.patch.object(Ticket, 'paged_search')
+    @mock.patch.object(Ticket, 'paged_query')
+    def test_paged_query_or_search(self, query, search, tsearch):
+        app_cfg, user = mock.Mock(), mock.Mock()
+        mongo_query = 'mongo query'
+        solr_query = 'solr query'
+        kw = {'kw1': 'test1', 'kw2': 'test2'}
+        filter = None
+        Ticket.paged_query_or_search(app_cfg, user, mongo_query, solr_query, filter, **kw)
+        query.assert_called_once_with(app_cfg, user, mongo_query, sort=None, limit=None,
page=0, **kw)
+        tsearch.query_filter_choices.assert_called_once()
+        assert_equal(search.call_count, 0)
+        query.reset_mock(), search.reset_mock(), tsearch.reset_mock()
+
+        filter = {'status': 'unread'}
+        Ticket.paged_query_or_search(app_cfg, user, mongo_query, solr_query, filter, **kw)
+        search.assert_called_once_with(app_cfg, user, solr_query, filter=filter, sort=None,
limit=None, page=0, **kw)
+        assert_equal(query.call_count, 0)
+        assert_equal(tsearch.query_filter_choices.call_count, 0)


Mime
View raw message