PEP8: fix E302: expected 2 blank lines, found 1
[nivanova/samba-autobuild/.git] / python / samba / tests / samba_tool / forest.py
1 # Unix SMB/CIFS implementation.
2 # Copyright (C) William Brown <william@blackhats.net.au> 2018
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 os
19 import ldb
20 from samba.tests.samba_tool.base import SambaToolCmdTest
21
22
23 class ForestCmdTestCase(SambaToolCmdTest):
24     """Tests for samba-tool dsacl subcommands"""
25     samdb = None
26
27     def setUp(self):
28         super(ForestCmdTestCase, self).setUp()
29         self.samdb = self.getSamDB("-H", "ldap://%s" % os.environ["DC_SERVER"],
30                                    "-U%s%%%s" % (os.environ["DC_USERNAME"], os.environ["DC_PASSWORD"]))
31         self.domain_dn = self.samdb.domain_dn()
32
33     def tearDown(self):
34         super(ForestCmdTestCase, self).tearDown()
35         # Reset the values we might have changed.
36         ds_dn = "CN=Directory Service,CN=Windows NT,CN=Services,CN=Configuration"
37         m = ldb.Message()
38         m.dn = ldb.Dn(self.samdb, "%s,%s" % (ds_dn, self.domain_dn))
39         m['dsheuristics'] = ldb.MessageElement(
40             '0000000', ldb.FLAG_MOD_REPLACE, 'dsheuristics')
41
42         self.samdb.modify(m)
43
44     def test_display(self):
45         """Tests that we can display forest settings"""
46         (result, out, err) = self.runsublevelcmd("forest", ("directory_service",
47                                                             "show"),
48                                                  "-H", "ldap://%s" % os.environ["DC_SERVER"],
49                                                  "-U%s%%%s" % (os.environ["DC_USERNAME"],
50                                                                os.environ["DC_PASSWORD"]))
51
52         self.assertCmdSuccess(result, out, err)
53         self.assertEquals(err, "", "Shouldn't be any error messages")
54         self.assertIn("dsheuristics: <NO VALUE>", out)
55
56     def test_modify_dsheuristics(self):
57         """Test that we can modify the dsheuristics setting"""
58
59         (result, out, err) = self.runsublevelcmd("forest", ("directory_service",
60                                                             "dsheuristics"), "0000002",
61                                                  "-H", "ldap://%s" % os.environ["DC_SERVER"],
62                                                  "-U%s%%%s" % (os.environ["DC_USERNAME"],
63                                                                os.environ["DC_PASSWORD"]))
64
65         self.assertCmdSuccess(result, out, err)
66         self.assertEquals(err, "", "Shouldn't be any error messages")
67         self.assertIn("set dsheuristics: 0000002", out)