selftest: enable py3 for samba.tests.kcc.graph
[metze/samba/wip.git] / python / samba / tests / kcc / graph.py
1 # Unix SMB/CIFS implementation. Tests for kcc.graph routines
2 # Copyright (C) Andrew Bartlett 2015
3 #
4 # Written by Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 #
19
20 """Tests for samba.kcc.graph"""
21
22 import samba
23 import samba.tests
24 from samba.kcc.graph import *
25
26 import itertools
27
28
29 def ntdsconn_schedule(times):
30     if times is None:
31         return None
32     from samba.dcerpc import drsblobs
33     schedule = drsblobs.schedule()
34     schedule.size = 188
35     schedule.bandwidth = 0
36     schedule.numberOfSchedules = 1
37     header = drsblobs.scheduleHeader()
38     header.type = 0
39     header.offset = 20
40     schedule.headerArray = [header]
41     data = drsblobs.scheduleSlots()
42     data.slots = times
43     schedule.dataArray = [data]
44     return schedule
45
46
47 class GraphFunctionTests(samba.tests.TestCase):
48
49     def test_total_schedule(self):
50         schedule = [0x81] * 84
51         for schedule, total in (
52                 ([0x81] * 84, 168),
53                 ([0xff] * 84, 84 * 8),
54                 ([0xaa] * 84, 84 * 4),
55                 ([0x03, 0x33] * 42, 42 * 6),
56                 (list(range(7)) * 12, 12 * 9),
57                 (list(range(4)) * 21, 21 * 4)):
58             self.assertEquals(total_schedule(schedule), total)
59
60     def test_convert_schedule_to_repltimes(self):
61         for ntdsconn_times, repltimes in (
62                 ([0x01] * 168, [0x11] * 84),
63                 (None, [0x11] * 84),
64                 ([0x06] * 168, [0x66] * 84),
65                 ([0x03, 0xa] * 84, [0x3a] * 84),
66                 (list(range(7)) * 24,
67                  [0x01, 0x23, 0x45, 0x60, 0x12, 0x34, 0x56] * 12)):
68             schedule = ntdsconn_schedule(ntdsconn_times)
69             self.assertEquals(convert_schedule_to_repltimes(schedule),
70                               repltimes)