Commit 47f26c68 authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

flake8 fixes

parent ea5d18e574cd
# pylint: disable-msg=W0622
"""cubicweb-registration application packaging information"""
from os import listdir as _listdir
from os.path import join, isdir
from glob import glob
modname = 'registration'
distname = 'cubicweb-registration'
......@@ -17,33 +21,34 @@ classifiers = [
'Framework :: CubicWeb',
'Programming Language :: Python',
'Programming Language :: JavaScript',
]
]
__depends__ = {'cubicweb': '>= 3.19.0',
'Pillow': None,
'pycrypto': None,
}
__depends__ = {
'cubicweb': '>= 3.19.0',
'Pillow': None,
'pycrypto': None,
}
# packaging ###
from os import listdir as _listdir
from os.path import join, isdir
from glob import glob
THIS_CUBE_DIR = join('share', 'cubicweb', 'cubes', modname)
def listdir(dirpath):
return [join(dirpath, fname) for fname in _listdir(dirpath)
if fname[0] != '.' and not fname.endswith('.pyc')
and not fname.endswith('~')
and not isdir(join(dirpath, fname))]
data_files = [
# common files
[THIS_CUBE_DIR, [fname for fname in glob('*.py') if fname != 'setup.py']],
]
]
# check for possible extended cube layout
for dirname in ('entities', 'views', 'sobjects', 'hooks', 'schema', 'data', 'i18n', 'migration', 'wdoc'):
for dirname in ('entities', 'views', 'sobjects', 'hooks', 'schema', 'data',
'i18n', 'migration', 'wdoc'):
if isdir(dirname):
data_files.append([join(THIS_CUBE_DIR, dirname), listdir(dirname)])
# Note: here, you'll need to add subdirectories if you want
......
options = (
('registration-cypher-seed',
{'type' : 'string',
{'type': 'string',
'default': u"this is my dummy registration cypher seed",
'help': 'seed used to cypher registration data in confirmation email link',
'group': 'registration', 'level': 2,
}),
)
)
from logilab.common.testlib import unittest_main
from cubicweb.devtools.testlib import AutomaticWebTest
class AutomaticWebTest(AutomaticWebTest):
def to_test_etypes(self):
......@@ -9,9 +10,6 @@ class AutomaticWebTest(AutomaticWebTest):
def list_startup_views(self):
return ('registration',)
if __name__ == '__main__':
unittest_main()
if __name__ == '__main__':
unittest_main()
import re, cgi, urlparse
import cgi
import re
import urlparse
from contextlib import contextmanager
from cubicweb import ValidationError
from cubicweb.crypto import encrypt, decrypt
from cubicweb.web import Redirect
from cubicweb.devtools.testlib import MAILBOX, CubicWebTC
from cubes.registration.views import RegistrationSendMailController
class RegistrationTC(CubicWebTC):
......@@ -53,7 +51,7 @@ class RegistrationTC(CubicWebTC):
data = self.data.copy()
for key in skipkeys:
data.pop(key, None)
if not '__errorurl' in skipkeys:
if '__errorurl' not in skipkeys:
data['__errorurl'] = 'registration'
return data
......@@ -76,7 +74,10 @@ class RegistrationTC(CubicWebTC):
req.session.data['captcha'] = self.captcha_value
path, params = self.expect_redirect_handle_request(req, 'registration_sendmail')
self.assertEqual(path, '')
self.assertMessageEqual(req, params, 'Your registration email has been sent. Follow instructions in there to activate your account.')
self.assertMessageEqual(
req, params,
'Your registration email has been sent. '
'Follow instructions in there to activate your account.')
# check email contains activation url...
URL_RE = re.compile('(%s[^.]+)$' % self.config['base-url'], re.M)
text = MAILBOX[-1].message.get_payload(decode=True)
......@@ -97,7 +98,6 @@ class RegistrationTC(CubicWebTC):
req.form = self._posted_form()
req.form[param] = val
req.session.data['captcha'] = self.captcha_value
#expected
self._check_error(req, 'registration_sendmail',
expected_formvalues=req.form,
expected_errors={param: msg})
......@@ -112,19 +112,20 @@ class RegistrationTC(CubicWebTC):
key = encrypt(data, self.config['registration-cypher-seed'])
req.form = {'key': key}
yield req
#self.vreg['controllers'].select('registration_confirm', req,
#appli=self.app)
def test_confirm_ok(self):
with self._confirm_req() as req:
path, params = self.expect_redirect_handle_request(req, 'registration_confirm')
self.assertEqual(path, '')
self.assertMessageEqual(req, params, 'Congratulations, your registration is complete. Welcome %(firstname-subject)s %(surname-subject)s !' % self.data)
self.assertMessageEqual(
req, params,
'Congratulations, your registration is complete. '
'Welcome %(firstname-subject)s %(surname-subject)s !' % self.data)
with self.admin_access.repo_cnx() as cnx:
rset = cnx.execute('Any U WHERE U login %(login)s, U firstname %(firstname)s, '
'U surname %(surname)s, U use_email M, M address %(email_address)s',
dict((k.replace('-subject', ''), v)
for k, v in self.data.items()))
'U surname %(surname)s, U use_email M, M address %(email_address)s',
dict((k.replace('-subject', ''), v)
for k, v in self.data.items()))
self.assertTrue(rset)
def test_confirm_failure_login_already_used(self):
......@@ -133,26 +134,31 @@ class RegistrationTC(CubicWebTC):
formvalues = self._posted_form('upassword-subject',
'upassword-subject-confirm')
formvalues['login-subject'] = 'admin'
self._check_error(req, 'registration_confirm',
expected_formvalues=formvalues,
expected_errors={'login-subject': 'the value "admin" is already used, use another one'})
self._check_error(
req, 'registration_confirm',
expected_formvalues=formvalues,
expected_errors={'login-subject':
'the value "admin" is already used, use another one'})
def test_confirm_failure_invalid_data(self):
with self._confirm_req('dummykey') as req:
self._check_error(req, 'registration_confirm', 'register',
expected_msg='Invalid registration data. Please try registering again.')
self._check_error(
req, 'registration_confirm', 'register',
expected_msg='Invalid registration data. Please try registering again.')
self._check_user_not_created()
def test_confirm_failure_email_already_used(self):
with self.admin_access.web_request() as req:
self.create_user(req, 'test')
req.execute('INSERT EmailAddress X: U use_email X, X address %(email_address)s '
'WHERE U login "test"', {'email_address': self.data['email_address-subject']})
'WHERE U login "test"',
{'email_address': self.data['email_address-subject']})
req.cnx.commit()
with self._confirm_req() as req:
req.form['__errorurl'] = 'registration'
self._check_user_not_created()
if __name__ == '__main__':
from logilab.common.testlib import unittest_main
unittest_main()
......@@ -5,9 +5,6 @@
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
"""
__docformat__ = "restructuredtext en"
from logilab.common.decorators import clear_cache
from yams.schema import role_name
......@@ -62,6 +59,7 @@ class RegistrationFormView(form.FormViewMixIn, StartupView):
form = self._cw.vreg['forms'].select('registration', self._cw)
form.render(w=self.w, display_progress_div=False)
class RegistrationSendMailController(controller.Controller):
__regid__ = 'registration_sendmail'
content = _(u'''
......@@ -88,7 +86,7 @@ See you soon on %(base_url)s !
confirmation check)
'''
form = self._cw.vreg['forms'].select('registration', self._cw)
form.formvalues = {} # init fields value cache
form.formvalues = {} # init fields value cache
data = {}
errors = {}
for field in form.fields:
......@@ -96,14 +94,14 @@ See you soon on %(base_url)s !
for field, value in field.process_posted(form):
if value is not None:
data[field.role_name()] = value
except ProcessFormError, exc:
except ProcessFormError as exc:
errors[field.role_name()] = unicode(exc)
if errors:
raise ValidationError(None, errors)
return data
def build_email(self, recipient, data):
activationurl = self.activation_url(data) # build url before modifying data
activationurl = self.activation_url(data) # build url before modifying data
data.setdefault(qname('firstname'), '')
data.setdefault(qname('surname'), '')
if not (data.get(qname('firstname')) or data.get(qname('surname'))):
......@@ -142,7 +140,7 @@ class RegistrationConfirmController(controller.Controller):
if self._cw.user.login == login:
# already logged in (e.g. regstration link replayed twice in the browser)
raise Redirect(self.success_redirect_url(self._cw.user.name()))
req.form = data # hijack for proper validation error handling
req.form = data # hijack for proper validation error handling
err_raised = False
try:
with self.appli.repo.internal_cnx() as cnx:
......@@ -189,11 +187,12 @@ class RegisterLink(basecomponents.HeaderComponent):
def render(self, w):
self._cw.add_css('cubicweb.pictograms.css')
w(u'<a class="logout icon-user-add" title="%s" href="%s"></a>' % (
self._cw._('i18n_register_user'), self._cw.build_url('register'), ))
self._cw._('i18n_register_user'), self._cw.build_url('register'), ))
## urls #######################################################################
# urls #########################################################################
class RegistrationSimpleReqRewriter(urlrewrite.SimpleReqRewriter):
rules = [
('/register', dict(vid='registration')),
]
]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment