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

Proposed by Maximiliano Bertacchini
Status: Merged
Merged at revision: 18614
Proposed branch: lp:~maxiberta/launchpad/sitesearch-dedup-tests
Merge into: lp:launchpad
Diff against target: 110 lines (+25/-50)
2 files modified
lib/lp/services/sitesearch/tests/test_bingservice.py (+0/-38)
lib/lp/services/sitesearch/tests/test_testservices.py (+25/-12)
To merge this branch: bzr merge lp:~maxiberta/launchpad/sitesearch-dedup-tests
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+343241@code.launchpad.net

Commit message

Deduplicate sitesearch testservices testing code.

Description of the change

Use test scenarios to deduplicate sitesearch testservices testing code.

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== removed file 'lib/lp/services/sitesearch/tests/test_bingservice.py'
2--- lib/lp/services/sitesearch/tests/test_bingservice.py 2018-03-26 20:05:20 +0000
3+++ lib/lp/services/sitesearch/tests/test_bingservice.py 1970-01-01 00:00:00 +0000
4@@ -1,38 +0,0 @@
5-# Copyright 2009-2018 Canonical Ltd. This software is licensed under the
6-# GNU Affero General Public License version 3 (see the file LICENSE).
7-
8-"""
9-Unit tests for the Bing test service stub.
10-"""
11-
12-__metaclass__ = type
13-
14-
15-import os
16-import unittest
17-
18-from lp.services.osutils import process_exists
19-from lp.services.pidfile import pidfile_path
20-from lp.services.sitesearch import bingtestservice
21-
22-
23-class TestServiceUtilities(unittest.TestCase):
24- """Test the service's supporting functions."""
25-
26- def test_stale_pid_file_cleanup(self):
27- """The service should be able to clean up invalid PID files."""
28- bogus_pid = 9999999
29- self.assertFalse(
30- process_exists(bogus_pid),
31- "There is already a process with PID '%d'." % bogus_pid)
32-
33- # Create a stale/bogus PID file.
34- filepath = pidfile_path(bingtestservice.service_name)
35- with file(filepath, 'w') as pidfile:
36- pidfile.write(str(bogus_pid))
37-
38- # The PID clean-up code should silently remove the file and return.
39- bingtestservice.kill_running_process()
40- self.assertFalse(
41- os.path.exists(filepath),
42- "The PID file '%s' should have been deleted." % filepath)
43
44=== renamed file 'lib/lp/services/sitesearch/tests/test_googleservice.py' => 'lib/lp/services/sitesearch/tests/test_testservices.py'
45--- lib/lp/services/sitesearch/tests/test_googleservice.py 2018-03-27 17:43:27 +0000
46+++ lib/lp/services/sitesearch/tests/test_testservices.py 2018-04-13 20:37:40 +0000
47@@ -1,9 +1,9 @@
48 # Copyright 2009-2018 Canonical Ltd. This software is licensed under the
49 # GNU Affero General Public License version 3 (see the file LICENSE).
50
51-"""
52-Unit tests for the Google test service stub.
53-"""
54+"""Unit tests for sitesearch test service stubs."""
55+
56+from __future__ import absolute_import, print_function, unicode_literals
57
58 __metaclass__ = type
59
60@@ -11,14 +11,28 @@
61 import os
62 import unittest
63
64+from testscenarios import WithScenarios
65+
66 from lp.services.osutils import process_exists
67 from lp.services.pidfile import pidfile_path
68-from lp.services.sitesearch import googletestservice
69-
70-
71-class TestServiceUtilities(unittest.TestCase):
72+from lp.services.sitesearch import (
73+ bingtestservice,
74+ googletestservice,
75+ )
76+
77+
78+class TestServiceUtilities(WithScenarios, unittest.TestCase):
79 """Test the service's supporting functions."""
80
81+ scenarios = [
82+ ("Bing", {
83+ "testservice": bingtestservice,
84+ }),
85+ ("Google", {
86+ "testservice": googletestservice,
87+ }),
88+ ]
89+
90 def test_stale_pid_file_cleanup(self):
91 """The service should be able to clean up invalid PID files."""
92 bogus_pid = 9999999
93@@ -27,13 +41,12 @@
94 "There is already a process with PID '%d'." % bogus_pid)
95
96 # Create a stale/bogus PID file.
97- filepath = pidfile_path(googletestservice.service_name)
98- pidfile = file(filepath, 'w')
99- pidfile.write(str(bogus_pid))
100- pidfile.close()
101+ filepath = pidfile_path(self.testservice.service_name)
102+ with file(filepath, 'w') as pidfile:
103+ pidfile.write(str(bogus_pid))
104
105 # The PID clean-up code should silently remove the file and return.
106- googletestservice.kill_running_process()
107+ self.testservice.kill_running_process()
108 self.assertFalse(
109 os.path.exists(filepath),
110 "The PID file '%s' should have been deleted." % filepath)