Update Samba build farm to new web site layout.
[build-farm.git] / buildfarm / tests / test_util.py
1 #!/usr/bin/python
2 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2010
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, write to the Free Software
16 #   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 import os
19 import tempfile
20 import testtools
21 import unittest
22
23 from buildfarm import util
24
25 class DhmTimeTests(unittest.TestCase):
26
27     def test_simple(self):
28         self.assertEquals("0s", util.dhm_time(0))
29         self.assertEquals("1m", util.dhm_time(61))
30         self.assertEquals("-", util.dhm_time(-20))
31         self.assertEquals("1d 3h 1m", util.dhm_time(97265))
32         self.assertEquals("3h 1m", util.dhm_time(10865))
33
34
35 class LoadTests(testtools.TestCase):
36
37     def test_simple(self):
38         fd, name = tempfile.mkstemp()
39         self.addCleanup(os.remove, name)
40         f = os.fdopen(fd, 'w')
41         f.write("""one
42 two
43 three
44
45 for
46 """)
47         f.close()
48         l = util.load_list(name)
49         self.assertEquals(4, len(l))
50         self.assertEquals("three", l[2])
51
52 class SambaWebFileLoadTest(testtools.TestCase):
53
54     def test_simple(self):
55         fd, name = tempfile.mkstemp()
56         self.addCleanup(os.remove, name)
57         f = os.fdopen(fd, 'w')
58         f.write('href="/samba/index.html"')
59         f.close()
60         l = util.SambaWebFileLoad(os.getcwd(),name)
61         self.assertEquals('href="http://www.samba.org/samba/index.html"', l)
62         fd1, name1 = tempfile.mkstemp()
63         self.addCleanup(os.remove, name1)
64         f1 = os.fdopen(fd1, 'w')
65         f1.write('<!--#include virtual="/samba/name2" -->')
66         f1.close()
67         l1 = util.SambaWebFileLoad(os.path.dirname(os.path.realpath("name1")),name1)
68         self.assertEquals('', l1)
69