python tests: fix format() strings for Python 2.6
[samba.git] / python / samba / tests / lsa_string.py
1 # Tests for lsa.String helpers in source4/librpc/ndr/py_lsa.c
2 #
3 # Copyright (C) Catalyst IT Ltd. 2017
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 #
18
19 from samba.tests import TestCase
20 from samba.dcerpc import lsa
21 from samba.ndr import ndr_pack, ndr_unpack
22 """
23 Tests for the C helper functions in source4/librpc/ndr/py_lsa.c
24 for samba.dcerpc.lsa.String
25 """
26
27
28 class LsaStringTests(TestCase):
29
30     def test_default_constructor(self):
31         s = lsa.String()
32         self.assertEqual(None, s.string)
33         self.assertEqual(0, s.size)
34         self.assertEqual(0, s.length)
35
36     def test_string_constructor(self):
37         CONTENT = "The content string"
38         s = lsa.String(CONTENT)
39         self.assertEqual(CONTENT, s.string)
40
41         # These should be zero, are set by ndr_pack and ndr_unpack
42         self.assertEqual(0, s.size)
43         self.assertEqual(0, s.length)
44
45     def test_string_constructor(self):
46         CONTENT = "The content string"
47         s = lsa.String(CONTENT)
48         self.assertEqual(CONTENT, s.string)
49
50         # These should be zero
51         self.assertEqual(0, s.size)
52         self.assertEqual(0, s.length)
53
54         packed = ndr_pack(s)
55         unpacked = ndr_unpack(lsa.String, packed)
56
57         # Original object should be unchanged
58         self.assertEqual(0, s.size)
59         self.assertEqual(0, s.length)
60
61         # But they should be correct in the unpacked object
62         self.assertEqual(36, unpacked.size)
63         self.assertEqual(36, unpacked.length)
64
65     def test_repr(self):
66         # test an empty string
67         self.assertEqual("lsaString(None)", repr(lsa.String()))
68         # and one with contents
69         self.assertEqual("lsaString('Hello world')",
70                          repr(lsa.String("Hello world")))
71
72     def test_to_string(self):
73         # test an empty string
74         self.assertEqual("", str(lsa.String()))
75         # and one with contents
76         self.assertEqual("Hello world",
77                          str(lsa.String("Hello world")))