[IMP]removed view editor from web to web addons.
[odoo/odoo.git] / openerp / tests / test_uninstall.py
1 # -*- coding: utf-8 -*-
2 # This assumes an existing but uninitialized database.
3 import psycopg2
4 import unittest2
5
6 import openerp
7 from openerp import SUPERUSER_ID
8 import common
9
10 DB = common.DB
11 ADMIN_USER_ID = common.ADMIN_USER_ID
12
13 def registry(model):
14     return openerp.modules.registry.RegistryManager.get(DB)[model]
15
16 def cursor():
17     return openerp.modules.registry.RegistryManager.get(DB).db.cursor()
18
19 def get_module(module_name):
20     registry = openerp.modules.registry.RegistryManager.get(DB)
21     return registry.get(module_name)
22
23 def reload_registry():
24     openerp.modules.registry.RegistryManager.new(
25         DB, update_module=True)
26
27 def search_registry(model_name, domain):
28     cr = cursor()
29     model = registry(model_name)
30     record_ids = model.search(cr, SUPERUSER_ID, domain, {})
31     cr.close()
32     return record_ids
33
34 def install_module(module_name):
35     ir_module_module = registry('ir.module.module')
36     cr = cursor()
37     module_ids = ir_module_module.search(cr, SUPERUSER_ID,
38         [('name', '=', module_name)], {})
39     assert len(module_ids) == 1
40     ir_module_module.button_install(cr, SUPERUSER_ID, module_ids, {})
41     cr.commit()
42     cr.close()
43     reload_registry()
44
45 def uninstall_module(module_name):
46     ir_module_module = registry('ir.module.module')
47     cr = cursor()
48     module_ids = ir_module_module.search(cr, SUPERUSER_ID,
49         [('name', '=', module_name)], {})
50     assert len(module_ids) == 1
51     ir_module_module.button_uninstall(cr, SUPERUSER_ID, module_ids, {})
52     cr.commit()
53     cr.close()
54     reload_registry()
55
56 class test_uninstall(unittest2.TestCase):
57     """
58     Test the install/uninstall of a test module. The module is available in
59     `openerp.tests` which should be present in the addons-path.
60     """
61
62     def test_01_install(self):
63         """ Check a few things showing the module is installed. """
64         install_module('test_uninstall')
65         assert get_module('test_uninstall.model')
66
67         assert search_registry('ir.model.data',
68             [('module', '=', 'test_uninstall')])
69
70         assert search_registry('ir.model.fields',
71             [('model', '=', 'test_uninstall.model')])
72
73     def test_02_uninstall(self):
74         """ Check a few things showing the module is uninstalled. """
75         uninstall_module('test_uninstall')
76         assert not get_module('test_uninstall.model')
77
78         assert not search_registry('ir.model.data',
79             [('module', '=', 'test_uninstall')])
80
81         assert not search_registry('ir.model.fields',
82             [('model', '=', 'test_uninstall.model')])
83
84
85
86 if __name__ == '__main__':
87     unittest2.main()
88
89
90 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: