Merge lp:~brian-murray/bileto/get-irc-nick into lp:bileto

Proposed by Brian Murray
Status: Merged
Merged at revision: 399
Proposed branch: lp:~brian-murray/bileto/get-irc-nick
Merge into: lp:bileto
Diff against target: 105 lines (+56/-2)
3 files modified
bileto/lplib.py (+13/-0)
bileto/models.py (+3/-1)
tests/test_app.py (+40/-1)
To merge this branch: bzr merge lp:~brian-murray/bileto/get-irc-nick
Reviewer Review Type Date Requested Status
Robert Bruce Park (community) Approve
Review via email: mp+284787@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Robert Bruce Park (robru) wrote :

awesome, thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bileto/lplib.py'
2--- bileto/lplib.py 2016-01-20 20:09:11 +0000
3+++ bileto/lplib.py 2016-02-02 19:46:27 +0000
4@@ -31,3 +31,16 @@
5 def get_series():
6 """Identify currently supported Ubuntu serieses."""
7 return [s.name for s in lp.distributions['ubuntu'].series if s.active]
8+
9+
10+@memoize
11+def get_irc_nick(user):
12+ """Find the freenode irc nick for an LP user."""
13+ try:
14+ person = lp.people[user]
15+ except KeyError:
16+ return user
17+ for irc_id in person.irc_nicknames:
18+ if irc_id.network == 'irc.freenode.net':
19+ return irc_id.nickname
20+ return user
21
22=== modified file 'bileto/models.py'
23--- bileto/models.py 2016-01-29 20:58:14 +0000
24+++ bileto/models.py 2016-02-02 19:46:27 +0000
25@@ -16,6 +16,7 @@
26 from sqlalchemy.inspection import inspect
27
28 from bileto.app import db
29+from bileto.lplib import get_irc_nick
30
31
32 # SQLite can't handle the BigInts, so we overload that for unit tests.
33@@ -197,11 +198,12 @@
34 @classmethod
35 def new(cls):
36 """Create a new Request with some values filled in."""
37+ user = session.get('nickname', '')
38 return cls(
39 distribution='ubuntu',
40 series='xenial+vivid',
41 qa_signoff='QA Required',
42- landers=session.get('nickname', ''))
43+ landers=get_irc_nick(user))
44
45 def publishable(self):
46 """Identify if this request is appropriate to publish or not."""
47
48=== modified file 'tests/test_app.py'
49--- tests/test_app.py 2016-01-20 20:32:06 +0000
50+++ tests/test_app.py 2016-02-02 19:46:27 +0000
51@@ -6,7 +6,7 @@
52 from mock import Mock, patch
53
54 from bileto.settings import read_from_file
55-from bileto.lplib import get_series
56+from bileto.lplib import get_series, get_irc_nick
57
58 from tests.tests import BiletoTestCase
59
60@@ -33,6 +33,45 @@
61 lp_mock.distributions = dict(ubuntu=ubu)
62 self.assertEqual(get_series(), ['alpha'])
63
64+ @patch('bileto.lplib.lp')
65+ def test_get_irc_nick(self, lp_mock):
66+ """Ensure that we get the freenode irc nick from lplib."""
67+ freenode = Mock()
68+ freenode.network = 'irc.freenode.net'
69+ freenode.nickname = 'freenode-nick'
70+ quakenet = Mock()
71+ quakenet.network = 'se.quakenet.org'
72+ quakenet.nickname = 'quakenet-nick'
73+ user = Mock()
74+ user.irc_nicknames = [freenode, quakenet]
75+ lp_mock.people = dict(fred=user)
76+ self.assertEqual(get_irc_nick('fred'), 'freenode-nick')
77+
78+ @patch('bileto.lplib.lp')
79+ def test_no_freenode_nick(self, lp_mock):
80+ """Ensure that we have the lp user when there is no irc nick in lp."""
81+ quakenet = Mock()
82+ quakenet.network = 'se.quakenet.org'
83+ quakenet.nickname = 'quakenet-nick'
84+ user = Mock()
85+ user.irc_nicknames = [quakenet]
86+ lp_mock.people = dict(fred=user)
87+ self.assertNotEqual(get_irc_nick('fred'), 'quakenet-nick')
88+
89+ @patch('bileto.lplib.lp')
90+ def test_no_irc(self, lp_mock):
91+ """Ensure that we have the lp user when there is no irc info in lp."""
92+ user = Mock()
93+ user.irc_nicknames = []
94+ lp_mock.people = dict(gary=user)
95+ self.assertEqual(get_irc_nick('gary'), 'gary')
96+
97+ @patch('bileto.lplib.lp')
98+ def test_not_lp_user(self, lp_mock):
99+ """If the lp user can not be found ensure the username is returned."""
100+ lp_mock.people = dict()
101+ self.assertEqual(get_irc_nick('bob'), 'bob')
102+
103 def test_read_from_file(self):
104 """Ensure that we can read files from disk correctly."""
105 self.assertIn('standard', read_from_file('/etc/python3/debian_config'))

Subscribers

People subscribed via source and target branches

to all changes: