Commit 973ffdef authored by Jérome Perrin's avatar Jérome Perrin

accounting: Fix "Account Type must be set" constraint not always applying

This constraint had a TALES expression making it not apply on invalidated
accounts, but during the transition invalidated -> validated, when the account's
consistency is checked, the account is still in invalidated state, so that
check was ignored, making it possible for users to validate an account without
and account type.
parent e051c03e
Pipeline #14403 failed with stage
in 0 seconds
...@@ -267,9 +267,22 @@ class TestAccounts(AccountingTestCase): ...@@ -267,9 +267,22 @@ class TestAccounts(AccountingTestCase):
def test_AccountValidation(self): def test_AccountValidation(self):
# Accounts need an account_type category to be valid # Accounts need an account_type category to be valid
account = self.portal.account_module.newContent(portal_type='Account') account = self.portal.account_module.newContent(portal_type='Account')
self.assertEqual(1, len(account.checkConsistency())) self.assertEqual(
[str(m.getMessage()) for m in account.checkConsistency()],
['Account Type must be set'])
account.setAccountType('equity')
self.assertEqual([str(m.getMessage()) for m in account.checkConsistency()], [])
# non regression: this constraint is also properly verified during workflow
account.setAccountType(None)
with self.assertRaisesRegexp(ValidationFailed, 'Account Type must be set'):
self.portal.portal_workflow.doActionFor(account, 'validate_action')
account.setAccountType('equity') account.setAccountType('equity')
self.assertEqual(0, len(account.checkConsistency())) self.portal.portal_workflow.doActionFor(account, 'validate_action')
self.portal.portal_workflow.doActionFor(account, 'invalidate_action')
account.setAccountType(None)
with self.assertRaisesRegexp(ValidationFailed, 'Account Type must be set'):
self.portal.portal_workflow.doActionFor(account, 'validate_action')
def test_AccountWorkflow(self): def test_AccountWorkflow(self):
account = self.portal.account_module.newContent(portal_type='Account') account = self.portal.account_module.newContent(portal_type='Account')
......
...@@ -6,6 +6,18 @@ ...@@ -6,6 +6,18 @@
</pickle> </pickle>
<pickle> <pickle>
<dictionary> <dictionary>
<item>
<key> <string>_identity_criterion</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>_range_criterion</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item> <item>
<key> <string>constraint_base_category</string> </key> <key> <string>constraint_base_category</string> </key>
<value> <value>
...@@ -26,6 +38,18 @@ ...@@ -26,6 +38,18 @@
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>account_type_category_existence_constraint</string> </value> <value> <string>account_type_category_existence_constraint</string> </value>
</item> </item>
<item>
<key> <string>int_index</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>membership_criterion_category</string> </key>
<value>
<tuple/>
</value>
</item>
<item> <item>
<key> <string>message_category_not_set</string> </key> <key> <string>message_category_not_set</string> </key>
<value> <string>Account Type must be set</string> </value> <value> <string>Account Type must be set</string> </value>
...@@ -34,9 +58,23 @@ ...@@ -34,9 +58,23 @@
<key> <string>portal_type</string> </key> <key> <string>portal_type</string> </key>
<value> <string>Category Existence Constraint</string> </value> <value> <string>Category Existence Constraint</string> </value>
</item> </item>
<item>
<key> <string>string_index</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>test_method_id</string> </key>
<value>
<tuple/>
</value>
</item>
<item> <item>
<key> <string>test_tales_expression</string> </key> <key> <string>test_tales_expression</string> </key>
<value> <string>python: object.getValidationState() not in ("invalidated", "deleted")</string> </value> <value>
<none/>
</value>
</item> </item>
<item> <item>
<key> <string>use_acquisition</string> </key> <key> <string>use_acquisition</string> </key>
...@@ -45,4 +83,34 @@ ...@@ -45,4 +83,34 @@
</dictionary> </dictionary>
</pickle> </pickle>
</record> </record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData> </ZopeData>
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