~openerp-dev/openobject-server/trunk-missing-default-values-pza

« back to all changes in this revision

Viewing changes to openerp/tests/test_uninstall.py

  • Committer: Pooja Zankhariya (OpenERP)
  • Date: 2014-01-31 06:44:29 UTC
  • mfrom: (5013.1.35 trunk)
  • Revision ID: pza@tinyerp.com-20140131064429-0a1u9ax5cf3sslug
[MERGE]Sync with Trunk

Show diffs side-by-side

added added

removed removed

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