Merge lp:~soren/surveilr/pep8 into lp:surveilr

Proposed by Soren Hansen
Status: Merged
Approved by: Soren Hansen
Approved revision: 23
Merged at revision: 23
Proposed branch: lp:~soren/surveilr/pep8
Merge into: lp:surveilr
Diff against target: 407 lines (+65/-21)
12 files modified
surveilr/admin.py (+7/-3)
surveilr/api/client.py (+28/-1)
surveilr/api/server/app.py (+1/-0)
surveilr/api/server/auth.py (+1/-0)
surveilr/api/server/factory.py (+3/-0)
surveilr/models.py (+2/-0)
surveilr/tests/api/server/test_app.py (+1/-0)
surveilr/tests/api/server/test_auth.py (+4/-3)
surveilr/tests/api/server/test_factory.py (+1/-0)
surveilr/tests/api/test_client.py (+7/-5)
surveilr/tests/test_admin.py (+8/-8)
surveilr/utils.py (+2/-1)
To merge this branch: bzr merge lp:~soren/surveilr/pep8
Reviewer Review Type Date Requested Status
Soren Hansen Pending
Review via email: mp+90588@code.launchpad.net

Commit message

PEP-8 cleanup

Description of the change

PEP-8 cleanup

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'surveilr/admin.py'
2--- surveilr/admin.py 2012-01-28 20:21:21 +0000
3+++ surveilr/admin.py 2012-01-28 21:11:23 +0000
4@@ -28,6 +28,7 @@
5
6 commands = {}
7
8+
9 class CommandMeta(type):
10 def __new__(mcs, name, bases, dict):
11 cls = type.__new__(mcs, name, bases, dict)
12@@ -35,6 +36,7 @@
13 commands[name] = cls
14 return cls
15
16+
17 class Command(object):
18 __metaclass__ = CommandMeta
19
20@@ -67,7 +69,7 @@
21 return None
22
23 def init(self, argv=None):
24- if argv is None: # pragma: nocover
25+ if argv is None: # pragma: nocover
26 argv = sys.argv
27
28 self.options, self.args = self.optparser.parse_args(argv)
29@@ -76,6 +78,7 @@
30
31 self.client = client_class(self.options.url, auth)
32
33+
34 class CreateUser(Command):
35 def get_optparser(self):
36 optparser = super(CreateUser, self).get_optparser()
37@@ -92,8 +95,9 @@
38 print 'Admin:', user.admin
39 print '--user %s --api_key %s' % (user.user_id, user.key)
40
41+
42 def main(argv=None):
43- if argv is None: # pragma: nocover
44+ if argv is None: # pragma: nocover
45 argv = sys.argv[1:]
46
47 if not len(argv):
48@@ -112,5 +116,5 @@
49 return False
50
51
52-if __name__ == '__main__': # pragma: nocover
53+if __name__ == '__main__': # pragma: nocover
54 sys.exit(not main())
55
56=== modified file 'surveilr/api/client.py'
57--- surveilr/api/client.py 2012-01-28 20:21:21 +0000
58+++ surveilr/api/client.py 2012-01-28 21:11:23 +0000
59@@ -1,9 +1,33 @@
60+"""
61+ Surveilr - Log aggregation, analysis and visualisation
62+
63+ Copyright (C) 2011 Linux2Go
64+
65+ This program is free software: you can redistribute it and/or
66+ modify it under the terms of the GNU Affero General Public License
67+ as published by the Free Software Foundation, either version 3 of
68+ the License, or (at your option) any later version.
69+
70+ This program is distributed in the hope that it will be useful,
71+ but WITHOUT ANY WARRANTY; without even the implied warranty of
72+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
73+ GNU Affero General Public License for more details.
74+
75+ You should have received a copy of the GNU Affero General Public
76+ License along with this program. If not, see
77+ <http://www.gnu.org/licenses/>.
78+
79+ Python Client for Surveilr
80+"""
81+
82 import httplib2
83 import json
84
85+
86 class UnauthorizedError(Exception):
87 pass
88
89+
90 class SurveilrClient(object):
91 def __init__(self, url, auth=None):
92 self.url = url
93@@ -32,6 +56,7 @@
94
95 return self.send_req(url_tail, method=method, body=json.dumps(data))
96
97+
98 class SurveilrDirectClient(SurveilrClient):
99 def __init__(self, *args, **kwargs):
100 super(SurveilrDirectClient, self).__init__(*args, **kwargs)
101@@ -46,6 +71,7 @@
102 resp = self.app(req)
103 return resp.body
104
105+
106 class APIObject(object):
107 def __init__(self, client):
108 self.client = client
109@@ -69,4 +95,5 @@
110 return cls(client, client.req(cls, 'create', {'admin': admin}))
111
112 def __repr__(self):
113- return '<User object, user_id=%r, key=%r, admin=%r>' % (self.user_id, self.key, self.admin)
114+ return ('<User object, user_id=%r, key=%r, admin=%r>' %
115+ (self.user_id, self.key, self.admin))
116
117=== modified file 'surveilr/api/server/app.py'
118--- surveilr/api/server/app.py 2012-01-04 23:08:26 +0000
119+++ surveilr/api/server/app.py 2012-01-28 21:11:23 +0000
120@@ -42,6 +42,7 @@
121 from surveilr import models
122 from surveilr import utils
123
124+
125 def is_privileged(req):
126 if 'surveilr.user' in req.environ:
127 return req.environ['surveilr.user'].credentials['admin']
128
129=== modified file 'surveilr/api/server/auth.py'
130--- surveilr/api/server/auth.py 2012-01-04 23:08:26 +0000
131+++ surveilr/api/server/auth.py 2012-01-28 21:11:23 +0000
132@@ -24,6 +24,7 @@
133
134 from riakalchemy import NoSuchObjectError
135
136+
137 class AlwaysRequireAuth(object):
138 def __call__(self, environ, status, headers):
139 return 'repoze.who.identity' not in environ
140
141=== modified file 'surveilr/api/server/factory.py'
142--- surveilr/api/server/factory.py 2012-01-04 23:08:26 +0000
143+++ surveilr/api/server/factory.py 2012-01-28 21:11:23 +0000
144@@ -21,9 +21,12 @@
145 """
146 import eventlet
147
148+
149 def server_factory(global_conf, host, port):
150 port = int(port)
151+
152 def serve(application):
153 socket = eventlet.listen((host, port))
154 eventlet.wsgi.server(socket, application)
155+
156 return serve
157
158=== modified file 'surveilr/models.py'
159--- surveilr/models.py 2012-01-04 23:08:26 +0000
160+++ surveilr/models.py 2012-01-28 21:11:23 +0000
161@@ -24,6 +24,7 @@
162
163 from surveilr import utils
164
165+
166 class Service(RiakObject):
167 """A service that is referenced by many LogEntry's
168
169@@ -53,6 +54,7 @@
170 if not hasattr(self, 'api_key'):
171 self.api_key = utils.generate_key()
172
173+
174 class LogEntry(RiakObject):
175 """A log entry holding one or more metrics
176
177
178=== modified file 'surveilr/tests/api/server/test_app.py'
179--- surveilr/tests/api/server/test_app.py 2012-01-04 23:08:26 +0000
180+++ surveilr/tests/api/server/test_app.py 2012-01-28 21:11:23 +0000
181@@ -42,6 +42,7 @@
182 method='POST',
183 POST=json.dumps({'messaging_driver': 'fake',
184 'messaging_address': 'foo'}))
185+
186 class FakeUser(object):
187 credentials = {'admin': False}
188
189
190=== modified file 'surveilr/tests/api/server/test_auth.py'
191--- surveilr/tests/api/server/test_auth.py 2012-01-04 23:08:26 +0000
192+++ surveilr/tests/api/server/test_auth.py 2012-01-28 21:11:23 +0000
193@@ -24,6 +24,7 @@
194 from surveilr import tests
195 from surveilr.api.server import auth
196
197+
198 class TestAPIServerAuth(tests.TestCase):
199 def test_AlwaysRequireAuth_unauthenticated(self):
200 decider = auth.AlwaysRequireAuth()
201@@ -31,7 +32,9 @@
202
203 def test_AlwaysRequireAuth_already_authenticated(self):
204 decider = auth.AlwaysRequireAuth()
205- self.assertEquals(decider({'repoze.who.identity': 'someone'}, '200 OK', {}), False)
206+ self.assertEquals(decider({'repoze.who.identity': 'someone'},
207+ '200 OK', {}), False)
208+
209
210 class TestSurveilrAuthPlugin(tests.TestCase):
211 def test_authenticate_invcomplete_identity(self):
212@@ -42,7 +45,6 @@
213 identity))
214 self.assertEquals(env, {})
215
216-
217 def test_authenticate_invalid_identity(self):
218 env = {}
219 identity = {'login': 'testuser',
220@@ -52,7 +54,6 @@
221 identity))
222 self.assertEquals(env, {})
223
224-
225 def test_authenticate_valid_credentials(self):
226 env = {}
227
228
229=== modified file 'surveilr/tests/api/server/test_factory.py'
230--- surveilr/tests/api/server/test_factory.py 2012-01-04 23:08:26 +0000
231+++ surveilr/tests/api/server/test_factory.py 2012-01-28 21:11:23 +0000
232@@ -25,6 +25,7 @@
233 from surveilr import tests
234 from surveilr.api.server import factory
235
236+
237 class APIServerFactoryTests(tests.TestCase):
238 def test_server_factory_returns_callable(self):
239 self.assertTrue(callable(factory.server_factory({}, 'somehost', 1234)))
240
241=== modified file 'surveilr/tests/api/test_client.py'
242--- surveilr/tests/api/test_client.py 2012-01-28 20:21:21 +0000
243+++ surveilr/tests/api/test_client.py 2012-01-28 21:11:23 +0000
244@@ -4,6 +4,7 @@
245 from surveilr import tests
246 from surveilr.api import client
247
248+
249 class APIClientTests(tests.TestCase):
250 test_url = 'http://somewhere:1234/else'
251 test_auth = ('foo', 'bar')
252@@ -15,7 +16,6 @@
253 auth = self.test_auth
254 return client.SurveilrClient(self.test_url, self.test_auth)
255
256-
257 @mock.patch('surveilr.api.client.User')
258 def test_new_user(self, User):
259 test_args = ('foo', 'bar', 'baz')
260@@ -27,7 +27,6 @@
261 User.new.assert_called_with(api_client, *test_args, **test_kwargs)
262 self.assertEquals(user, User.new.return_value)
263
264-
265 @mock.patch('surveilr.api.client.httplib2')
266 def test_send_req(self, httplib2):
267 api_client = self._get_client()
268@@ -46,13 +45,13 @@
269
270 self.assertEquals(client_response, 'resp')
271
272-
273 @mock.patch('surveilr.api.client.httplib2')
274 def test_send_req_403_reraises_unauthorized_error(self, httplib2):
275 api_client = self._get_client()
276
277 class FakeResponse(object):
278 reason = 'Just because, ok?'
279+
280 def __init__(self, status_code):
281 self.status = status_code
282
283@@ -88,6 +87,7 @@
284
285 client_obj.req.assert_called_with(TestObject, 'ACTION', data)
286
287+
288 class APITypeTests(tests.TestCase):
289 def _test_user_new(self, admin):
290 client_obj = mock.Mock()
291@@ -95,7 +95,8 @@
292 'key': 'testkey',
293 'admin': admin})
294 user = client.User.new(client_obj)
295- client_obj.req.assert_called_with(client.User, 'create', {'admin': False})
296+ client_obj.req.assert_called_with(client.User, 'create',
297+ {'admin': False})
298
299 self.assertEquals(user.user_id, 'testid')
300 self.assertEquals(user.key, 'testkey')
301@@ -109,6 +110,7 @@
302 def test_user_new_not_admin(self):
303 self._test_user_new(False)
304
305+
306 class DirectClientTests(tests.TestCase):
307 def test_init(self):
308 client_obj = client.SurveilrDirectClient({})
309@@ -122,7 +124,7 @@
310 api_client = client.SurveilrDirectClient({})
311 api_client.app = mock.Mock()
312 response = mock.Mock()
313- response.body = 'response'
314+ response.body = 'response'
315 api_client.app.return_value = response
316
317 client_response = api_client.send_req('tail', 'METHOD', 'body')
318
319=== modified file 'surveilr/tests/test_admin.py'
320--- surveilr/tests/test_admin.py 2012-01-28 20:21:21 +0000
321+++ surveilr/tests/test_admin.py 2012-01-28 21:11:23 +0000
322@@ -28,10 +28,11 @@
323 from surveilr import tests
324 from surveilr.api import client
325
326+
327 class AdminToolTests(tests.TestCase):
328 def test_main(self):
329 saved_commands = admin.commands
330-
331+
332 def restore_commands():
333 admin.commands = saved_commands
334
335@@ -62,19 +63,19 @@
336 self.succesful = True
337 if inner_self.options.reject:
338 raise client.UnauthorizedError('blah')
339-
340+
341 def cleanup():
342 del admin.commands['Foo']
343
344 self.addCleanup(cleanup)
345 return Foo
346-
347+
348 def test_command_class_registers_in_commands(self):
349 Foo = self._define_test_cmd()
350
351 self.assertTrue('Foo' in admin.commands)
352 self.assertEquals(admin.commands['Foo'], Foo)
353-
354+
355 def test_command_short_option(self):
356 self._define_test_cmd()
357 self.succesful = False
358@@ -131,7 +132,7 @@
359 create_user.init(['--admin'])
360 create_user.client = mock.Mock()
361 create_user()
362-
363+
364 create_user.client.new_user.assert_called_with(admin=True)
365
366 def test_CreateUser_non_admin(self):
367@@ -140,7 +141,7 @@
368 create_user.init([])
369 create_user.client = mock.Mock()
370 create_user()
371-
372+
373 create_user.client.new_user.assert_called_with(admin=False)
374
375 def _replace_stdout_with_stringio(self):
376@@ -161,7 +162,6 @@
377 self.assertFalse(ret)
378 self.assertEquals(sys.stdout.getvalue(),
379 'Action not permitted\n')
380-
381
382 def test_cmd_list(self):
383 self._replace_stdout_with_stringio()
384@@ -169,7 +169,7 @@
385
386 self.assertEquals(ret, False)
387 stdout = sys.stdout.getvalue()
388- self.assertEquals(len(stdout.split('\n'))-1, len(admin.commands))
389+ self.assertEquals(len(stdout.split('\n')) - 1, len(admin.commands))
390
391 expected_commands = set(admin.commands.keys())
392 found_commands = set()
393
394=== modified file 'surveilr/utils.py'
395--- surveilr/utils.py 2012-01-04 23:08:26 +0000
396+++ surveilr/utils.py 2012-01-28 21:11:23 +0000
397@@ -42,9 +42,10 @@
398
399
400 def generate_key():
401- return ''.join([random.choice(string.letters + string.digits)
402+ return ''.join([random.choice(string.letters + string.digits)
403 for x in range(32)])
404
405+
406 def enhance_data_point(data_point):
407 http = httplib2.Http(timeout=10)
408

Subscribers

People subscribed via source and target branches

to all changes: