← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~cjwatson/launchpad/testfix-question-cleanup-api into lp:launchpad

 

Colin Watson has proposed merging lp:~cjwatson/launchpad/testfix-question-cleanup-api into lp:launchpad.

Commit message:
Explicitly set the creation dates of test Question objects in lp.answers.tests.test_question_webservice.TestQuestionSetWebService.test_searchQuestions, to ensure that they are sorted reliably.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/testfix-question-cleanup-api/+merge/253233

Explicitly set the creation dates of test Question objects in lp.answers.tests.test_question_webservice.TestQuestionSetWebService.test_searchQuestions, to ensure that they are sorted reliably.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/testfix-question-cleanup-api into lp:launchpad.
=== modified file 'lib/lp/answers/tests/test_question_webservice.py'
--- lib/lp/answers/tests/test_question_webservice.py	2015-03-13 04:07:31 +0000
+++ lib/lp/answers/tests/test_question_webservice.py	2015-03-17 15:37:07 +0000
@@ -1,12 +1,18 @@
-# Copyright 2011 Canonical Ltd.  This software is licensed under the
+# Copyright 2011-2015 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Webservice unit tests related to Launchpad Questions."""
 
 __metaclass__ = type
 
+from datetime import (
+    datetime,
+    timedelta,
+    )
+
 from BeautifulSoup import BeautifulSoup
 from lazr.restfulclient.errors import HTTPError
+import pytz
 from simplejson import dumps
 from testtools.matchers import Equals
 import transaction
@@ -30,6 +36,7 @@
     record_two_runs,
     TestCase,
     TestCaseWithFactory,
+    time_counter,
     ws_object,
     )
 from lp.testing.layers import (
@@ -257,7 +264,11 @@
     layer = DatabaseFunctionalLayer
 
     def test_searchQuestions(self):
-        created = [self.factory.makeQuestion(title="foo") for i in range(10)]
+        date_gen = time_counter(
+            datetime(2015, 01, 01, tzinfo=pytz.UTC), timedelta(days=1))
+        created = [
+            self.factory.makeQuestion(title="foo", datecreated=next(date_gen))
+            for i in range(10)]
         webservice = webservice_for_person(self.factory.makePerson())
         collection = webservice.named_get(
             '/questions', 'searchQuestions', search_text='foo',

=== modified file 'lib/lp/testing/factory.py'
--- lib/lp/testing/factory.py	2015-03-17 10:51:15 +0000
+++ lib/lp/testing/factory.py	2015-03-17 15:37:07 +0000
@@ -2203,7 +2203,7 @@
         return work_item
 
     def makeQuestion(self, target=None, title=None,
-                     owner=None, description=None, language=None):
+                     owner=None, description=None, **kwargs):
         """Create and return a new, arbitrary Question.
 
         :param target: The IQuestionTarget to make the question on. If one is
@@ -2213,8 +2213,6 @@
         :param owner: The owner of the question. If one is not provided, the
             question target owner will be used.
         :param description: The question description.
-        :param language: The question language. If one is not provided, then
-            English will be used.
         """
         if target is None:
             target = self.makeProduct()
@@ -2226,8 +2224,7 @@
             description = self.getUniqueString('description')
         with person_logged_in(owner):
             question = target.newQuestion(
-                owner=owner, title=title, description=description,
-                language=language)
+                owner=owner, title=title, description=description, **kwargs)
         return question
 
     def makeQuestionSubscription(self, question=None, person=None):


Follow ups