Commit 66e967f6 authored by Julien Cristau's avatar Julien Cristau
Browse files

[hooks/integrity] kill CheckUniqueHook

It's the backend's job.

The noticeable consequence (as can be seen in tests updated here) is that
error message are a bit less user-friendly.
parent eedf0684533c
......@@ -244,25 +244,6 @@ class CheckAttributeConstraintHook(IntegrityHook):
(self.entity.eid, attr, None, constraints))
class CheckUniqueHook(IntegrityHook):
__regid__ = 'checkunique'
events = ('before_add_entity', 'before_update_entity')
def __call__(self):
entity = self.entity
eschema = entity.e_schema
for attr, val in entity.cw_edited.items():
if eschema.subjrels[attr].final and eschema.has_unique_values(attr):
if val is None:
continue
rql = '%s X WHERE X %s %%(val)s' % (entity.e_schema, attr)
rset = self._cw.execute(rql, {'val': val})
if rset and rset[0][0] != entity.eid:
msg = _('the value "%s" is already used, use another one')
raise validation_error(entity, {(attr, 'subject'): msg},
(val,))
class DontRemoveOwnersGroupHook(IntegrityHook):
"""delete the composed of a composite relation when this relation is deleted
"""
......
# -*- coding: utf-8 -*-
# copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# copyright 2003-2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
# This file is part of CubicWeb.
......@@ -27,7 +27,8 @@ from datetime import datetime
from six import text_type
from pytz import utc
from cubicweb import ValidationError, AuthenticationError, BadConnectionId
from cubicweb import ValidationError
from cubicweb.devtools.testlib import CubicWebTC
......@@ -213,7 +214,9 @@ class SchemaHooksTC(CubicWebTC):
ex = cm.exception
ex.translate(text_type)
self.assertIsInstance(ex.entity, int)
self.assertEqual(ex.errors, {'login-subject': 'the value "admin" is already used, use another one'})
self.assertEqual(ex.errors,
{'': u'some relations violate a unicity constraint',
'login': u'login is part of violated unicity constraint'})
if __name__ == '__main__':
......
......@@ -241,8 +241,11 @@ class ApplicationTC(CubicWebTC):
self.assertIsInstance(forminfo['eidmap']['X'], int)
self.assertIsInstance(forminfo['eidmap']['Y'], int)
self.assertEqual(forminfo['error'].entity, forminfo['eidmap']['X'])
self.assertEqual(forminfo['error'].errors,
{'login-subject': u'the value "admin" is already used, use another one'})
expected_errors = {
'': u'some relations violate a unicity constraint',
'login': u'login is part of violated unicity constraint',
}
self.assertEqual(forminfo['error'].errors, expected_errors)
self.assertEqual(forminfo['values'], req.form)
def _edit_parent(self, dir_eid, parent_eid, role='subject',
......
......@@ -96,9 +96,12 @@ class EditControllerTC(CubicWebTC):
}
with self.assertRaises(ValidationError) as cm:
self.ctrl_publish(req)
cm.exception.translate(text_type)
self.assertEqual({'login-subject': 'the value "admin" is already used, use another one'},
cm.exception.errors)
cm.exception.translate(text_type)
expected = {
'': u'some relations violate a unicity constraint',
'login': u'login is part of violated unicity constraint',
}
self.assertEqual(cm.exception.errors, expected)
def test_simultaneous_edition_only_one_commit(self):
""" Allow two simultaneous edit view of the same entity as long as only one commits
......
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