diff --git a/tests/test_rendercv.py b/tests/test_rendercv.py index 2d11c8f..3a9fbc6 100644 --- a/tests/test_rendercv.py +++ b/tests/test_rendercv.py @@ -2,6 +2,8 @@ import unittest from rendercv import data_model, rendering from datetime import date as Date +from pydantic import ValidationError +from pydantic_core import Url class TestRendercv(unittest.TestCase): @@ -55,6 +57,86 @@ class TestRendercv(unittest.TestCase): result = data_model.format_date(date) self.assertEqual(result, expected) + def test_data_cv_name(self): + cv_dict = {"name": "John Doe Test"} + cv = data_model.CurriculumVitae(**cv_dict) + self.assertEqual(cv.name, "John Doe Test") + + with self.assertRaises(ValidationError): + cv_dict = {} + data_model.CurriculumVitae(**cv_dict) + + def test_data_cv_email(self): + # Test invalid emails + cv_dict = {"name": "John Doe", "email": "wrongEmail"} + with self.assertRaises(ValidationError): + data_model.CurriculumVitae(**cv_dict) + + cv_dict["email"] = "anotherWrongEmail@.com" + with self.assertRaises(ValidationError): + data_model.CurriculumVitae(**cv_dict) + + # Test empty email field + cv_dict["email"] = "" + with self.assertRaises(ValidationError): + data_model.CurriculumVitae(**cv_dict) + + # Test valid email + cv_dict["email"] = "johndoe@example.com" + cv = data_model.CurriculumVitae(**cv_dict) + self.assertEqual(cv.email, "johndoe@example.com") + + def test_data_cv_phone(self): + # Test invalid phone numbers + cv_dict = {"name": "John Doe", "phone": "123456789"} + with self.assertRaises(ValidationError): + data_model.CurriculumVitae(**cv_dict) + + cv_dict["phone"] = "12" + with self.assertRaises(ValidationError): + data_model.CurriculumVitae(**cv_dict) + + # Test empty phone field + cv_dict["phone"] = "" + with self.assertRaises(ValidationError): + data_model.CurriculumVitae(**cv_dict) + + # Test valid phone numbers + cv_dict["phone"] = "+1-512-456-9999" + cv = data_model.CurriculumVitae(**cv_dict) + self.assertEqual(cv.phone, "tel:+1-512-456-9999") + + cv_dict["phone"] = "+90(555) 555 55 55" + cv = data_model.CurriculumVitae(**cv_dict) + self.assertEqual(cv.phone, "tel:+90-555-555-55-55") + + cv_dict["phone"] = "+86 139 1099 8888" + cv = data_model.CurriculumVitae(**cv_dict) + self.assertEqual(cv.phone, "tel:+86-139-1099-8888") + + def test_data_cv_website(self): + # Test invalid website + cv_dict = {"name": "John Doe", "website": "wrongWebsite"} + with self.assertRaises(ValidationError): + data_model.CurriculumVitae(**cv_dict) + + cv_dict["website"] = "anotherWrongWebsit@e.com" + with self.assertRaises(ValidationError): + data_model.CurriculumVitae(**cv_dict) + + # Test empty website field + cv_dict["website"] = "" + with self.assertRaises(ValidationError): + data_model.CurriculumVitae(**cv_dict) + + # Test valid websites + cv_dict["website"] = "https://example.com" + cv = data_model.CurriculumVitae(**cv_dict) + self.assertEqual(cv.website, Url("https://example.com/")) + + cv_dict["website"] = "http://www.example.com" + cv = data_model.CurriculumVitae(**cv_dict) + self.assertEqual(cv.website, Url("http://www.example.com/")) if __name__ == "__main__": unittest.main()