Skip to content

Commit

Permalink
Password validator
Browse files Browse the repository at this point in the history
  • Loading branch information
ikostan committed Dec 20, 2024
1 parent 11a3eb0 commit bca0306
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 25 deletions.
1 change: 1 addition & 0 deletions kyu_7/password_validator/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Password validator."""
5 changes: 4 additions & 1 deletion kyu_7/password_validator/password.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
"""
Solution for -> Password validator
Solution for -> Password validator.
Created by Egor Kostan.
GitHub: https://github.com/ikostan
"""


def password(string: str) -> bool:
"""
Password validator function.
Your job is to create a simple password
validation function, as seen on many websites.
Expand Down
49 changes: 25 additions & 24 deletions kyu_7/password_validator/test_password.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
Test for -> Password validator
Test for -> Password validator.
Created by Egor Kostan.
GitHub: https://github.com/ikostan
"""
Expand All @@ -9,6 +10,7 @@

import unittest
import allure
from parameterized import parameterized
from utils.log_func import print_log
from kyu_7.password_validator.password import password

Expand All @@ -30,38 +32,37 @@
name='Source/Kata')
# pylint: enable-msg=R0801
class PasswordTestCase(unittest.TestCase):
"""
Testing password function
"""
"""Testing password function."""

def test_password(self):
@parameterized.expand([
("Abcd1234", True),
("Abcd123", False),
("abcd1234", False),
("AbcdefGhijKlmnopQRsTuvwxyZ1234567890", True),
("ABCD1234", False),
(r"Ab1!@#$%^&*()-_+={}[]|\:;?/>.<,", True),
(r"!@#$%^&*()-_+={}[]|\:;?/>.<,", False),
("", False),
(" aA1----", True),
("4aA1----", True)])
def test_password(self, string, expected):
"""
Testing password function with various test inputs
Testing password function with various test inputs.
:return:
"""
# pylint: disable-msg=R0801
allure.dynamic.title("Testing password function")
allure.dynamic.severity(allure.severity_level.NORMAL)
allure.dynamic.description_html(
'<h3>Codewars badge:</h3>'
'<img src="https://www.codewars.com/users/myFirstCode'
'/badges/large">'
'<img src="'
'https://www.codewars.com/users/myFirstCode/badges/large'
'">'
'<h3>Test Description:</h3>'
"<p></p>")
# pylint: enable-msg=R0801
with allure.step("Enter test string and verify the result"):
test_data: tuple = (
("Abcd1234", True),
("Abcd123", False),
("abcd1234", False),
("AbcdefGhijKlmnopQRsTuvwxyZ1234567890", True),
("ABCD1234", False),
(r"Ab1!@#$%^&*()-_+={}[]|\:;?/>.<,", True),
(r"!@#$%^&*()-_+={}[]|\:;?/>.<,", False),
("", False),
(" aA1----", True),
("4aA1----", True))

for string, expected in test_data:
print_log(string=string, expected=expected)
self.assertEqual(expected, password(string))
with allure.step(f"Enter test string: {string} "
f"and verify the expected result: {expected}."):
print_log(string=string, expected=expected)
self.assertEqual(expected, password(string))

0 comments on commit bca0306

Please sign in to comment.