Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # ------------- tasks/acceptable_password.py ------------
- def has_digits(password: str) -> bool:
- return all([password.isalnum(),
- not password.isalpha(),
- not password.isnumeric()])
- def is_acceptable_password(password: str) -> bool:
- misses_password_word = "password" not in password.lower()
- is_long = len(password) > 8
- is_short = len(password) >= 7 and not is_long
- digits_check = has_digits(password)
- is_valid_short = all([is_short, digits_check, misses_password_word])
- is_valid_long = all([is_long, misses_password_word])
- return any([is_valid_short, is_valid_long])
- # -------------- tests/test_acceptable_password.py -------------
- import pytest
- from tasks.acceptable_password import is_acceptable_password, has_digits
- @pytest.mark.parametrize(["data", "is_valid"], [
- ["short", False],
- ['short54', True],
- ['muchlonger', True],
- ['ashort', False],
- ['muchlonger5', True],
- ['sh5', False],
- ['1234567', False],
- ['12345678910', True],
- ['password12345', False],
- ['PASSWORD12345', False],
- ['pass1234word', True]
- ])
- def test_acceptable_password(data, is_valid):
- assert is_acceptable_password(data) == is_valid
- @pytest.mark.parametrize(["data", "is_valid"], [
- ["short", False],
- ['short54', True],
- ['345', False],
- ])
- def test_has_digits(data, is_valid):
- assert has_digits(data) == is_valid
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement