summaryrefslogtreecommitdiff
path: root/source4/scripting/swig/torture/torture_ldb.py
blob: fe79f4f843b1d23318123338d286d5aebd5bba7e (plain)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/python
#
# A torture test for the Python Ldb bindings.  Also a short guide on
# how the API works.
#

from Ldb import *

# Helpers

def t(cond, msg):
    """Test a condition."""
    if not cond:
        raise RuntimeError('FAILED: %s' % msg)

#
# Torture LdbMessage
#

m = LdbMessage()

# Empty message

t(m.keys() == [], 'empty msg')
t(m.dn == None, 'empty dn')

t(m.sanity_check() == LDB_ERR_INVALID_DN_SYNTAX, 'sanity check')

# Test invalid dn

try:
    m.dn = 'invalid dn'
except LdbError, arg:
    if arg[0] != LDB_ERR_INVALID_DN_SYNTAX:
        raise
else:
    t(False, 'LdbError not raised')

# Test valid dn

m.dn = 'name=spotty'
t(m.dn == 'name=spotty', 'specified dn')

t(m.sanity_check() == LDB_SUCCESS, 'sanity check')

# Test some single-valued attributes

m['animal'] = 'dog'
m['name'] = 'spotty'

t(m.keys() == ['animal', 'name'], 'keys() test failed')
t(m.values() == [['dog'], ['spotty']], 'values() test failed')
t(m.items() == [('animal', ['dog']), ('name', ['spotty'])],
  'items() test failed')

t(m.sanity_check() == LDB_SUCCESS, 'sanity check')

m['animal'] = 'canine'
t(m['animal'] == ['canine'], 'replace value failed')

# Test a multi-valued attribute

names = ['spotty', 'foot']
m['name'] = names

t(m['name'] == names, 'multi-valued attr failed')

t(m.sanity_check() == LDB_SUCCESS, 'sanity check')

# Test non-string attributes

try:
    m['foo'] = 42
except TypeError:
    pass
else:
    t(False, 'TypeError not raised')

#
# Torture Ldb
#

l = Ldb('foo.ldb')