-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] validate number before subscription request
check that the belgian national registry number is valid before validating the subscription request, to avoid creating and posting the capital release request and then having it rolled back.
- Loading branch information
Showing
2 changed files
with
47 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,19 @@ | |
# Robin Keunen <[email protected]> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
|
||
from unittest import mock | ||
|
||
from odoo.exceptions import UserError, ValidationError | ||
from odoo.tests.common import TransactionCase | ||
|
||
from odoo.addons.cooperator.tests.cooperator_test_mixin import CooperatorTestMixin | ||
|
||
NATIONAL_NUMBER = 90010100123 | ||
|
||
account_move_action_post = ( | ||
"odoo.addons.account.models.account_move.AccountMove.action_post" | ||
) | ||
|
||
|
||
class TestCooperatorNationalNumber(TransactionCase, CooperatorTestMixin): | ||
@classmethod | ||
|
@@ -73,6 +79,27 @@ def test_no_national_number_provided(self): | |
with self.assertRaises(UserError): | ||
subscription_request.validate_subscription_request() | ||
|
||
@mock.patch(account_move_action_post) | ||
def test_invalid_national_number_provided(self, account_move_action_post_mock): | ||
""" | ||
Providing an invalid national number should raise a validation error. | ||
""" | ||
self.set_national_number_required() | ||
vals = self.get_dummy_subscription_requests_vals() | ||
subscription_request = self.env["subscription.request"].create(vals) | ||
subscription_request.national_number = "42" | ||
with self.assertRaises(ValidationError): | ||
subscription_request.validate_subscription_request() | ||
# no capital release requests should be created or posted | ||
capital_release_requests = self.env["account.move"].search( | ||
[("subscription_request", "=", subscription_request.id)] | ||
) | ||
self.assertFalse(capital_release_requests) | ||
# mocking account.move.create() would be better, but if it is called, | ||
# the error is confusing: psycopg2.ProgrammingError: can't adapt type | ||
# 'MagicMock' | ||
account_move_action_post_mock.assert_not_called() | ||
|
||
def test_national_number_provided_not_required(self): | ||
"""Expect no error when a number is given but not required.""" | ||
vals = self.get_dummy_subscription_requests_vals() | ||
|