Advertisement
Guest User

Untitled

a guest
Jan 30th, 2016
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. import unittest
  2.  
  3. from email import *
  4.  
  5.  
  6. class EmailTests(unittest.TestCase):
  7.  
  8. def test_rule_1(self):
  9. cases = (
  10. ("abcvsio", RULE_1_ERROR),
  11. ("aovooioaisd@mail.ru", CHECK_OK),
  12. )
  13. for case in cases:
  14. r = check_email(case[0])
  15. try:
  16. self.assertEqual(r, case[1])
  17. except AssertionError:
  18. print case[0], r, case[1]
  19. raise AssertionError
  20.  
  21. def test_rule_2(self):
  22. cases = (
  23. ("abcdef@y.r", RULE_2_ERROR_1),
  24. ("abcdef@yandex.ru", CHECK_OK),
  25. ("abcdef@{}.ru".format("y" * 300), RULE_2_ERROR_1),
  26. )
  27. for case in cases:
  28. r = check_email(case[0])
  29. try:
  30. self.assertEqual(r, case[1])
  31. except AssertionError:
  32. print case[0], r, case[1]
  33. raise AssertionError
  34.  
  35. def test_rule_3(self):
  36. cases = (
  37. ("abcdef@-yandex.ru", RULE_3_ERROR),
  38. ("abcdef@-yandex-.ru", RULE_3_ERROR),
  39. ("abcdef@yandex-.ru", RULE_3_ERROR),
  40. ("abcdef@yandex.ru", CHECK_OK),
  41. )
  42. for case in cases:
  43. r = check_email(case[0])
  44. try:
  45. self.assertEqual(r, case[1])
  46. except AssertionError:
  47. print case[0], r, case[1]
  48. raise AssertionError
  49.  
  50. def test_rule_4(self):
  51. cases = (
  52. ("abc.def{}@yandex.ru".format("ddd" * 128), RULE_4_ERROR_1),
  53. ("abc-def@yandex.ru", CHECK_OK),
  54. ("abc1234465787999@yandex.ru", CHECK_OK),
  55. )
  56. for case in cases:
  57. r = check_email(case[0])
  58. try:
  59. self.assertEqual(r, case[1])
  60. except AssertionError:
  61. print case[0], r, case[1]
  62. raise AssertionError
  63.  
  64. def test_rule_5(self):
  65. cases = (
  66. ("abc.def@yandex.ru", CHECK_OK),
  67. ("abc..def@yandex.ru", RULE_5_ERROR),
  68. )
  69. for case in cases:
  70. r = check_email(case[0])
  71. try:
  72. self.assertEqual(r, case[1])
  73. except AssertionError:
  74. print case[0], r, case[1]
  75. raise AssertionError
  76.  
  77. def test_rule_6(self):
  78. cases = (
  79. ("abcdef@yandex.ru", CHECK_OK),
  80. ("ab\"cdef@yandex.ru", RULE_6_ERROR),
  81. ("a\"bc\"def@yandex.ru", CHECK_OK),
  82. ("a\"bc\"def\"vvv\"@yandex.ru", CHECK_OK),
  83. ("a\"bc\"de\"f@yandex.ru", RULE_6_ERROR),
  84. )
  85. for case in cases:
  86. r = check_email(case[0])
  87. try:
  88. self.assertEqual(r, case[1])
  89. except AssertionError:
  90. print case[0], r, case[1]
  91. raise AssertionError
  92.  
  93. def test_rule_7(self):
  94. cases = (
  95. ("abcdef@yandex.ru", CHECK_OK),
  96. ("a\"bbb!\"def@yandex.ru", CHECK_OK),
  97. ("a\"ccc,;\"def@yandex.ru", RULE_4_ERROR_2),
  98. ("a\"eee:e\"def@yandex.ru", CHECK_OK),
  99. ("a,:vvv\"@yandex.ru", RULE_7_ERROR),
  100. ("a!poaf@yandex.ru", RULE_7_ERROR),
  101. )
  102. for case in cases:
  103. r = check_email(case[0])
  104. try:
  105. self.assertEqual(r, case[1])
  106. except AssertionError:
  107. print case[0], r, case[1]
  108. raise AssertionError
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement