summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Treinish <mtreinish@kortar.org>2016-08-31 16:13:36 -0400
committerMatthew Treinish <mtreinish@kortar.org>2016-08-31 16:14:24 -0400
commit75cd6edad266f7f13d613bab7ae2bc80d5ce6082 (patch)
tree11dd1a93fa380ba6ca0237757e52b0da93155f1e
parent01050415dc8cb0e253823ad5fff5e4439a0205b4 (diff)
Add pro forma tests
This commit adds tests so we have tests.
-rw-r--r--lpmqtt/daemon.py2
-rw-r--r--lpmqtt/tests/base.py36
-rw-r--r--lpmqtt/tests/test_daemon.py63
3 files changed, 100 insertions, 1 deletions
diff --git a/lpmqtt/daemon.py b/lpmqtt/daemon.py
index 1043fa7..f009da0 100644
--- a/lpmqtt/daemon.py
+++ b/lpmqtt/daemon.py
@@ -49,7 +49,7 @@ def process_event(event, base_topic):
49 pieces = [base_topic] 49 pieces = [base_topic]
50 if 'project' in event: 50 if 'project' in event:
51 pieces.append(event['project']) 51 pieces.append(event['project'])
52 if 'event_type' in event: 52 if 'event-type' in event:
53 pieces.append(event['event-type']) 53 pieces.append(event['event-type'])
54 if 'bug-number' in event: 54 if 'bug-number' in event:
55 pieces.append(event['bug-number']) 55 pieces.append(event['bug-number'])
diff --git a/lpmqtt/tests/base.py b/lpmqtt/tests/base.py
new file mode 100644
index 0000000..a346f8d
--- /dev/null
+++ b/lpmqtt/tests/base.py
@@ -0,0 +1,36 @@
1# Copyright (c) 2016 Hewlett-Packard Development Company, L.P.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12# implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16import os
17
18import fixtures
19import testtools
20
21
22class TestCase(testtools.TestCase):
23 true = ('True', 'true', '1', 'yes')
24
25 def setUp(self):
26 super(TestCase, self).setUp()
27 if os.environ.get('OS_STDOUT_CAPTURE') in self.true:
28 stdout = self.useFixture(fixtures.StringStream('stdout')).stream
29 self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout))
30 if os.environ.get('OS_STDERR_CAPTURE') in self.true:
31 stderr = self.useFixture(fixtures.StringStream('stderr')).stream
32 self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))
33 if (os.environ.get('OS_LOG_CAPTURE') != 'False' and
34 os.environ.get('OS_LOG_CAPTURE') != '0'):
35 self.useFixture(fixtures.LoggerFixture(nuke_handlers=False,
36 level=None))
diff --git a/lpmqtt/tests/test_daemon.py b/lpmqtt/tests/test_daemon.py
new file mode 100644
index 0000000..13f8f07
--- /dev/null
+++ b/lpmqtt/tests/test_daemon.py
@@ -0,0 +1,63 @@
1# Copyright (c) 2016 Hewlett-Packard Development Company, L.P.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12# implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16import json
17
18from lpmqtt import daemon
19from lpmqtt.tests import base
20
21
22class TestDaemonHelpers(base.TestCase):
23
24 def test_process_event_full_topic(self):
25 fake_event = {
26 'project': 'tempest',
27 'event-type': 'bug',
28 'bug-number': '124321',
29 'body': 'I am a email body',
30 }
31 msg, topic = daemon.process_event(fake_event, 'launchpad')
32 self.assertEqual(json.dumps(fake_event), msg)
33 self.assertEqual('launchpad/tempest/bug/124321', topic)
34
35 def test_process_event_up_to_bug_number_no_event_type(self):
36 fake_event = {
37 'project': 'tempest',
38 'bug-number': '124321',
39 'body': 'I am a email body',
40 }
41 msg, topic = daemon.process_event(fake_event, 'launchpad')
42 self.assertEqual(json.dumps(fake_event), msg)
43 self.assertEqual('launchpad/tempest', topic)
44
45 def test_process_event_no_bug_number(self):
46 fake_event = {
47 'project': 'tempest',
48 'body': 'I am a email body',
49 'event-type': 'bug',
50 }
51 msg, topic = daemon.process_event(fake_event, 'launchpad')
52 self.assertEqual(json.dumps(fake_event), msg)
53 self.assertEqual('launchpad/tempest/bug', topic)
54
55 def test_process_event_no_project(self):
56 fake_event = {
57 'body': 'I am a email body',
58 'event-type': 'bug',
59 'bug-number': '124321',
60 }
61 msg, topic = daemon.process_event(fake_event, 'launchpad')
62 self.assertEqual(json.dumps(fake_event), msg)
63 self.assertEqual('launchpad', topic)