Commit | Line | Data |
---|---|---|
c9da760a PD |
1 | ''' |
2 | unit_tester.py - The module contains the MailScriptTester class. | |
3 | ||
4 | Copyright (c) 2012 Intra2net AG | |
5 | Author: Plamen Dimitrov | |
6 | ||
7 | This program is free software: you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation, either version 3 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ''' | |
17 | ||
18 | import unittest | |
19 | import datetime | |
20 | import date_interpreter | |
21 | ||
22 | class MailScriptTester(unittest.TestCase): | |
23 | ||
24 | def setUp(self): | |
25 | self.date_interp = date_interpreter.DateInterpreter() | |
26 | self.true_date = datetime.datetime(2007, 12, 11, 18, 24, 35) | |
27 | ||
28 | def test_received_header1(self): | |
29 | """Tests the date extraction method.""" | |
30 | date = [[0, b"Tue, 11 Dec 2007 18:24:35 +0100"]] | |
31 | extracted_date = self.date_interp.extract_received_date(date) | |
32 | self.assertEqual(extracted_date, self.true_date, "Failed date format 1") | |
33 | ||
34 | def test_received_header2(self): | |
35 | """Tests the date extraction method.""" | |
36 | date = [[0, b"11 Dec 2007 \r\n18:24:35 +0100"]] | |
37 | extracted_date = self.date_interp.extract_received_date(date) | |
38 | self.assertEqual(extracted_date, self.true_date, "Failed date format 2") | |
39 | return | |
40 | ||
41 | def test_received_header3(self): | |
42 | """Tests the date extraction method.""" | |
43 | date = [[0, b"11 Dec 2007 18:24:35 +0100"]] | |
44 | extracted_date = self.date_interp.extract_received_date(date) | |
45 | self.assertEqual(extracted_date, self.true_date, "Failed date format 3") | |
46 | ||
47 | def test_received_header4(self): | |
48 | """Tests the date extraction method.""" | |
49 | date = [[0, b"11 Dec 2007 18:24:35"]] | |
50 | extracted_date = self.date_interp.extract_received_date(date) | |
51 | #should not be equal because of time zone assumption | |
52 | self.assertNotEqual(extracted_date, self.true_date, "Failed date format 4") | |
53 | ||
54 | def test_received_header5(self): | |
55 | """Tests the received date extraction method.""" | |
56 | date = [[0, b"11 Dec 2007 18:24:35 GMT"]] | |
57 | extracted_date = self.date_interp.extract_received_date(date) | |
58 | #should not be equal because of time zone assumption | |
59 | self.assertNotEqual(extracted_date, self.true_date, "Failed date format 5") | |
60 | ||
61 | def test_compare_dates(self): | |
62 | """Tests the date comparison method.""" | |
63 | self.true_date2 = datetime.datetime(2007, 12, 11, 18, 34, 35) | |
64 | #is difference of 10 mins significant if tolerance is 9 mins | |
65 | self.assertTrue(bool(self.date_interp.compare_dates(self.true_date, self.true_date2, 9*60)), "Failed at comparison test") | |
66 | #is difference of 10 mins significant if tolerance is 11 mins | |
67 | self.assertFalse(bool(self.date_interp.compare_dates(self.true_date, self.true_date2, 11*60)), "Failed at comparison test") | |
68 | ||
69 | if __name__ == '__main__': | |
70 | unittest.main() |