allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jetm...@apache.org
Subject [32/50] [abbrv] allura git commit: PEP8 cleanup; add license header to test_webhooks.py
Date Tue, 24 Feb 2015 11:48:26 GMT
http://git-wip-us.apache.org/repos/asf/allura/blob/a3620b4a/Allura/allura/lib/plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py
index a901ba9..fb1c3b9 100644
--- a/Allura/allura/lib/plugin.py
+++ b/Allura/allura/lib/plugin.py
@@ -107,8 +107,8 @@ class AuthenticationProvider(object):
             self.logout()
             return M.User.anonymous()
         if not user.is_anonymous() and \
-                        self.get_last_password_updated(user) > datetime.utcfromtimestamp(self.session.created)
and \
-                        user.get_tool_data('allura', 'pwd_reset_preserve_session') != self.session.id:
+                self.get_last_password_updated(user) > datetime.utcfromtimestamp(self.session.created)
and \
+                user.get_tool_data('allura', 'pwd_reset_preserve_session') != self.session.id:
             log.debug('Session logged out: due to user %s pwd change %s > %s', user.username,
                       self.get_last_password_updated(user), datetime.utcfromtimestamp(self.session.created))
             self.logout()
@@ -133,7 +133,7 @@ class AuthenticationProvider(object):
         :param user_doc: a dict with 'username' and 'display_name'.  Optionally 'password'
and others
         :rtype: :class:`User <allura.model.auth.User>`
         '''
-        raise NotImplementedError, 'register_user'
+        raise NotImplementedError('register_user')
 
     def _login(self):
         '''
@@ -142,7 +142,7 @@ class AuthenticationProvider(object):
         :rtype: :class:`User <allura.model.auth.User>`
         :raises: HTTPUnauthorized if user not found, or credentials are not valid
         '''
-        raise NotImplementedError, '_login'
+        raise NotImplementedError('_login')
 
     def login(self, user=None):
         try:
@@ -184,23 +184,23 @@ class AuthenticationProvider(object):
 
         :rtype: bool
         '''
-        raise NotImplementedError, 'validate_password'
+        raise NotImplementedError('validate_password')
 
     def disable_user(self, user, **kw):
         '''Disable user account'''
-        raise NotImplementedError, 'disable_user'
+        raise NotImplementedError('disable_user')
 
     def enable_user(self, user, **kw):
         '''Enable user account'''
-        raise NotImplementedError, 'enable_user'
+        raise NotImplementedError('enable_user')
 
     def activate_user(self, user, **kw):
         '''Activate user after registration'''
-        raise NotImplementedError, 'activate_user'
+        raise NotImplementedError('activate_user')
 
     def deactivate_user(self, user, **kw):
         '''Deactivate user (== registation not confirmed)'''
-        raise NotImplementedError, 'deactivate_user'
+        raise NotImplementedError('deactivate_user')
 
     def by_username(self, username):
         '''
@@ -208,20 +208,20 @@ class AuthenticationProvider(object):
 
         :rtype: :class:`User <allura.model.auth.User>` or None
         '''
-        raise NotImplementedError, 'by_username'
+        raise NotImplementedError('by_username')
 
     def set_password(self, user, old_password, new_password):
         '''
         Set a user's password.
 
-        A provider implementing this method should store the timestamp of this change, either
on ``user.last_password_updated`` or
-        somewhere else that a custom ``get_last_password_updated`` method uses.
+        A provider implementing this method should store the timestamp of this change, either
+        on ``user.last_password_updated`` or somewhere else that a custom ``get_last_password_updated``
method uses.
 
         :param user: a :class:`User <allura.model.auth.User>`
         :rtype: None
         :raises: HTTPUnauthorized if old_password is not valid
         '''
-        raise NotImplementedError, 'set_password'
+        raise NotImplementedError('set_password')
 
     def upload_sshkey(self, username, pubkey):
         '''
@@ -230,7 +230,7 @@ class AuthenticationProvider(object):
         :rtype: None
         :raises: AssertionError with user message, upon any error
         '''
-        raise NotImplementedError, 'upload_sshkey'
+        raise NotImplementedError('upload_sshkey')
 
     def account_navigation(self):
         return [
@@ -269,17 +269,17 @@ class AuthenticationProvider(object):
         :param user: a :class:`User <allura.model.auth.User>`
         :rtype: str
         '''
-        raise NotImplementedError, 'user_project_shortname'
+        raise NotImplementedError('user_project_shortname')
 
     def user_by_project_shortname(self, shortname):
         '''
         :param str: shortname
         :rtype: user: a :class:`User <allura.model.auth.User>`
         '''
-        raise NotImplementedError, 'user_by_project_shortname'
+        raise NotImplementedError('user_by_project_shortname')
 
     def update_notifications(self, user):
-        raise NotImplementedError, 'update_notifications'
+        raise NotImplementedError('update_notifications')
 
     def user_registration_date(self, user):
         '''
@@ -288,7 +288,7 @@ class AuthenticationProvider(object):
         :param user: a :class:`User <allura.model.auth.User>`
         :rtype: :class:`datetime <datetime.datetime>`
         '''
-        raise NotImplementedError, 'user_registration_date'
+        raise NotImplementedError('user_registration_date')
 
     def get_last_password_updated(self, user):
         '''
@@ -297,7 +297,7 @@ class AuthenticationProvider(object):
         :param user: a :class:`User <allura.model.auth.User>`
         :rtype: :class:`datetime <datetime.datetime>`
         '''
-        raise NotImplementedError, 'get_last_password_updated'
+        raise NotImplementedError('get_last_password_updated')
 
     def get_primary_email_address(self, user_record):
         return user_record.get_pref('email_address') if user_record else None
@@ -330,7 +330,7 @@ class AuthenticationProvider(object):
         Links will show up at admin user search page.
         '''
         return [
-           ('/nf/admin/user/%s' % user.username, 'Details/Edit'),
+            ('/nf/admin/user/%s' % user.username, 'Details/Edit'),
         ]
 
 
@@ -479,7 +479,8 @@ class LdapAuthenticationProvider(AuthenticationProvider):
                 raise Exception('You should not have both "auth.ldap.autoregister" and '
                                 '"auth.allow_user_registration" set to true')
             else:
-                log.debug('LdapAuth: autoregister is true, so only creating the mongo record
(no creating ldap record)')
+                log.debug('LdapAuth: autoregister is true, so only creating the mongo '
+                          'record (not creating ldap record)')
                 return result
 
         # full registration into LDAP
@@ -521,7 +522,7 @@ class LdapAuthenticationProvider(AuthenticationProvider):
 
     def upload_sshkey(self, username, pubkey):
         if not asbool(config.get('auth.ldap.use_schroot', True)):
-            raise NotImplementedError, 'SSH keys are not supported'
+            raise NotImplementedError('SSH keys are not supported')
 
         argv = ('schroot -d / -c %s -u root /ldap-userconfig.py upload %s' % (
             config['auth.ldap.schroot_name'], username)).split() + [pubkey]
@@ -574,7 +575,8 @@ class LdapAuthenticationProvider(AuthenticationProvider):
 
     def _login(self):
         if ldap is None:
-            raise Exception('The python-ldap package needs to be installed.  Run `pip install
python-ldap` in your allura environment.')
+            raise Exception('The python-ldap package needs to be installed.  '
+                            'Run `pip install python-ldap` in your allura environment.')
         from allura import model as M
         try:
             username = str(self.request.params['username'])
@@ -585,7 +587,8 @@ class LdapAuthenticationProvider(AuthenticationProvider):
         user = M.User.query.get(username=username)
         if user is None:
             if asbool(config.get('auth.ldap.autoregister', True)):
-                log.debug('LdapAuth: authorized user {} needs a mongo record registered.
 Creating...'.format(username))
+                log.debug('LdapAuth: authorized user {} needs a mongo record registered.
 '
+                          'Creating...'.format(username))
                 user = M.User.register({'username': username,
                                         'display_name': LdapUserPreferencesProvider()._get_pref(username,
'display_name'),
                                         })
@@ -751,7 +754,7 @@ class ProjectRegistrationProvider(object):
         from allura import model as M
 
         # Check for private project rights
-        if neighborhood.features['private_projects'] == False and private_project:
+        if neighborhood.features['private_projects'] is False and private_project:
             raise ValueError(
                 "You can't create private projects for %s neighborhood" %
                 neighborhood.name)
@@ -957,8 +960,8 @@ class ProjectRegistrationProvider(object):
         Links will show up at admin project search page
         '''
         return [
-           (project.url() + 'admin/groups/', 'Members'),
-           (project.url() + 'admin/audit/', 'Audit Trail'),
+            (project.url() + 'admin/groups/', 'Members'),
+            (project.url() + 'admin/audit/', 'Audit Trail'),
         ]
 
 
@@ -1242,7 +1245,7 @@ class UserPreferencesProvider(object):
         :return: pref_value
         :raises: AttributeError if pref_name not found
         '''
-        raise NotImplementedError, 'get_pref'
+        raise NotImplementedError('get_pref')
 
     def set_pref(self, user, pref_name, pref_value):
         '''
@@ -1250,7 +1253,7 @@ class UserPreferencesProvider(object):
         :param str pref_name:
         :param pref_value:
         '''
-        raise NotImplementedError, 'set_pref'
+        raise NotImplementedError('set_pref')
 
     def additional_urls(self):
         '''

http://git-wip-us.apache.org/repos/asf/allura/blob/a3620b4a/Allura/allura/model/webhook.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/webhook.py b/Allura/allura/model/webhook.py
index 563f871..d1165ff 100644
--- a/Allura/allura/model/webhook.py
+++ b/Allura/allura/model/webhook.py
@@ -25,7 +25,6 @@ from allura.model import Artifact
 
 
 class Webhook(Artifact):
-
     class __mongometa__:
         name = 'webhook'
         unique_indexes = [('app_config_id', 'type', 'hook_url')]

http://git-wip-us.apache.org/repos/asf/allura/blob/a3620b4a/Allura/allura/tests/functional/test_auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_auth.py b/Allura/allura/tests/functional/test_auth.py
index b71ffcd..eacabd0 100644
--- a/Allura/allura/tests/functional/test_auth.py
+++ b/Allura/allura/tests/functional/test_auth.py
@@ -309,8 +309,8 @@ class TestAuth(TestController):
         ThreadLocalORMSession.flush_all()
 
         self.app.post('/auth/send_verification_link',
-                          params=dict(a=email_address),
-                          extra_environ=dict(username='test-user'))
+                      params=dict(a=email_address),
+                      extra_environ=dict(username='test-user'))
 
         user1 = M.User.query.get(username='test-user-1')
         user1.claim_address(email_address)
@@ -324,7 +324,6 @@ class TestAuth(TestController):
         email = M.EmailAddress.find(dict(email=email_address, claimed_by_user_id=user._id)).first()
         assert not email.confirmed
 
-
     @td.with_user_project('test-admin')
     def test_prefs(self):
         r = self.app.get('/auth/preferences/',
@@ -777,9 +776,9 @@ class TestPreferences(TestController):
                       params=dict(socialnetwork=socialnetwork,
                                   accounturl=accounturl))
         user = M.User.query.get(username='test-admin')
-        assert len(user.socialnetworks) == 1 \
-               and user.socialnetworks[0].socialnetwork == socialnetwork \
-               and user.socialnetworks[0].accounturl == accounturl
+        assert len(user.socialnetworks) == 1
+        assert_equal(user.socialnetworks[0].socialnetwork, socialnetwork)
+        assert_equal(user.socialnetworks[0].accounturl, accounturl)
 
         # Add second social network account
         socialnetwork2 = 'Twitter'
@@ -788,31 +787,31 @@ class TestPreferences(TestController):
                       params=dict(socialnetwork=socialnetwork2,
                                   accounturl='@test'))
         user = M.User.query.get(username='test-admin')
-        assert len(user.socialnetworks) == 2 and \
-               ({'socialnetwork': socialnetwork, 'accounturl': accounturl} in user.socialnetworks
and
-                {'socialnetwork': socialnetwork2, 'accounturl': accounturl2} in user.socialnetworks)
+        assert len(user.socialnetworks) == 2
+        assert_in({'socialnetwork': socialnetwork, 'accounturl': accounturl}, user.socialnetworks)
+        assert_in({'socialnetwork': socialnetwork2, 'accounturl': accounturl2}, user.socialnetworks)
 
         # Remove first social network account
         self.app.post('/auth/user_info/contacts/remove_social_network',
                       params=dict(socialnetwork=socialnetwork,
                                   account=accounturl))
         user = M.User.query.get(username='test-admin')
-        assert len(user.socialnetworks) == 1 and \
-               {'socialnetwork': socialnetwork2, 'accounturl': accounturl2} in user.socialnetworks
+        assert len(user.socialnetworks) == 1
+        assert_in({'socialnetwork': socialnetwork2, 'accounturl': accounturl2}, user.socialnetworks)
 
         # Add empty social network account
         self.app.post('/auth/user_info/contacts/add_social_network',
                       params=dict(accounturl=accounturl, socialnetwork=''))
         user = M.User.query.get(username='test-admin')
-        assert len(user.socialnetworks) == 1 and \
-               {'socialnetwork': socialnetwork2, 'accounturl': accounturl2} in user.socialnetworks
+        assert len(user.socialnetworks) == 1
+        assert_in({'socialnetwork': socialnetwork2, 'accounturl': accounturl2}, user.socialnetworks)
 
         # Add invalid social network account
         self.app.post('/auth/user_info/contacts/add_social_network',
                       params=dict(accounturl=accounturl, socialnetwork='invalid'))
         user = M.User.query.get(username='test-admin')
-        assert len(user.socialnetworks) == 1 and \
-               {'socialnetwork': socialnetwork2, 'accounturl': accounturl2} in user.socialnetworks
+        assert len(user.socialnetworks) == 1
+        assert_in({'socialnetwork': socialnetwork2, 'accounturl': accounturl2}, user.socialnetworks)
 
         # Add telephone number
         telnumber = '+3902123456'
@@ -886,9 +885,9 @@ class TestPreferences(TestController):
         user = M.User.query.get(username='test-admin')
         timeslot2dict = dict(week_day=weekday2,
                              start_time=starttime2, end_time=endtime2)
-        assert len(user.availability) == 2 \
-               and timeslot1dict in user.get_availability_timeslots() \
-               and timeslot2dict in user.get_availability_timeslots()
+        assert len(user.availability) == 2
+        assert_in(timeslot1dict, user.get_availability_timeslots())
+        assert_in(timeslot2dict, user.get_availability_timeslots())
 
         # Remove availability timeslot
         r = self.app.post('/auth/user_info/availability/remove_timeslot',
@@ -936,9 +935,9 @@ class TestPreferences(TestController):
                               enddate=enddate2.strftime('%d/%m/%Y')))
         user = M.User.query.get(username='test-admin')
         period2dict = dict(start_date=startdate2, end_date=enddate2)
-        assert len(user.inactiveperiod) == 2 \
-               and period1dict in user.get_inactive_periods() \
-               and period2dict in user.get_inactive_periods()
+        assert len(user.inactiveperiod) == 2
+        assert_in(period1dict, user.get_inactive_periods())
+        assert_in(period2dict, user.get_inactive_periods())
 
         # Remove first inactivity period
         r = self.app.post(

http://git-wip-us.apache.org/repos/asf/allura/blob/a3620b4a/Allura/allura/tests/test_webhooks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_webhooks.py b/Allura/allura/tests/test_webhooks.py
index fee1556..330c4bd 100644
--- a/Allura/allura/tests/test_webhooks.py
+++ b/Allura/allura/tests/test_webhooks.py
@@ -1,3 +1,20 @@
+#       Licensed to the Apache Software Foundation (ASF) under one
+#       or more contributor license agreements.  See the NOTICE file
+#       distributed with this work for additional information
+#       regarding copyright ownership.  The ASF licenses this file
+#       to you under the Apache License, Version 2.0 (the
+#       "License"); you may not use this file except in compliance
+#       with the License.  You may obtain a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#       Unless required by applicable law or agreed to in writing,
+#       software distributed under the License is distributed on an
+#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#       KIND, either express or implied.  See the License for the
+#       specific language governing permissions and limitations
+#       under the License.
+
 import json
 import hmac
 import hashlib
@@ -37,7 +54,6 @@ with_git2 = td.with_tool(test_project_with_repo, 'git', 'src2', 'Git2')
 
 
 class TestWebhookBase(object):
-
     def setUp(self):
         setup_basic_test()
         self.patches = self.monkey_patch()
@@ -69,7 +85,6 @@ class TestWebhookBase(object):
 
 
 class TestValidators(TestWebhookBase):
-
     @with_git2
     def test_webhook_validator(self):
         sender = Mock(type='repo-push')
@@ -107,7 +122,6 @@ class TestValidators(TestWebhookBase):
 
 
 class TestWebhookController(TestController):
-
     def setUp(self):
         super(TestWebhookController, self).setUp()
         self.patches = self.monkey_patch()
@@ -167,8 +181,8 @@ class TestWebhookController(TestController):
                          extra_environ={'username': '*anonymous'},
                          status=302)
         assert_equal(r.location,
-            'http://localhost/auth/'
-            '?return_to=%2Fadobe%2Fadobe-1%2Fadmin%2Fsrc%2Fwebhooks%2Frepo-push%2F')
+                     'http://localhost/auth/'
+                     '?return_to=%2Fadobe%2Fadobe-1%2Fadmin%2Fsrc%2Fwebhooks%2Frepo-push%2F')
 
     def test_invalid_hook_type(self):
         self.app.get(self.url + '/invalid-hook-type/', status=404)
@@ -197,7 +211,7 @@ class TestWebhookController(TestController):
         with td.out_audits(msg):
             r = self.app.post(self.url + '/repo-push/create', data)
         self.find_error(r, '_the_form',
-            '"repo-push" webhook already exists for Git http://httpbin.org/post')
+                        '"repo-push" webhook already exists for Git http://httpbin.org/post')
         assert_equal(M.Webhook.query.find().count(), 1)
 
     def test_create_limit_reached(self):
@@ -230,7 +244,7 @@ class TestWebhookController(TestController):
         data = {'url': 'qwer', 'secret': 'qwe'}
         r = self.app.post(self.url + '/repo-push/create', data)
         self.find_error(r, 'url',
-            'You must provide a full domain name (like qwer.com)')
+                        'You must provide a full domain name (like qwer.com)')
 
     def test_edit(self):
         data1 = {'url': u'http://httpbin.org/post',
@@ -268,8 +282,8 @@ class TestWebhookController(TestController):
         form['url'] = data2['url']
         r = form.submit()
         self.find_error(r, '_the_form',
-            u'"repo-push" webhook already exists for Git http://example.com/hook',
-            form_type='edit')
+                        u'"repo-push" webhook already exists for Git http://example.com/hook',
+                        form_type='edit')
 
     def test_edit_validation(self):
         invalid = M.Webhook(
@@ -299,7 +313,7 @@ class TestWebhookController(TestController):
         data = {'url': 'qwe', 'secret': 'qwe', 'webhook': str(wh._id)}
         r = self.app.post(self.url + '/repo-push/edit', data)
         self.find_error(r, 'url',
-            'You must provide a full domain name (like qwe.com)', 'edit')
+                        'You must provide a full domain name (like qwe.com)', 'edit')
 
     def test_delete(self):
         data = {'url': u'http://httpbin.org/post',
@@ -375,17 +389,19 @@ class TestWebhookController(TestController):
         def link(td):
             a = td.find('a')
             return {'href': a.get('href'), 'text': a.getText()}
+
         def text(td):
             return {'text': td.getText()}
+
         def delete_btn(td):
             a = td.find('a')
             return {'href': a.get('href'), 'data-id': a.get('data-id')}
+
         tds = row.findAll('td')
         return [text(tds[0]), text(tds[1]), link(tds[2]), delete_btn(tds[3])]
 
 
 class TestSendWebhookHelper(TestWebhookBase):
-
     def setUp(self, *args, **kw):
         super(TestSendWebhookHelper, self).setUp(*args, **kw)
         self.payload = {'some': ['data', 23]}
@@ -490,7 +506,6 @@ class TestSendWebhookHelper(TestWebhookBase):
 
 
 class TestRepoPushWebhookSender(TestWebhookBase):
-
     @patch('allura.webhooks.send_webhook', autospec=True)
     def test_send(self, send_webhook):
         sender = RepoPushWebhookSender()
@@ -597,10 +612,9 @@ class TestRepoPushWebhookSender(TestWebhookBase):
 
 
 class TestModels(TestWebhookBase):
-
     def test_webhook_url(self):
         assert_equal(self.wh.url(),
-            '/adobe/adobe-1/admin/src/webhooks/repo-push/{}'.format(self.wh._id))
+                     '/adobe/adobe-1/admin/src/webhooks/repo-push/{}'.format(self.wh._id))
 
     def test_webhook_enforce_limit(self):
         self.wh.last_sent = None

http://git-wip-us.apache.org/repos/asf/allura/blob/a3620b4a/Allura/allura/webhooks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/webhooks.py b/Allura/allura/webhooks.py
index ba55a89..fc21bf4 100644
--- a/Allura/allura/webhooks.py
+++ b/Allura/allura/webhooks.py
@@ -192,7 +192,6 @@ class WebhookController(BaseController):
 
 
 class SendWebhookHelper(object):
-
     def __init__(self, webhook, payload):
         self.webhook = webhook
         self.payload = payload
@@ -246,10 +245,10 @@ class SendWebhookHelper(object):
     def _send(self, url, data, headers):
         try:
             r = requests.post(
-                    url,
-                    data=data,
-                    headers=headers,
-                    timeout=self.timeout)
+                url,
+                data=data,
+                headers=headers,
+                timeout=self.timeout)
         except (requests.exceptions.RequestException,
                 socket.timeout,
                 ssl.SSLError):

http://git-wip-us.apache.org/repos/asf/allura/blob/a3620b4a/ForgeDiscussion/forgediscussion/tests/functional/test_forum.py
----------------------------------------------------------------------
diff --git a/ForgeDiscussion/forgediscussion/tests/functional/test_forum.py b/ForgeDiscussion/forgediscussion/tests/functional/test_forum.py
index 732c5c5..f557e6c 100644
--- a/ForgeDiscussion/forgediscussion/tests/functional/test_forum.py
+++ b/ForgeDiscussion/forgediscussion/tests/functional/test_forum.py
@@ -235,9 +235,8 @@ class TestForumAsync(TestController):
                           upload_files=[('file_info', 'test.asdfasdtxt',
                                          'This is a textfile')])
         r = self.app.post(url + 'attach',
-                          upload_files=[(
-                              'file_info', 'test1.txt', 'This is a textfile'),
-                              ('file_info', 'test2.txt', 'This is a textfile')])
+                          upload_files=[('file_info', 'test1.txt', 'This is a textfile'),
+                                        ('file_info', 'test2.txt', 'This is a textfile')])
         r = self.app.get(url)
         assert "test1.txt" in r
         assert "test2.txt" in r
@@ -373,11 +372,9 @@ class TestForum(TestController):
                 if field.has_key('name'):
                     params[field['name']] = field.has_key(
                         'value') and field['value'] or ''
-            params[f.find('textarea')['name']
-                   ] = '1st post in Zero Posts thread'
+            params[f.find('textarea')['name']] = '1st post in Zero Posts thread'
             params[f.find('select')['name']] = 'testforum'
-            params[f.find('input', {'style': 'width: 90%'})
-                   ['name']] = 'Test Zero Posts'
+            params[f.find('input', {'style': 'width: 90%'})['name']] = 'Test Zero Posts'
             r = self.app.post('/discussion/save_new_topic', params=params,
                               extra_environ=dict(username='*anonymous'),
                               status=302)
@@ -404,27 +401,23 @@ class TestForum(TestController):
         _post_pending()
         r = self.app.get('/discussion/testforum/moderate?status=pending')
         post_id = r.html.find('input', {'name': 'post-0._id'})['value']
-        r = self.app.post('/discussion/testforum/moderate/save_'
-                          'moderation', params={
-                              'post-0._id': post_id,
-                              'post-0.checked': 'on',
-                              'delete': 'Delete Marked'})
+        r = self.app.post('/discussion/testforum/moderate/save_moderation', params={
+            'post-0._id': post_id,
+            'post-0.checked': 'on',
+            'delete': 'Delete Marked'})
         _check()
 
     def test_posting(self):
         r = self.app.get('/discussion/create_topic/')
-        f = r.html.find(
-            'form', {'action': '/p/test/discussion/save_new_topic'})
+        f = r.html.find('form', {'action': '/p/test/discussion/save_new_topic'})
         params = dict()
         inputs = f.findAll('input')
         for field in inputs:
             if field.has_key('name'):
-                params[field['name']] = field.has_key(
-                    'value') and field['value'] or ''
+                params[field['name']] = field.has_key('value') and field['value'] or ''
         params[f.find('textarea')['name']] = 'This is a *test thread*'
         params[f.find('select')['name']] = 'testforum'
-        params[f.find('input', {'style': 'width: 90%'})
-               ['name']] = 'Test Thread'
+        params[f.find('input', {'style': 'width: 90%'})['name']] = 'Test Thread'
         r = self.app.post('/discussion/save_new_topic', params=params)
         r = self.app.get('/admin/discussion/forums')
         assert 'Message posted' in r
@@ -445,12 +438,10 @@ class TestForum(TestController):
         inputs = f.findAll('input')
         for field in inputs:
             if field.has_key('name'):
-                params[field['name']] = field.has_key(
-                    'value') and field['value'] or ''
+                params[field['name']] = field.has_key('value') and field['value'] or ''
         params[f.find('textarea')['name']] = 'Post text'
         params[f.find('select')['name']] = 'testforum'
-        params[f.find('input', {'style': 'width: 90%'})
-               ['name']] = "this is <h2> o'clock"
+        params[f.find('input', {'style': 'width: 90%'})['name']] = "this is <h2> o'clock"
         r = self.app.post('/discussion/save_new_topic', params=params)
         n = M.Notification.query.find(
             dict(subject="[test:discussion] this is <h2> o'clock")).first()
@@ -476,18 +467,15 @@ class TestForum(TestController):
         spam_checker.check.return_value = True
         self._set_anon_allowed()
         r = self.app.get('/discussion/create_topic/')
-        f = r.html.find(
-            'form', {'action': '/p/test/discussion/save_new_topic'})
+        f = r.html.find('form', {'action': '/p/test/discussion/save_new_topic'})
         params = dict()
         inputs = f.findAll('input')
         for field in inputs:
             if field.has_key('name'):
-                params[field['name']] = field.has_key(
-                    'value') and field['value'] or ''
+                params[field['name']] = field.has_key('value') and field['value'] or ''
         params[f.find('textarea')['name']] = 'Post content'
         params[f.find('select')['name']] = 'testforum'
-        params[f.find('input', {'style': 'width: 90%'})
-               ['name']] = 'Test Thread'
+        params[f.find('input', {'style': 'width: 90%'})['name']] = 'Test Thread'
         thread = self.app.post('/discussion/save_new_topic', params=params,
                                extra_environ=dict(username='*anonymous')).follow()
 
@@ -521,25 +509,21 @@ class TestForum(TestController):
         inputs = f.findAll('input')
         for field in inputs:
             if field.has_key('name'):
-                params[field['name']] = field.has_key(
-                    'value') and field['value'] or ''
+                params[field['name']] = field.has_key('value') and field['value'] or ''
         params[f.find('textarea')['name']] = 'aaa'
         params[f.find('select')['name']] = 'testforum'
         params[f.find('input', {'style': 'width: 90%'})['name']] = 'AAA'
-        thread = self.app.post(
-            '/discussion/save_new_topic', params=params).follow()
+        thread = self.app.post('/discussion/save_new_topic', params=params).follow()
         url = thread.request.url
 
         # test reply to post
-        f = thread.html.find(
-            'div', {'class': 'row reply_post_form'}).find('form')
+        f = thread.html.find('div', {'class': 'row reply_post_form'}).find('form')
         rep_url = f.get('action')
         params = dict()
         inputs = f.findAll('input')
         for field in inputs:
             if field.has_key('name'):
-                params[field['name']] = field.has_key(
-                    'value') and field['value'] or ''
+                params[field['name']] = field.has_key('value') and field['value'] or ''
         params[f.find('textarea')['name']] = 'bbb'
         thread = self.app.post(str(rep_url), params=params)
         thread = self.app.get(url)
@@ -555,15 +539,13 @@ class TestForum(TestController):
         # test edit post
         thread_url = thread.request.url
         r = thread
-        reply_form = r.html.find(
-            'div', {'class': 'edit_post_form reply'}).find('form')
+        reply_form = r.html.find('div', {'class': 'edit_post_form reply'}).find('form')
         post_link = str(reply_form['action'])
         params = dict()
         inputs = reply_form.findAll('input')
         for field in inputs:
             if field.has_key('name'):
-                params[field['name']] = field.has_key(
-                    'value') and field['value'] or ''
+                params[field['name']] = field.has_key('value') and field['value'] or ''
         params[reply_form.find('textarea')['name']] = 'zzz'
         self.app.post(post_link, params)
         r = self.app.get(thread_url)
@@ -573,19 +555,16 @@ class TestForum(TestController):
 
     def test_subscription_controls(self):
         r = self.app.get('/discussion/create_topic/')
-        f = r.html.find(
-            'form', {'action': '/p/test/discussion/save_new_topic'})
+        f = r.html.find('form', {'action': '/p/test/discussion/save_new_topic'})
         params = dict()
         inputs = f.findAll('input')
         for field in inputs:
             if field.has_key('name'):
-                params[field['name']] = field.has_key(
-                    'value') and field['value'] or ''
+                params[field['name']] = field.has_key('value') and field['value'] or ''
         params[f.find('textarea')['name']] = 'Post text'
         params[f.find('select')['name']] = 'testforum'
         params[f.find('input', {'style': 'width: 90%'})['name']] = 'Post subject'
-        thread = self.app.post(
-            '/discussion/save_new_topic', params=params).follow()
+        thread = self.app.post('/discussion/save_new_topic', params=params).follow()
         assert M.Notification.query.find(
             dict(subject='[test:discussion] Post subject')).count() == 1
         r = self.app.get('/discussion/testforum/')
@@ -595,19 +574,16 @@ class TestForum(TestController):
         inputs = f.findAll('input')
         for field in inputs:
             if field.has_key('name') and 'subscription' not in field['name']:
-                params[field['name']] = field.has_key(
-                    'value') and field['value'] or ''
+                params[field['name']] = field.has_key('value') and field['value'] or ''
         self.app.post(str(subscribe_url), params=params)
         self.app.get('/discussion/general/subscribe_to_forum?subscribe=True')
-        f = thread.html.find(
-            'div', {'class': 'row reply_post_form'}).find('form')
+        f = thread.html.find('div', {'class': 'row reply_post_form'}).find('form')
         rep_url = f.get('action')
         params = dict()
         inputs = f.findAll('input')
         for field in inputs:
             if field.has_key('name'):
-                params[field['name']] = field.has_key(
-                    'value') and field['value'] or ''
+                params[field['name']] = field.has_key('value') and field['value'] or ''
         params[f.find('textarea')['name']] = 'Reply 2'
         self.app.post(str(rep_url), params=params)
         assert M.Notification.query.find(
@@ -627,14 +603,12 @@ class TestForum(TestController):
 
     def test_thread_announcement(self):
         r = self.app.get('/discussion/create_topic/')
-        f = r.html.find(
-            'form', {'action': '/p/test/discussion/save_new_topic'})
+        f = r.html.find('form', {'action': '/p/test/discussion/save_new_topic'})
         params = dict()
         inputs = f.findAll('input')
         for field in inputs:
             if field.has_key('name'):
-                params[field['name']] = field.has_key(
-                    'value') and field['value'] or ''
+                params[field['name']] = field.has_key('value') and field['value'] or ''
         params[f.find('textarea')['name']] = 'aaa aaa'
         params[f.find('select')['name']] = 'testforum'
         params[f.find('input', {'style': 'width: 90%'})['name']] = 'AAAA'
@@ -682,14 +656,12 @@ class TestForum(TestController):
 
     def test_thread_sticky(self):
         r = self.app.get('/discussion/create_topic/')
-        f = r.html.find(
-            'form', {'action': '/p/test/discussion/save_new_topic'})
+        f = r.html.find('form', {'action': '/p/test/discussion/save_new_topic'})
         params = dict()
         inputs = f.findAll('input')
         for field in inputs:
             if field.has_key('name'):
-                params[field['name']] = field.has_key(
-                    'value') and field['value'] or ''
+                params[field['name']] = field.has_key('value') and field['value'] or ''
         params[f.find('textarea')['name']] = 'aaa aaa'
         params[f.find('select')['name']] = 'testforum'
         params[f.find('input', {'style': 'width: 90%'})['name']] = 'topic1'
@@ -698,14 +670,12 @@ class TestForum(TestController):
         tid1 = url1.rstrip('/').rsplit('/', 1)[-1]
 
         r = self.app.get('/discussion/create_topic/')
-        f = r.html.find(
-            'form', {'action': '/p/test/discussion/save_new_topic'})
+        f = r.html.find('form', {'action': '/p/test/discussion/save_new_topic'})
         params = dict()
         inputs = f.findAll('input')
         for field in inputs:
             if field.has_key('name'):
-                params[field['name']] = field.has_key(
-                    'value') and field['value'] or ''
+                params[field['name']] = field.has_key('value') and field['value'] or ''
         params[f.find('textarea')['name']] = 'aaa aaa'
         params[f.find('select')['name']] = 'testforum'
         params[f.find('input', {'style': 'width: 90%'})['name']] = 'topic2'
@@ -745,20 +715,18 @@ class TestForum(TestController):
         r = self.app.get('/discussion/testforum/')
         rows = self.get_table_rows(r, 'forum_threads')
         assert_equal(len(rows), 2)
-        #assert 'topic2' in str(rows[0])
-        #assert 'topic1' in str(rows[1])
+        # assert 'topic2' in str(rows[0])
+        # assert 'topic1' in str(rows[1])
 
     def test_move_thread(self):
         # make the topic
         r = self.app.get('/discussion/create_topic/')
-        f = r.html.find(
-            'form', {'action': '/p/test/discussion/save_new_topic'})
+        f = r.html.find('form', {'action': '/p/test/discussion/save_new_topic'})
         params = dict()
         inputs = f.findAll('input')
         for field in inputs:
             if field.has_key('name'):
-                params[field['name']] = field.has_key(
-                    'value') and field['value'] or ''
+                params[field['name']] = field.has_key('value') and field['value'] or ''
         params[f.find('textarea')['name']] = 'aaa aaa'
         params[f.find('select')['name']] = 'testforum'
         params[f.find('input', {'style': 'width: 90%'})['name']] = 'topic1'
@@ -773,8 +741,7 @@ class TestForum(TestController):
         inputs = f.findAll('input')
         for field in inputs:
             if field.has_key('name'):
-                params[field['name']] = field.has_key(
-                    'value') and field['value'] or ''
+                params[field['name']] = field.has_key('value') and field['value'] or ''
         params[f.find('textarea')['name']] = 'bbb'
         thread = self.app.post(str(rep_url), params=params)
         thread = self.app.get(url)
@@ -800,19 +767,16 @@ class TestForum(TestController):
         assert '<a href="/p/test/discussion/markdown_syntax"><span>Formatting
Help</span></a>' in sidebarmenu
         assert '<a href="flag_as_spam" class="sidebar_thread_spam"><b data-icon="^"
class="ico ico-flag"></b> <span>Mark as Spam</span></a>' not in
sidebarmenu
         r = self.app.get('/discussion/create_topic/')
-        f = r.html.find(
-            'form', {'action': '/p/test/discussion/save_new_topic'})
+        f = r.html.find('form', {'action': '/p/test/discussion/save_new_topic'})
         params = dict()
         inputs = f.findAll('input')
         for field in inputs:
             if field.has_key('name'):
-                params[field['name']] = field.has_key(
-                    'value') and field['value'] or ''
+                params[field['name']] = field.has_key('value') and field['value'] or ''
         params[f.find('textarea')['name']] = 'aaa'
         params[f.find('select')['name']] = 'testforum'
         params[f.find('input', {'style': 'width: 90%'})['name']] = 'AAA'
-        thread = self.app.post(
-            '/discussion/save_new_topic', params=params).follow()
+        thread = self.app.post('/discussion/save_new_topic', params=params).follow()
         thread_sidebarmenu = str(thread.html.find('div', {'id': 'sidebar'}))
         assert '<a href="flag_as_spam" class="sidebar_thread_spam"><b data-icon="^"
class="ico ico-flag"></b> <span>Mark as Spam</span></a>' in thread_sidebarmenu
 
@@ -825,14 +789,12 @@ class TestForum(TestController):
         assert '<a href="/p/test/discussion/markdown_syntax"><span>Formatting
Help</span></a>' in sidebarmenu
         assert '<a href="flag_as_spam" class="sidebar_thread_spam"><b data-icon="^"
class="ico ico-flag"></b> <span>Mark as Spam</span></a>' not in
sidebarmenu
         r = self.app.get('/discussion/create_topic/')
-        f = r.html.find(
-            'form', {'action': '/p/test/discussion/save_new_topic'})
+        f = r.html.find('form', {'action': '/p/test/discussion/save_new_topic'})
         params = dict()
         inputs = f.findAll('input')
         for field in inputs:
             if field.has_key('name'):
-                params[field['name']] = field.has_key(
-                    'value') and field['value'] or ''
+                params[field['name']] = field.has_key('value') and field['value'] or ''
         params[f.find('textarea')['name']] = 'aaa'
         params[f.find('select')['name']] = 'testforum'
         params[f.find('input', {'style': 'width: 90%'})['name']] = 'AAA'
@@ -862,8 +824,7 @@ class TestForum(TestController):
         r.forms[1].submit()
         r = self.app.get('/admin/discussion/forums')
         assert u'téstforum'.encode('utf-8') in r
-        r = self.app.get(
-            u'/p/test/discussion/create_topic/téstforum/'.encode('utf-8'))
+        r = self.app.get(u'/p/test/discussion/create_topic/téstforum/'.encode('utf-8'))
         assert u'<option value="téstforum" selected>Tést Forum</option>' in
r
 
 
@@ -876,24 +837,27 @@ class TestForumStats(TestController):
     def test_stats_data(self, aggregate):
         # partial data, some days are implicit 0
         aggregate.return_value = {'result': [
-            {"_id": {
-                "year": 2013,
-                "month": 1,
-                "day": 2},
-             "posts": 3
-             },
-            {"_id": {
-                "year": 2013,
-                "month": 1,
-                "day": 3},
-             "posts": 5
-             },
-            {"_id": {
-                "year": 2013,
-                "month": 1,
-                "day": 5},
-             "posts": 2
-             },
+            {
+                "_id": {
+                    "year": 2013,
+                    "month": 1,
+                    "day": 2},
+                "posts": 3
+            },
+            {
+                "_id": {
+                    "year": 2013,
+                    "month": 1,
+                    "day": 3},
+                "posts": 5
+            },
+            {
+                "_id": {
+                    "year": 2013,
+                    "month": 1,
+                    "day": 5},
+                "posts": 2
+            },
         ]}
         r = self.app.get(
             '/discussion/stats_data?begin=2013-01-01&end=2013-01-06')


Mime
View raw message