From 2cd0ccef04767ebfc3f6619f39f5b7dbee9a783b Mon Sep 17 00:00:00 2001 From: Hasan Ramezani Date: Fri, 12 Mar 2021 08:56:11 +0100 Subject: [PATCH] Added tests for AssertionErrors in get_complete_version() and _lazy_re_compile(). --- tests/utils_tests/test_regex_helper.py | 11 +++++++++++ tests/version/tests.py | 13 ++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/tests/utils_tests/test_regex_helper.py b/tests/utils_tests/test_regex_helper.py index 77bcd5bb35..895890bd26 100644 --- a/tests/utils_tests/test_regex_helper.py +++ b/tests/utils_tests/test_regex_helper.py @@ -1,5 +1,7 @@ +import re import unittest +from django.test import SimpleTestCase from django.utils import regex_helper @@ -41,3 +43,12 @@ class NormalizeTests(unittest.TestCase): ['first_group_name'])] result = regex_helper.normalize(pattern) self.assertEqual(result, expected) + + +class LazyReCompileTests(SimpleTestCase): + def test_flags_with_pre_compiled_regex(self): + test_pattern = re.compile('test') + lazy_test_pattern = regex_helper._lazy_re_compile(test_pattern, re.I) + msg = 'flags must be empty if regex is passed pre-compiled' + with self.assertRaisesMessage(AssertionError, msg): + lazy_test_pattern.match('TEST') diff --git a/tests/version/tests.py b/tests/version/tests.py index c0075744bc..bfa4af0496 100644 --- a/tests/version/tests.py +++ b/tests/version/tests.py @@ -1,6 +1,6 @@ from django import get_version from django.test import SimpleTestCase -from django.utils.version import get_version_tuple +from django.utils.version import get_complete_version, get_version_tuple class VersionTests(SimpleTestCase): @@ -28,3 +28,14 @@ class VersionTests(SimpleTestCase): self.assertEqual(get_version_tuple('1.2.3'), (1, 2, 3)) self.assertEqual(get_version_tuple('1.2.3b2'), (1, 2, 3)) self.assertEqual(get_version_tuple('1.2.3b2.dev0'), (1, 2, 3)) + + def test_get_version_invalid_version(self): + tests = [ + # Invalid length. + (3, 2, 0, 'alpha', 1, '20210315111111'), + # Invalid development status. + (3, 2, 0, 'gamma', 1, '20210315111111'), + ] + for version in tests: + with self.subTest(version=version), self.assertRaises(AssertionError): + get_complete_version(version)