Files
odoo_source/addons/document/test/document_test2.yml
T
Goffin Simon 0fd773a486 [IMP] Cleanup and refactoring of exception handling
Unify and refactor exception handling in framework and addons.

The generic `except_osv` is now deprecated, and replaced by more specialized exception subtypes:
 - `UserError` (renamed from Warning, as it conflicts with the built-in `Warning`) raised when a non-technical error occurs during a business operation. It could be a missing information in the data provided by the user, or a misconfiguration.
 - `AccessError`: raised when any operation is denied because the user conducting it does not have the required access rights.
 - `AccessDenied`: raised when an operation that requires authenticated access is attempted via an unauthenticated request.
 - `MissingError`: raised when an operation is attempted on a record that does not exist.
 - `ValidationError`: raised when an operation violates a SQL or Python constraint.
 - All other exceptions are internal errors due to a system problem or bug, and raised untouched to the client-side, which should display a traceback.

All exceptions take a single message argument.

The `test_exceptions` module has been updated to showcase both new and old (deprecated) exceptions.

A great many old `except_osv` had a useless title with "Error!" or "Warning", those have been removed, as this is handled by the client-side widget that displays the messages.

This commit introduces a more consistent policy for logging errors and warnings:
 - All messages that do not require administrator attention should be logged at INFO level or lower. This includes all errors that are notified to the user in a friendly manner, even for access right problems or validation errors during business operations.
 - All messages that indicate a likely misconfiguration or malicious use by the users should be logged at WARNING level, as they typically require administrator attention.
 - All other unhandled internal errors cannot typically be handled by the user and should be logged at ERROR or higher level, as they require immediate administrator attention.
2015-01-16 17:15:18 +01:00

89 lines
2.9 KiB
YAML

-
I create a "Testing" folder where all the test data will go.
-
!record {model: document.directory, id: dir_tests }:
name: 'Testing (will be deleted!)'
parent_id: dir_root
-
I create an attachment into the root folder (w. empty fields, test that
defaults work)
-
!record {model: ir.attachment, id: file_test1 }:
name: Test file.txt
-
I delete the attachment from the root folder
-
!python {model: ir.attachment}: |
self.unlink(cr, uid, [ref('file_test1')])
-
I create an attachment into the Testing folder.
-
!record {model: ir.attachment, id: file_test2 }:
name: Test file 2
parent_id: dir_tests
-
I update the attachment with data, namely "abcd"
-
!record {model: ir.attachment, id: file_test2 }:
datas: "YWJjZA==\n"
-
I test that the datas of the attachment are correct
-
!assert {model: ir.attachment, id: file_test2 }:
- datas == "YWJjZA==\n"
- file_size == 4
-
I rename the attachment.
-
!record {model: ir.attachment, id: file_test2 }:
name: Test renamed 2
-
I search the testing folder for attachments.
-
!python {model: ir.attachment}: |
ids = self.search(cr, uid, [('parent_id.name','=', 'Testing (will be deleted!)'), ('name','=','Test renamed 2')])
assert ids == [ ref("file_test2") ], ids
-
I create an attachment to a 3rd resource, eg. a res.country
-
!record {model: ir.attachment, id: attach_3rd }:
name: 'Country attachment.txt'
parent_id: dir_tests
datas: "Q291bnRyeSBhdHRhY2htZW50IGNvbnRlbnQ=\n"
res_model: res.country
res_id: !eval ref("base.za")
-
I search for the res.country attachment
-
!python {model: ir.attachment}: |
ids = self.search(cr, uid, [('res_model', '=', 'res.country'), ('res_id', '=', ref("base.za"))])
assert ids == [ ref("attach_3rd")], ids
-
I test that I can't create duplicate directories (even when duplicates are hidden by a record rule)
-
!python {model: document.directory}: |
duplicate_detected = False
from openerp.osv.osv import except_osv
try:
demo_uid = ref('base.user_demo')
dir_vals = {
'name': 'Testing (will be deleted!)',
'parent_id': ref('document.dir_root')
}
new_dir_id = self.create(cr, demo_uid, dir_vals, context=None)
self.unlink(cr, uid, [new_dir_id], context=None)
except except_osv, e:
duplicate_detected = e.name == u'Directory name must be unique!'
assert duplicate_detected is True, 'Failed to detect duplicate directory'
-
I delete the attachments
-
!python {model: ir.attachment}: |
self.unlink(cr, uid, [ref('file_test2')])
self.unlink(cr, uid, [ref('attach_3rd')])
-
I delete the tests folder
-
!python {model: document.directory}: |
self.unlink(cr, uid, [ref('dir_tests')])