You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by ke...@apache.org on 2020/06/03 16:05:25 UTC

[allura] 03/12: [#8361] test_admin fixes; MaxBytesValidator should not convert

This is an automated email from the ASF dual-hosted git repository.

kentontaylor pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git

commit 34e0aa07200307806fa230668ba767411f2482e1
Author: Dave Brondsema <da...@brondsema.net>
AuthorDate: Mon May 11 18:11:37 2020 -0400

    [#8361] test_admin fixes; MaxBytesValidator should not convert
---
 Allura/allura/lib/validators.py              |  4 ++--
 Allura/allura/tests/decorators.py            | 14 +++++++++----
 Allura/allura/tests/functional/test_admin.py | 31 ++++++++++++++--------------
 Allura/allura/tests/functional/test_auth.py  |  4 ++--
 4 files changed, 30 insertions(+), 23 deletions(-)

diff --git a/Allura/allura/lib/validators.py b/Allura/allura/lib/validators.py
index cd29024..f84ec5a 100644
--- a/Allura/allura/lib/validators.py
+++ b/Allura/allura/lib/validators.py
@@ -117,8 +117,8 @@ class MaxBytesValidator(fev.FancyValidator):
     max = 255
 
     def _to_python(self, value, state):
-        value = h.really_unicode(value or '').encode('utf-8')
-        if len(value) > self.max:
+        value_bytes = h.really_unicode(value or '').encode('utf-8')
+        if len(value_bytes) > self.max:
             raise fe.Invalid("Please enter a value less than %s bytes long." %
                              self.max, value, state)
         return value
diff --git a/Allura/allura/tests/decorators.py b/Allura/allura/tests/decorators.py
index 647674f..0a48ae7 100644
--- a/Allura/allura/tests/decorators.py
+++ b/Allura/allura/tests/decorators.py
@@ -173,11 +173,17 @@ def audits(*messages, **kwargs):
         preamble = '(Done by user: {}\n)?IP Address: {}\nUser-Agent: {}\n'.format(actor, ip_addr, user_agent)
     else:
         preamble = ''
+
     for message in messages:
-        assert M.AuditLog.query.find(dict(message=re.compile(preamble + message))).count(), \
-            'Could not find "%s"%s' % (message,
-                                       '\nYou may need to escape the regex chars in the text you are matching'
-                                       if message != re.escape(message) else '')
+        found = M.AuditLog.query.find(dict(message=re.compile(preamble + message))).count()
+        if not found:
+            hints = ''
+            all = M.AuditLog.query.find().all()
+            if len(all) < 10:
+                hints += '\nin these AuditLog messages:\n\t' + '\n\t'.join(a.message for a in all)
+            if message != re.escape(message):
+                hints += '\nYou may need to escape the regex chars in the text you are matching'
+            raise AssertionError('Could not find "%s"%s' % (message, hints))
 
 
 @contextlib.contextmanager
diff --git a/Allura/allura/tests/functional/test_admin.py b/Allura/allura/tests/functional/test_admin.py
index 15f862e..b02294b 100644
--- a/Allura/allura/tests/functional/test_admin.py
+++ b/Allura/allura/tests/functional/test_admin.py
@@ -20,8 +20,6 @@ from __future__ import unicode_literals
 from __future__ import absolute_import
 import os
 from datetime import datetime
-
-import allura
 import pkg_resources
 from io import BytesIO
 import logging
@@ -34,7 +32,9 @@ from ming.orm.ormsession import ThreadLocalORMSession
 from tg import expose
 from tg import tmpl_context as c, app_globals as g
 import mock
+import six
 
+import allura
 from allura.tests import TestController
 from allura.tests import decorators as td
 from allura.tests.decorators import audits, out_audits
@@ -59,12 +59,13 @@ class TestProjectAdmin(TestController):
                 'change summary to Milkshakes are for crazy monkeys',
                 'change project name to My Test Project',
                 'change short description to (\u00bf A Test Project \?){45}'):
-            self.app.post('/admin/update', status=302, params=dict(
+            r = self.app.post('/admin/update', params=dict(
                 name='My Test Project',
                 shortname='test',
                 summary='Milkshakes are for crazy monkeys',
                 short_description=('\u00bf A Test Project ?' * 45).encode('utf-8'),
                 labels='aaa,bbb'))
+            assert r.status_int == 302, (r.status, r.html.select('.error,.fielderror'))
         r = self.app.get('/admin/overview')
         assert b'A Test Project ?\xc2\xbf A' in r.body
         assert 'Test Subproject' not in r
@@ -168,7 +169,7 @@ class TestProjectAdmin(TestController):
     def test_features(self):
         proj = M.Project.query.get(shortname='test')
         assert_equals(proj.features, [])
-        with audits("change project features to \[u'One', u'Two'\]"):
+        with audits("change project features to \[{u}'One', {u}'Two'\]".format(u='u' if six.PY2 else '')):
             resp = self.app.post('/admin/update', params={
                 'features-0.feature': 'One',
                 'features-1.feature': '  ',
@@ -838,10 +839,10 @@ class TestProjectAdmin(TestController):
         dev_holder = r.html.find('table', {'id': 'usergroup_admin'}).findAll('tr')[2]
         mem_holder = r.html.find('table', {'id': 'usergroup_admin'}).findAll('tr')[3]
         mem_id = mem_holder['data-group']
-        # neither group has update permission
-        assert dev_holder.findAll('ul')[1].findAll('li')[2]['class'] == ["no"]
-        assert mem_holder.findAll('ul')[1].findAll('li')[2]['class'] == ["no"]
-        # add update permission to Member
+        # neither group has create permission
+        assert dev_holder.select_one('li[data-permission=create]')['class'] == ["no"]
+        assert mem_holder.select_one('li[data-permission=create]')['class'] == ["no"]
+        # add create permission to Member
         r = self.app.post('/admin/groups/change_perm', params={
             'role_id': mem_id,
             'permission': 'create',
@@ -849,10 +850,10 @@ class TestProjectAdmin(TestController):
         r = self.app.get('/admin/groups/')
         dev_holder = r.html.find('table', {'id': 'usergroup_admin'}).findAll('tr')[2]
         mem_holder = r.html.find('table', {'id': 'usergroup_admin'}).findAll('tr')[3]
-        # Member now has update permission
-        assert mem_holder.findAll('ul')[1].findAll('li')[2]['class'] == ["yes"]
-        # Developer has inherited update permission from Member
-        assert dev_holder.findAll('ul')[1].findAll('li')[2]['class'] == ["inherit"]
+        # Member now has create permission
+        assert mem_holder.select_one('li[data-permission=create]')['class'] == ["yes"]
+        # Developer has inherited create permission from Member
+        assert dev_holder.select_one('li[data-permission=create]')['class'] == ["inherit"]
         # remove update permission from Member
         r = self.app.post('/admin/groups/change_perm', params={
             'role_id': mem_id,
@@ -861,9 +862,9 @@ class TestProjectAdmin(TestController):
         r = self.app.get('/admin/groups/')
         dev_holder = r.html.find('table', {'id': 'usergroup_admin'}).findAll('tr')[2]
         mem_holder = r.html.find('table', {'id': 'usergroup_admin'}).findAll('tr')[3]
-        # neither group has update permission
-        assert dev_holder.findAll('ul')[1].findAll('li')[2]['class'] == ["no"]
-        assert mem_holder.findAll('ul')[1].findAll('li')[2]['class'] == ["no"]
+        # neither group has create permission
+        assert dev_holder.select_one('li[data-permission=create]')['class'] == ["no"]
+        assert mem_holder.select_one('li[data-permission=create]')['class'] == ["no"]
 
     def test_permission_inherit(self):
         r = self.app.get('/admin/groups/')
diff --git a/Allura/allura/tests/functional/test_auth.py b/Allura/allura/tests/functional/test_auth.py
index c85ca4a..c7dd677 100644
--- a/Allura/allura/tests/functional/test_auth.py
+++ b/Allura/allura/tests/functional/test_auth.py
@@ -882,9 +882,9 @@ class TestAuth(TestController):
         field_name = None
         for k, v in six.iteritems(form.fields):
             if subscribed:
-                check = c and v[0].value == 'on'
+                check = v and v[0].value == 'on'
             else:
-                check = c and v[0].value != 'on'
+                check = v and v[0].value != 'on'
             if k and k.endswith('.subscribed') and check:
                 field_name = k.replace('.subscribed', '')
         assert field_name, "Can't find unsubscribed tool for user"