]> git.decadent.org.uk Git - dak.git/blob - tests/test_fix_maintainer.py
Add Binary packages to new.822
[dak.git] / tests / test_fix_maintainer.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 from base_test import DakTestCase
5
6 import unittest
7
8 from daklib.textutils import fix_maintainer
9 from daklib.dak_exceptions import ParseMaintError
10
11 class FixMaintainerTestCase(DakTestCase):
12     def assertValid(self, input, a, b, c, d):
13         a_, b_, c_, d_ = fix_maintainer(input)
14
15         self.assertEqual(a, a_)
16         self.assertEqual(b, b_)
17         self.assertEqual(c, c_)
18         self.assertEqual(d, d_)
19
20     def assertNotValid(self, input):
21         self.assertRaises(ParseMaintError, lambda: fix_maintainer(input))
22
23     def testUTF8Maintainer(self):
24         # Check Valid UTF-8 maintainer field
25         self.assertValid(
26             "Noèl Köthe <noel@debian.org>",
27             "Noèl Köthe <noel@debian.org>",
28             "=?utf-8?b?Tm/DqGwgS8O2dGhl?= <noel@debian.org>",
29             "Noèl Köthe",
30             "noel@debian.org",
31         )
32
33     def testASCII(self):
34         # Check valid ASCII maintainer field
35         self.assertValid(
36             "James Troup <james@nocrew.org>",
37             "James Troup <james@nocrew.org>",
38             "James Troup <james@nocrew.org>",
39             "James Troup",
40             "james@nocrew.org",
41         )
42
43     def testRFC822(self):
44         # Check "Debian vs RFC822" fixup of names with '.' or ',' in them
45         self.assertValid(
46             "James J. Troup <james@nocrew.org>",
47             "james@nocrew.org (James J. Troup)",
48             "james@nocrew.org (James J. Troup)",
49             "James J. Troup",
50             "james@nocrew.org",
51         )
52
53     def testSimple(self):
54         self.assertValid(
55             "James J, Troup <james@nocrew.org>",
56             "james@nocrew.org (James J, Troup)",
57             "james@nocrew.org (James J, Troup)",
58             "James J, Troup",
59             "james@nocrew.org",
60         )
61
62     def testJustEmail(self):
63         # Check just-email form
64         self.assertValid(
65             "james@nocrew.org",
66             " <james@nocrew.org>",
67             " <james@nocrew.org>",
68             "",
69             "james@nocrew.org",
70         )
71
72     def testBracketedEmail(self):
73         # Check bracketed just-email form
74         self.assertValid(
75             "<james@nocrew.org>",
76             " <james@nocrew.org>",
77             " <james@nocrew.org>",
78             "",
79             "james@nocrew.org",
80         )
81
82     def testKrazy(self):
83         # Check Krazy quoted-string local part email address
84         self.assertValid(
85             "Cris van Pelt <\"Cris van Pelt\"@tribe.eu.org>",
86             "Cris van Pelt <\"Cris van Pelt\"@tribe.eu.org>",
87             "Cris van Pelt <\"Cris van Pelt\"@tribe.eu.org>",
88             "Cris van Pelt",
89             "\"Cris van Pelt\"@tribe.eu.org",
90         )
91
92     def testEmptyString(self):
93         # Check empty string
94         self.assertValid("", "", "", "", "")
95
96     def testMissingEmailAddress(self):
97         # Check for missing email address
98         self.assertNotValid("James Troup")
99
100     def testInvalidEmail(self):
101         # Check for invalid email address
102         self.assertNotValid("James Troup <james@nocrew.org")
103
104 if __name__ == '__main__':
105     unittest.main()