4 # Copyright (C) 2007, 2008 Google Inc.
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 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 """Script for unittesting the http module"""
30 from ganeti import http
33 class HttpLogfileTests(unittest.TestCase):
34 """Rests for ApacheLogfile class."""
37 FAKE_ADDRESS = "1.2.3.4"
39 def address_string(self):
40 return self.FAKE_ADDRESS
43 self.tmpfile = tempfile.NamedTemporaryFile()
44 self.logfile = http.ApacheLogfile(self.tmpfile)
49 def testFormatLogTime(self):
50 self._TestInTimezone(1208646123.0, "Europe/London",
51 "19/Apr/2008:23:02:03 +0000")
52 self._TestInTimezone(1208646123, "Europe/Zurich",
53 "19/Apr/2008:23:02:03 +0000")
54 self._TestInTimezone(1208646123, "Australia/Sydney",
55 "19/Apr/2008:23:02:03 +0000")
57 def _TestInTimezone(self, seconds, timezone, expected):
58 """Tests HttpLogfile._FormatLogTime with a specific timezone
61 # Preserve environment
62 old_TZ = os.environ.get("TZ", None)
64 os.environ["TZ"] = timezone
66 result = self.logfile._FormatLogTime(seconds)
69 if old_TZ is not None:
70 os.environ["TZ"] = old_TZ
71 elif "TZ" in os.environ:
75 self.assertEqual(result, expected)
78 def testLogRequest(self):
79 request = self.FakeRequest()
80 self.logfile.LogRequest(request, "This is only a %s", "test")
83 if __name__ == '__main__':