10547.1.5
by Michael Hudson
tests at the other end |
1 |
# Copyright 2010 Canonical Ltd. This software is licensed under the
|
2 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
|
3 |
||
4 |
"""Tests for the hooks in lp.codehosting.vfs.hooks."""
|
|
5 |
||
6 |
__metaclass__ = type |
|
7 |
||
8 |
import unittest |
|
9 |
||
10 |
from lp.codehosting.vfs.hooks import SetProcTitleHook |
|
11 |
from lp.testing import TestCase |
|
12 |
||
13 |
||
14 |
class FakeSetProcTitleModule: |
|
15 |
"""A fake for the setproctitle module.
|
|
16 |
||
17 |
The `setproctitle` module (obviously) has global effects, so can't really
|
|
18 |
be used in unit tests. Instances of this class can be used as a safe
|
|
19 |
replacement.
|
|
20 |
"""
|
|
21 |
||
22 |
def __init__(self, initial_title): |
|
23 |
self.title = initial_title |
|
24 |
||
25 |
def getproctitle(self): |
|
26 |
return self.title |
|
27 |
||
28 |
def setproctitle(self, new_title): |
|
29 |
self.title = new_title |
|
30 |
||
31 |
||
32 |
class TestSetProcTitleHook(TestCase): |
|
33 |
"""Tests for `SetProcTitleHook`."""
|
|
34 |
||
35 |
def test_hook_once(self): |
|
36 |
# Calling the hook once records the passed branch identifier in the
|
|
37 |
# process title.
|
|
38 |
initial_title = self.factory.getUniqueString() |
|
39 |
setproctitle_mod = FakeSetProcTitleModule(initial_title) |
|
40 |
branch_url = self.factory.getUniqueString() |
|
41 |
hook = SetProcTitleHook(setproctitle_mod) |
|
42 |
hook.seen(branch_url) |
|
43 |
self.assertEqual( |
|
10547.1.6
by Michael Hudson
writing tests is only much good if you run them |
44 |
initial_title + " BRANCH:" + branch_url, |
10547.1.5
by Michael Hudson
tests at the other end |
45 |
setproctitle_mod.getproctitle()) |
46 |
||
47 |
def test_hook_twice(self): |
|
48 |
# Calling the hook twice replaces the first branch identifier in the
|
|
49 |
# process title.
|
|
50 |
initial_title = self.factory.getUniqueString() |
|
51 |
setproctitle_mod = FakeSetProcTitleModule(initial_title) |
|
52 |
branch_url1 = self.factory.getUniqueString() |
|
53 |
branch_url2 = self.factory.getUniqueString() |
|
54 |
hook = SetProcTitleHook(setproctitle_mod) |
|
55 |
hook.seen(branch_url1) |
|
56 |
hook.seen(branch_url2) |
|
57 |
self.assertEqual( |
|
10547.1.6
by Michael Hudson
writing tests is only much good if you run them |
58 |
initial_title + " BRANCH:" + branch_url2, |
10547.1.5
by Michael Hudson
tests at the other end |
59 |
setproctitle_mod.getproctitle()) |
60 |
||
61 |
||
62 |
def test_suite(): |
|
63 |
return unittest.TestLoader().loadTestsFromName(__name__) |