test_fix_maintainer.py 3.1 KB

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