pytests: heed assertEquals deprecation warning en-masse
[amitay/samba.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 total_schedule, convert_schedule_to_repltimes
25
26 def ntdsconn_schedule(times):
27     if times is None:
28         return None
29     from samba.dcerpc import drsblobs
30     schedule = drsblobs.schedule()
31     schedule.size = 188
32     schedule.bandwidth = 0
33     schedule.numberOfSchedules = 1
34     header = drsblobs.scheduleHeader()
35     header.type = 0
36     header.offset = 20
37     schedule.headerArray = [header]
38     data = drsblobs.scheduleSlots()
39     data.slots = times
40     schedule.dataArray = [data]
41     return schedule
42
43
44 class GraphFunctionTests(samba.tests.TestCase):
45
46     def test_total_schedule(self):
47         schedule = [0x81] * 84
48         for schedule, total in (
49                 ([0x81] * 84, 168),
50                 ([0xff] * 84, 84 * 8),
51                 ([0xaa] * 84, 84 * 4),
52                 ([0x03, 0x33] * 42, 42 * 6),
53                 (list(range(7)) * 12, 12 * 9),
54                 (list(range(4)) * 21, 21 * 4)):
55             self.assertEqual(total_schedule(schedule), total)
56
57     def test_convert_schedule_to_repltimes(self):
58         for ntdsconn_times, repltimes in (
59                 ([0x01] * 168, [0x11] * 84),
60                 (None, [0x11] * 84),
61                 ([0x06] * 168, [0x66] * 84),
62                 ([0x03, 0xa] * 84, [0x3a] * 84),
63                 (list(range(7)) * 24,
64                  [0x01, 0x23, 0x45, 0x60, 0x12, 0x34, 0x56] * 12)):
65             schedule = ntdsconn_schedule(ntdsconn_times)
66             self.assertEqual(convert_schedule_to_repltimes(schedule),
67                               repltimes)