Implemented E-Mail converter.
[philipp/winterrodeln/wrpylib.git] / tests / test_wrvalidators.py
index 8cc33e636f46d92fd2c352cd460fbb5da34b1721..b12962b4fe22cbef6c570d7b674393b2825f4599 100644 (file)
@@ -377,6 +377,25 @@ class TestTelefonauskunft(unittest.TestCase):
         self.assertEqual(telefonauskunft_to_str([('+43-512-1234', 'untertags'), ('+43-664-123456', 'Alm')]), '+43-512-1234 (untertags); +43-664-123456 (Alm)')
 
 
+class TestEmail(unittest.TestCase):
+    def setUp(self):
+        self.good_addresses = ['office@example.com', 'winter+rodeln@localhost', 'joe.doe@exämple.com']
+        self.bad_addresses = ['öffice@example.com', 'winter rodeln@localhost', 'www.winterrodeln.org', 'mailto:info@example.com', 'info@example.com.']
+
+    def test_from_str(self):
+        for value in self.good_addresses:
+            self.assertEqual(value, email_from_str(value))
+        for value in self.bad_addresses:
+            with self.assertRaises(ValueError):
+                email_from_str(value)
+                print(value)
+
+    def test_to_str(self):
+        for value in self.good_addresses:
+            self.assertEqual(value, email_from_str(value))
+
+
+
 class TestBox(unittest.TestCase):
     def test_from_str(self):
         value = '{{MyTemplate|apple=2|banana=5}}'