-
Notifications
You must be signed in to change notification settings - Fork 12
/
test_db.py
61 lines (46 loc) · 2.14 KB
/
test_db.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from . import BaseTestCase
from ..core import Client
import os
import os.path
import unittest
import time
import six
@unittest.skipUnless(os.environ.get('TEST_DB_SERVICE', False), 'requires DB service test enabled')
class Test_999_DB(BaseTestCase):
def setUp(self):
super(self.__class__, self).setUp()
self.client = Client(self.env.host, protocol=self.env.protocol, port=self.env.port)
def test_00_create_db(self):
# create database if it was not created yet
if self.env.dbname not in self.client.services.db.list_db():
self.client.services.db.create_db(self.env.super_password, self.env.dbname, demo=True, admin_password=self.env.password)
else:
raise unittest.SkipTest("database already creaated. no need to create it")
def test_10_to_dbname(self):
cl_db = self.client.login(self.env.dbname, 'admin', self.env.password)
from openerp_proxy.service.db import to_dbname
res = to_dbname(self.env.dbname)
self.assertEqual(res, self.env.dbname)
self.assertIsInstance(res, six.string_types)
res = to_dbname(cl_db)
self.assertEqual(res, self.env.dbname)
self.assertIsInstance(res, six.string_types)
# Test that value error is raise when unexpected value passed to
# function
with self.assertRaises(ValueError):
to_dbname(25)
def test_20_dump_drop_restore(self):
# dump db
dump_data = self.client.services.db.dump_db(self.env.super_password, self.env.dbname)
self.assertIsInstance(dump_data, bytes)
# drop it
self.client.services.db.drop_db(self.env.super_password, self.env.dbname)
self.assertNotIn(self.env.dbname, self.client.services.db)
# and try to restore it
self.client.services.db.restore_db(self.env.super_password, self.env.dbname, dump_data)
self.assertIn(self.env.dbname, self.client.services.db)
# check if objects were restored
time.sleep(2)
cl = self.client.login(self.env.dbname, self.env.user, self.env.password)
self.assertIsNotNone(cl.uid)
self.assertIsNotNone(cl.user)