Best Python code snippet using mailosaur-python_python
tests.py
Source:tests.py
1import os2import re3import types4from datetime import datetime, timedelta5from decimal import Decimal6from unittest import TestCase, mock7from django.core.exceptions import ValidationError8from django.core.files.base import ContentFile9from django.core.validators import (10 BaseValidator, DecimalValidator, EmailValidator, FileExtensionValidator,11 MaxLengthValidator, MaxValueValidator, MinLengthValidator,12 MinValueValidator, ProhibitNullCharactersValidator, RegexValidator,13 URLValidator, int_list_validator, validate_comma_separated_integer_list,14 validate_email, validate_image_file_extension, validate_integer,15 validate_ipv4_address, validate_ipv6_address, validate_ipv46_address,16 validate_slug, validate_unicode_slug,17)18from django.test import SimpleTestCase, ignore_warnings19from django.utils.deprecation import RemovedInDjango41Warning20try:21 from PIL import Image # noqa22except ImportError:23 PILLOW_IS_INSTALLED = False24else:25 PILLOW_IS_INSTALLED = True26NOW = datetime.now()27EXTENDED_SCHEMES = ['http', 'https', 'ftp', 'ftps', 'git', 'file', 'git+ssh']28TEST_DATA = [29 # (validator, value, expected),30 (validate_integer, '42', None),31 (validate_integer, '-42', None),32 (validate_integer, -42, None),33 (validate_integer, -42.5, ValidationError),34 (validate_integer, None, ValidationError),35 (validate_integer, 'a', ValidationError),36 (validate_integer, '\n42', ValidationError),37 (validate_integer, '42\n', ValidationError),38 (validate_email, 'email@here.com', None),39 (validate_email, 'weirder-email@here.and.there.com', None),40 (validate_email, 'email@[127.0.0.1]', None),41 (validate_email, 'email@[2001:dB8::1]', None),42 (validate_email, 'email@[2001:dB8:0:0:0:0:0:1]', None),43 (validate_email, 'email@[::fffF:127.0.0.1]', None),44 (validate_email, 'example@valid-----hyphens.com', None),45 (validate_email, 'example@valid-with-hyphens.com', None),46 (validate_email, 'test@domain.with.idn.tld.à¤à¤¦à¤¾à¤¹à¤°à¤£.परà¥à¤à¥à¤·à¤¾', None),47 (validate_email, 'email@localhost', None),48 (EmailValidator(allowlist=['localdomain']), 'email@localdomain', None),49 (validate_email, '"test@test"@example.com', None),50 (validate_email, 'example@atm.%s' % ('a' * 63), None),51 (validate_email, 'example@%s.atm' % ('a' * 63), None),52 (validate_email, 'example@%s.%s.atm' % ('a' * 63, 'b' * 10), None),53 (validate_email, 'example@atm.%s' % ('a' * 64), ValidationError),54 (validate_email, 'example@%s.atm.%s' % ('b' * 64, 'a' * 63), ValidationError),55 (validate_email, None, ValidationError),56 (validate_email, '', ValidationError),57 (validate_email, 'abc', ValidationError),58 (validate_email, 'abc@', ValidationError),59 (validate_email, 'abc@bar', ValidationError),60 (validate_email, 'a @x.cz', ValidationError),61 (validate_email, 'abc@.com', ValidationError),62 (validate_email, 'something@@somewhere.com', ValidationError),63 (validate_email, 'email@127.0.0.1', ValidationError),64 (validate_email, 'email@[127.0.0.256]', ValidationError),65 (validate_email, 'email@[2001:db8::12345]', ValidationError),66 (validate_email, 'email@[2001:db8:0:0:0:0:1]', ValidationError),67 (validate_email, 'email@[::ffff:127.0.0.256]', ValidationError),68 (validate_email, 'example@invalid-.com', ValidationError),69 (validate_email, 'example@-invalid.com', ValidationError),70 (validate_email, 'example@invalid.com-', ValidationError),71 (validate_email, 'example@inv-.alid-.com', ValidationError),72 (validate_email, 'example@inv-.-alid.com', ValidationError),73 (validate_email, 'test@example.com\n\n<script src="x.js">', ValidationError),74 # Quoted-string format (CR not allowed)75 (validate_email, '"\\\011"@here.com', None),76 (validate_email, '"\\\012"@here.com', ValidationError),77 (validate_email, 'trailingdot@shouldfail.com.', ValidationError),78 # Max length of domain name labels is 63 characters per RFC 1034.79 (validate_email, 'a@%s.us' % ('a' * 63), None),80 (validate_email, 'a@%s.us' % ('a' * 64), ValidationError),81 # Trailing newlines in username or domain not allowed82 (validate_email, 'a@b.com\n', ValidationError),83 (validate_email, 'a\n@b.com', ValidationError),84 (validate_email, '"test@test"\n@example.com', ValidationError),85 (validate_email, 'a@[127.0.0.1]\n', ValidationError),86 (validate_slug, 'slug-ok', None),87 (validate_slug, 'longer-slug-still-ok', None),88 (validate_slug, '--------', None),89 (validate_slug, 'nohyphensoranything', None),90 (validate_slug, 'a', None),91 (validate_slug, '1', None),92 (validate_slug, 'a1', None),93 (validate_slug, '', ValidationError),94 (validate_slug, ' text ', ValidationError),95 (validate_slug, ' ', ValidationError),96 (validate_slug, 'some@mail.com', ValidationError),97 (validate_slug, 'ä½ å¥½', ValidationError),98 (validate_slug, 'ä½ å¥½', ValidationError),99 (validate_slug, '\n', ValidationError),100 (validate_slug, 'trailing-newline\n', ValidationError),101 (validate_unicode_slug, 'slug-ok', None),102 (validate_unicode_slug, 'longer-slug-still-ok', None),103 (validate_unicode_slug, '--------', None),104 (validate_unicode_slug, 'nohyphensoranything', None),105 (validate_unicode_slug, 'a', None),106 (validate_unicode_slug, '1', None),107 (validate_unicode_slug, 'a1', None),108 (validate_unicode_slug, 'ä½ å¥½', None),109 (validate_unicode_slug, '', ValidationError),110 (validate_unicode_slug, ' text ', ValidationError),111 (validate_unicode_slug, ' ', ValidationError),112 (validate_unicode_slug, 'some@mail.com', ValidationError),113 (validate_unicode_slug, '\n', ValidationError),114 (validate_unicode_slug, 'ä½ å¥½', ValidationError),115 (validate_unicode_slug, 'trailing-newline\n', ValidationError),116 (validate_ipv4_address, '1.1.1.1', None),117 (validate_ipv4_address, '255.0.0.0', None),118 (validate_ipv4_address, '0.0.0.0', None),119 (validate_ipv4_address, '256.1.1.1', ValidationError),120 (validate_ipv4_address, '25.1.1.', ValidationError),121 (validate_ipv4_address, '25,1,1,1', ValidationError),122 (validate_ipv4_address, '25.1 .1.1', ValidationError),123 (validate_ipv4_address, '1.1.1.1\n', ValidationError),124 (validate_ipv4_address, 'Ù§.2Ù¥.3Ù£.243', ValidationError),125 # validate_ipv6_address uses django.utils.ipv6, which126 # is tested in much greater detail in its own testcase127 (validate_ipv6_address, 'fe80::1', None),128 (validate_ipv6_address, '::1', None),129 (validate_ipv6_address, '1:2:3:4:5:6:7:8', None),130 (validate_ipv6_address, '1:2', ValidationError),131 (validate_ipv6_address, '::zzz', ValidationError),132 (validate_ipv6_address, '12345::', ValidationError),133 (validate_ipv46_address, '1.1.1.1', None),134 (validate_ipv46_address, '255.0.0.0', None),135 (validate_ipv46_address, '0.0.0.0', None),136 (validate_ipv46_address, 'fe80::1', None),137 (validate_ipv46_address, '::1', None),138 (validate_ipv46_address, '1:2:3:4:5:6:7:8', None),139 (validate_ipv46_address, '256.1.1.1', ValidationError),140 (validate_ipv46_address, '25.1.1.', ValidationError),141 (validate_ipv46_address, '25,1,1,1', ValidationError),142 (validate_ipv46_address, '25.1 .1.1', ValidationError),143 (validate_ipv46_address, '1:2', ValidationError),144 (validate_ipv46_address, '::zzz', ValidationError),145 (validate_ipv46_address, '12345::', ValidationError),146 (validate_comma_separated_integer_list, '1', None),147 (validate_comma_separated_integer_list, '12', None),148 (validate_comma_separated_integer_list, '1,2', None),149 (validate_comma_separated_integer_list, '1,2,3', None),150 (validate_comma_separated_integer_list, '10,32', None),151 (validate_comma_separated_integer_list, '', ValidationError),152 (validate_comma_separated_integer_list, 'a', ValidationError),153 (validate_comma_separated_integer_list, 'a,b,c', ValidationError),154 (validate_comma_separated_integer_list, '1, 2, 3', ValidationError),155 (validate_comma_separated_integer_list, ',', ValidationError),156 (validate_comma_separated_integer_list, '1,2,3,', ValidationError),157 (validate_comma_separated_integer_list, '1,2,', ValidationError),158 (validate_comma_separated_integer_list, ',1', ValidationError),159 (validate_comma_separated_integer_list, '1,,2', ValidationError),160 (int_list_validator(sep='.'), '1.2.3', None),161 (int_list_validator(sep='.', allow_negative=True), '1.2.3', None),162 (int_list_validator(allow_negative=True), '-1,-2,3', None),163 (int_list_validator(allow_negative=True), '1,-2,-12', None),164 (int_list_validator(), '-1,2,3', ValidationError),165 (int_list_validator(sep='.'), '1,2,3', ValidationError),166 (int_list_validator(sep='.'), '1.2.3\n', ValidationError),167 (MaxValueValidator(10), 10, None),168 (MaxValueValidator(10), -10, None),169 (MaxValueValidator(10), 0, None),170 (MaxValueValidator(NOW), NOW, None),171 (MaxValueValidator(NOW), NOW - timedelta(days=1), None),172 (MaxValueValidator(0), 1, ValidationError),173 (MaxValueValidator(NOW), NOW + timedelta(days=1), ValidationError),174 (MinValueValidator(-10), -10, None),175 (MinValueValidator(-10), 10, None),176 (MinValueValidator(-10), 0, None),177 (MinValueValidator(NOW), NOW, None),178 (MinValueValidator(NOW), NOW + timedelta(days=1), None),179 (MinValueValidator(0), -1, ValidationError),180 (MinValueValidator(NOW), NOW - timedelta(days=1), ValidationError),181 # limit_value may be a callable.182 (MinValueValidator(lambda: 1), 0, ValidationError),183 (MinValueValidator(lambda: 1), 1, None),184 (MaxLengthValidator(10), '', None),185 (MaxLengthValidator(10), 10 * 'x', None),186 (MaxLengthValidator(10), 15 * 'x', ValidationError),187 (MinLengthValidator(10), 15 * 'x', None),188 (MinLengthValidator(10), 10 * 'x', None),189 (MinLengthValidator(10), '', ValidationError),190 (URLValidator(EXTENDED_SCHEMES), 'file://localhost/path', None),191 (URLValidator(EXTENDED_SCHEMES), 'git://example.com/', None),192 (URLValidator(EXTENDED_SCHEMES), 'git+ssh://git@github.com/example/hg-git.git', None),193 (URLValidator(EXTENDED_SCHEMES), 'git://-invalid.com', ValidationError),194 (URLValidator(), None, ValidationError),195 (URLValidator(), 56, ValidationError),196 (URLValidator(), 'no_scheme', ValidationError),197 # Trailing newlines not accepted198 (URLValidator(), 'http://www.djangoproject.com/\n', ValidationError),199 (URLValidator(), 'http://[::ffff:192.9.5.5]\n', ValidationError),200 # Trailing junk does not take forever to reject201 (URLValidator(), 'http://www.asdasdasdasdsadfm.com.br ', ValidationError),202 (URLValidator(), 'http://www.asdasdasdasdsadfm.com.br z', ValidationError),203 (BaseValidator(True), True, None),204 (BaseValidator(True), False, ValidationError),205 (RegexValidator(), '', None),206 (RegexValidator(), 'x1x2', None),207 (RegexValidator('[0-9]+'), 'xxxxxx', ValidationError),208 (RegexValidator('[0-9]+'), '1234', None),209 (RegexValidator(re.compile('[0-9]+')), '1234', None),210 (RegexValidator('.*'), '', None),211 (RegexValidator(re.compile('.*')), '', None),212 (RegexValidator('.*'), 'xxxxx', None),213 (RegexValidator('x'), 'y', ValidationError),214 (RegexValidator(re.compile('x')), 'y', ValidationError),215 (RegexValidator('x', inverse_match=True), 'y', None),216 (RegexValidator(re.compile('x'), inverse_match=True), 'y', None),217 (RegexValidator('x', inverse_match=True), 'x', ValidationError),218 (RegexValidator(re.compile('x'), inverse_match=True), 'x', ValidationError),219 (RegexValidator('x', flags=re.IGNORECASE), 'y', ValidationError),220 (RegexValidator('a'), 'A', ValidationError),221 (RegexValidator('a', flags=re.IGNORECASE), 'A', None),222 (FileExtensionValidator(['txt']), ContentFile('contents', name='fileWithUnsupportedExt.jpg'), ValidationError),223 (FileExtensionValidator(['txt']), ContentFile('contents', name='fileWithUnsupportedExt.JPG'), ValidationError),224 (FileExtensionValidator(['txt']), ContentFile('contents', name='fileWithNoExtension'), ValidationError),225 (FileExtensionValidator(['']), ContentFile('contents', name='fileWithAnExtension.txt'), ValidationError),226 (FileExtensionValidator([]), ContentFile('contents', name='file.txt'), ValidationError),227 (FileExtensionValidator(['']), ContentFile('contents', name='fileWithNoExtension'), None),228 (FileExtensionValidator(['txt']), ContentFile('contents', name='file.txt'), None),229 (FileExtensionValidator(['txt']), ContentFile('contents', name='file.TXT'), None),230 (FileExtensionValidator(['TXT']), ContentFile('contents', name='file.txt'), None),231 (FileExtensionValidator(), ContentFile('contents', name='file.jpg'), None),232 (DecimalValidator(max_digits=2, decimal_places=2), Decimal('0.99'), None),233 (DecimalValidator(max_digits=2, decimal_places=1), Decimal('0.99'), ValidationError),234 (DecimalValidator(max_digits=3, decimal_places=1), Decimal('999'), ValidationError),235 (DecimalValidator(max_digits=4, decimal_places=1), Decimal('999'), None),236 (DecimalValidator(max_digits=20, decimal_places=2), Decimal('742403889818000000'), None),237 (DecimalValidator(20, 2), Decimal('7.42403889818E+17'), None),238 (DecimalValidator(max_digits=20, decimal_places=2), Decimal('7424742403889818000000'), ValidationError),239 (DecimalValidator(max_digits=5, decimal_places=2), Decimal('7304E-1'), None),240 (DecimalValidator(max_digits=5, decimal_places=2), Decimal('7304E-3'), ValidationError),241 (DecimalValidator(max_digits=5, decimal_places=5), Decimal('70E-5'), None),242 (DecimalValidator(max_digits=5, decimal_places=5), Decimal('70E-6'), ValidationError),243 # 'Enter a number.' errors244 *[245 (DecimalValidator(decimal_places=2, max_digits=10), Decimal(value), ValidationError)246 for value in (247 'NaN', '-NaN', '+NaN', 'sNaN', '-sNaN', '+sNaN',248 'Inf', '-Inf', '+Inf', 'Infinity', '-Infinity', '+Infinity',249 )250 ],251 (validate_image_file_extension, ContentFile('contents', name='file.jpg'), None),252 (validate_image_file_extension, ContentFile('contents', name='file.png'), None),253 (validate_image_file_extension, ContentFile('contents', name='file.PNG'), None),254 (validate_image_file_extension, ContentFile('contents', name='file.txt'), ValidationError),255 (validate_image_file_extension, ContentFile('contents', name='file'), ValidationError),256 (ProhibitNullCharactersValidator(), '\x00something', ValidationError),257 (ProhibitNullCharactersValidator(), 'something', None),258 (ProhibitNullCharactersValidator(), None, None),259]260def create_path(filename):261 return os.path.abspath(os.path.join(os.path.dirname(__file__), filename))262# Add valid and invalid URL tests.263# This only tests the validator without extended schemes.264with open(create_path('valid_urls.txt'), encoding='utf8') as f:265 for url in f:266 TEST_DATA.append((URLValidator(), url.strip(), None))267with open(create_path('invalid_urls.txt'), encoding='utf8') as f:268 for url in f:269 TEST_DATA.append((URLValidator(), url.strip(), ValidationError))270class TestValidators(SimpleTestCase):271 def test_validators(self):272 for validator, value, expected in TEST_DATA:273 name = validator.__name__ if isinstance(validator, types.FunctionType) else validator.__class__.__name__274 exception_expected = expected is not None and issubclass(expected, Exception)275 with self.subTest(name, value=value):276 if validator is validate_image_file_extension and not PILLOW_IS_INSTALLED:277 self.skipTest('Pillow is required to test validate_image_file_extension.')278 if exception_expected:279 with self.assertRaises(expected):280 validator(value)281 else:282 self.assertEqual(expected, validator(value))283 def test_single_message(self):284 v = ValidationError('Not Valid')285 self.assertEqual(str(v), "['Not Valid']")286 self.assertEqual(repr(v), "ValidationError(['Not Valid'])")287 def test_message_list(self):288 v = ValidationError(['First Problem', 'Second Problem'])289 self.assertEqual(str(v), "['First Problem', 'Second Problem']")290 self.assertEqual(repr(v), "ValidationError(['First Problem', 'Second Problem'])")291 def test_message_dict(self):292 v = ValidationError({'first': ['First Problem']})293 self.assertEqual(str(v), "{'first': ['First Problem']}")294 self.assertEqual(repr(v), "ValidationError({'first': ['First Problem']})")295 def test_regex_validator_flags(self):296 msg = 'If the flags are set, regex must be a regular expression string.'297 with self.assertRaisesMessage(TypeError, msg):298 RegexValidator(re.compile('a'), flags=re.IGNORECASE)299 def test_max_length_validator_message(self):300 v = MaxLengthValidator(16, message='"%(value)s" has more than %(limit_value)d characters.')301 with self.assertRaisesMessage(ValidationError, '"djangoproject.com" has more than 16 characters.'):302 v('djangoproject.com')303class TestValidatorEquality(TestCase):304 """305 Validators have valid equality operators (#21638)306 """307 def test_regex_equality(self):308 self.assertEqual(309 RegexValidator(r'^(?:[a-z0-9\.\-]*)://'),310 RegexValidator(r'^(?:[a-z0-9\.\-]*)://'),311 )312 self.assertNotEqual(313 RegexValidator(r'^(?:[a-z0-9\.\-]*)://'),314 RegexValidator(r'^(?:[0-9\.\-]*)://'),315 )316 self.assertEqual(317 RegexValidator(r'^(?:[a-z0-9\.\-]*)://', "oh noes", "invalid"),318 RegexValidator(r'^(?:[a-z0-9\.\-]*)://', "oh noes", "invalid"),319 )320 self.assertNotEqual(321 RegexValidator(r'^(?:[a-z0-9\.\-]*)://', "oh", "invalid"),322 RegexValidator(r'^(?:[a-z0-9\.\-]*)://', "oh noes", "invalid"),323 )324 self.assertNotEqual(325 RegexValidator(r'^(?:[a-z0-9\.\-]*)://', "oh noes", "invalid"),326 RegexValidator(r'^(?:[a-z0-9\.\-]*)://'),327 )328 self.assertNotEqual(329 RegexValidator('', flags=re.IGNORECASE),330 RegexValidator(''),331 )332 self.assertNotEqual(333 RegexValidator(''),334 RegexValidator('', inverse_match=True),335 )336 def test_regex_equality_nocache(self):337 pattern = r'^(?:[a-z0-9\.\-]*)://'338 left = RegexValidator(pattern)339 re.purge()340 right = RegexValidator(pattern)341 self.assertEqual(342 left,343 right,344 )345 def test_regex_equality_blank(self):346 self.assertEqual(347 RegexValidator(),348 RegexValidator(),349 )350 def test_email_equality(self):351 self.assertEqual(352 EmailValidator(),353 EmailValidator(),354 )355 self.assertNotEqual(356 EmailValidator(message="BAD EMAIL"),357 EmailValidator(),358 )359 self.assertEqual(360 EmailValidator(message="BAD EMAIL", code="bad"),361 EmailValidator(message="BAD EMAIL", code="bad"),362 )363 def test_basic_equality(self):364 self.assertEqual(365 MaxValueValidator(44),366 MaxValueValidator(44),367 )368 self.assertEqual(MaxValueValidator(44), mock.ANY)369 self.assertNotEqual(370 MaxValueValidator(44),371 MinValueValidator(44),372 )373 self.assertNotEqual(374 MinValueValidator(45),375 MinValueValidator(11),376 )377 def test_decimal_equality(self):378 self.assertEqual(379 DecimalValidator(1, 2),380 DecimalValidator(1, 2),381 )382 self.assertNotEqual(383 DecimalValidator(1, 2),384 DecimalValidator(1, 1),385 )386 self.assertNotEqual(387 DecimalValidator(1, 2),388 DecimalValidator(2, 2),389 )390 self.assertNotEqual(391 DecimalValidator(1, 2),392 MinValueValidator(11),393 )394 def test_file_extension_equality(self):395 self.assertEqual(396 FileExtensionValidator(),397 FileExtensionValidator()398 )399 self.assertEqual(400 FileExtensionValidator(['txt']),401 FileExtensionValidator(['txt'])402 )403 self.assertEqual(404 FileExtensionValidator(['TXT']),405 FileExtensionValidator(['txt'])406 )407 self.assertEqual(408 FileExtensionValidator(['TXT', 'png']),409 FileExtensionValidator(['txt', 'png'])410 )411 self.assertEqual(412 FileExtensionValidator(['txt']),413 FileExtensionValidator(['txt'], code='invalid_extension')414 )415 self.assertNotEqual(416 FileExtensionValidator(['txt']),417 FileExtensionValidator(['png'])418 )419 self.assertNotEqual(420 FileExtensionValidator(['txt']),421 FileExtensionValidator(['png', 'jpg'])422 )423 self.assertNotEqual(424 FileExtensionValidator(['txt']),425 FileExtensionValidator(['txt'], code='custom_code')426 )427 self.assertNotEqual(428 FileExtensionValidator(['txt']),429 FileExtensionValidator(['txt'], message='custom error message')430 )431 def test_prohibit_null_characters_validator_equality(self):432 self.assertEqual(433 ProhibitNullCharactersValidator(message='message', code='code'),434 ProhibitNullCharactersValidator(message='message', code='code')435 )436 self.assertEqual(437 ProhibitNullCharactersValidator(),438 ProhibitNullCharactersValidator()439 )440 self.assertNotEqual(441 ProhibitNullCharactersValidator(message='message1', code='code'),442 ProhibitNullCharactersValidator(message='message2', code='code')443 )444 self.assertNotEqual(445 ProhibitNullCharactersValidator(message='message', code='code1'),446 ProhibitNullCharactersValidator(message='message', code='code2')447 )448class DeprecationTests(SimpleTestCase):449 @ignore_warnings(category=RemovedInDjango41Warning)450 def test_whitelist(self):451 validator = EmailValidator(whitelist=['localdomain'])452 self.assertEqual(validator.domain_allowlist, ['localdomain'])453 self.assertIsNone(validator('email@localdomain'))454 self.assertEqual(validator.domain_allowlist, validator.domain_whitelist)455 def test_whitelist_warning(self):456 msg = "The whitelist argument is deprecated in favor of allowlist."457 with self.assertRaisesMessage(RemovedInDjango41Warning, msg):458 EmailValidator(whitelist='localdomain')459 @ignore_warnings(category=RemovedInDjango41Warning)460 def test_domain_whitelist(self):461 validator = EmailValidator()462 validator.domain_whitelist = ['mydomain']463 self.assertEqual(validator.domain_allowlist, ['mydomain'])464 self.assertEqual(validator.domain_allowlist, validator.domain_whitelist)465 def test_domain_whitelist_access_warning(self):466 validator = EmailValidator()467 msg = (468 'The domain_whitelist attribute is deprecated in favor of '469 'domain_allowlist.'470 )471 with self.assertRaisesMessage(RemovedInDjango41Warning, msg):472 validator.domain_whitelist473 def test_domain_whitelist_set_warning(self):474 validator = EmailValidator()475 msg = (476 'The domain_whitelist attribute is deprecated in favor of '477 'domain_allowlist.'478 )479 with self.assertRaisesMessage(RemovedInDjango41Warning, msg):...
test_validators.py
Source:test_validators.py
...6 try:7 validate_country_code("ZZ")8 except ValidationError:9 pass10def test_validate_email():11 """Test that the check_email_format() works properly"""12 assert validate_email("user@examplectf.com") is True13 assert validate_email("user+plus@gmail.com") is True14 assert validate_email("user.period1234@gmail.com") is True15 assert validate_email("user.period1234@b.c") is True16 assert validate_email("user.period1234@b") is False17 assert validate_email("no.ampersand") is False18 assert validate_email("user@") is False19 assert validate_email("@examplectf.com") is False20 assert validate_email("user.io@ctfd") is False21 assert validate_email("user\\@ctfd") is False22 for invalid_email in [23 "user.@examplectf.com",24 ".user@examplectf.com",25 "user@ctfd..io",26 ]:27 try:28 assert validate_email(invalid_email) is False29 except AssertionError:...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!