← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~maxiberta/launchpad/sitesearch-dedup-tests into lp:launchpad

 

Maximiliano Bertacchini has proposed merging lp:~maxiberta/launchpad/sitesearch-dedup-tests into lp:launchpad.

Commit message:
Deduplicate sitesearch testservices testing code.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~maxiberta/launchpad/sitesearch-dedup-tests/+merge/343241

Use test scenarios to deduplicate sitesearch testservices testing code.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~maxiberta/launchpad/sitesearch-dedup-tests into lp:launchpad.
=== removed file 'lib/lp/services/sitesearch/tests/test_bingservice.py'
--- lib/lp/services/sitesearch/tests/test_bingservice.py	2018-03-26 20:05:20 +0000
+++ lib/lp/services/sitesearch/tests/test_bingservice.py	1970-01-01 00:00:00 +0000
@@ -1,38 +0,0 @@
-# Copyright 2009-2018 Canonical Ltd.  This software is licensed under the
-# GNU Affero General Public License version 3 (see the file LICENSE).
-
-"""
-Unit tests for the Bing test service stub.
-"""
-
-__metaclass__ = type
-
-
-import os
-import unittest
-
-from lp.services.osutils import process_exists
-from lp.services.pidfile import pidfile_path
-from lp.services.sitesearch import bingtestservice
-
-
-class TestServiceUtilities(unittest.TestCase):
-    """Test the service's supporting functions."""
-
-    def test_stale_pid_file_cleanup(self):
-        """The service should be able to clean up invalid PID files."""
-        bogus_pid = 9999999
-        self.assertFalse(
-            process_exists(bogus_pid),
-            "There is already a process with PID '%d'." % bogus_pid)
-
-        # Create a stale/bogus PID file.
-        filepath = pidfile_path(bingtestservice.service_name)
-        with file(filepath, 'w') as pidfile:
-            pidfile.write(str(bogus_pid))
-
-        # The PID clean-up code should silently remove the file and return.
-        bingtestservice.kill_running_process()
-        self.assertFalse(
-            os.path.exists(filepath),
-            "The PID file '%s' should have been deleted." % filepath)

=== renamed file 'lib/lp/services/sitesearch/tests/test_googleservice.py' => 'lib/lp/services/sitesearch/tests/test_testservices.py'
--- lib/lp/services/sitesearch/tests/test_googleservice.py	2018-03-27 17:43:27 +0000
+++ lib/lp/services/sitesearch/tests/test_testservices.py	2018-04-13 20:37:40 +0000
@@ -1,9 +1,9 @@
 # Copyright 2009-2018 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
-"""
-Unit tests for the Google test service stub.
-"""
+"""Unit tests for sitesearch test service stubs."""
+
+from __future__ import absolute_import, print_function, unicode_literals
 
 __metaclass__ = type
 
@@ -11,14 +11,28 @@
 import os
 import unittest
 
+from testscenarios import WithScenarios
+
 from lp.services.osutils import process_exists
 from lp.services.pidfile import pidfile_path
-from lp.services.sitesearch import googletestservice
-
-
-class TestServiceUtilities(unittest.TestCase):
+from lp.services.sitesearch import (
+    bingtestservice,
+    googletestservice,
+    )
+
+
+class TestServiceUtilities(WithScenarios, unittest.TestCase):
     """Test the service's supporting functions."""
 
+    scenarios = [
+        ("Bing", {
+            "testservice": bingtestservice,
+            }),
+        ("Google", {
+            "testservice": googletestservice,
+            }),
+        ]
+
     def test_stale_pid_file_cleanup(self):
         """The service should be able to clean up invalid PID files."""
         bogus_pid = 9999999
@@ -27,13 +41,12 @@
             "There is already a process with PID '%d'." % bogus_pid)
 
         # Create a stale/bogus PID file.
-        filepath = pidfile_path(googletestservice.service_name)
-        pidfile = file(filepath, 'w')
-        pidfile.write(str(bogus_pid))
-        pidfile.close()
+        filepath = pidfile_path(self.testservice.service_name)
+        with file(filepath, 'w') as pidfile:
+            pidfile.write(str(bogus_pid))
 
         # The PID clean-up code should silently remove the file and return.
-        googletestservice.kill_running_process()
+        self.testservice.kill_running_process()
         self.assertFalse(
             os.path.exists(filepath),
             "The PID file '%s' should have been deleted." % filepath)


Follow ups