PEP8: add spaces after operators
[nivanova/samba-autobuild/.git] / python / samba / tests / tdb_util.py
1 # Unix SMB/CIFS implementation.
2 # Copyright (C) Lumir Balhar <lbalhar@redhat.com> 2017
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 #
17
18 import samba.tests
19 from samba import ldb, Ldb
20 from samba.tdb_util import tdb_copy
21 import os
22
23
24 class TDBUtilTests(samba.tests.TestCaseInTempDir):
25
26     def setUp(self):
27         super(TDBUtilTests, self).setUp()
28
29     def test_tdb_copy(self):
30         src_ldb_file = os.path.join(self.tempdir, "source.ldb")
31         dst_ldb_file = os.path.join(self.tempdir, "destination.ldb")
32
33         # Create LDB source file with some content
34         src_ldb = Ldb(src_ldb_file)
35         src_ldb.add({"dn": "f=dc", "b": "bla"})
36
37         # Copy source file to destination file and check return status
38         self.assertIsNone(tdb_copy(src_ldb_file, dst_ldb_file))
39
40         # Load copied file as LDB object
41         dst_ldb = Ldb(dst_ldb_file)
42
43         # Copmare contents of files
44         self.assertEqual(
45             src_ldb.searchone(basedn=ldb.Dn(src_ldb, "f=dc"), attribute="b"),
46             dst_ldb.searchone(basedn=ldb.Dn(dst_ldb, "f=dc"), attribute="b")
47         )
48
49         # Clean up
50         del src_ldb
51         del dst_ldb
52         os.unlink(src_ldb_file)
53         os.unlink(dst_ldb_file)