コード例 #1
0
 def test_invalid_characters(self):
     self.assertEqual(validate_user("invalid_user", 1), False)
コード例 #2
0
 def test_valid(self):
     self.assertEqual(validate_user("validuser", 3), True)
コード例 #3
0
 def test_too_short(self):
     self.assertEqual(validate_user("inv", 5), False)
コード例 #4
0
 def test_valid(self):
     self.assertEqual(validate_user("Bhuvan",2),True)
 def test_too_short(self):
     self.assertEqual(
         validate_user("inv", 5), False
     )  # inv is 3 chars, the minlen is 5, so I characterize this as False and tell it to the computer
 def test_valid(self):  # I name the function according to the test I do
     self.assertEqual(
         validate_user("validuser", 3), True
     )  # I instruct the computer to consider these arguments as True, as acceptable results

"""
if minimum length is smaller than 1 then raise a ValueError saying that minlen must be at least 1
"""
#%%
"""
I created the py file with testing code, "validations_test.py"

and I will try various test cases/arguments to test the code in validations.py 

PLEASE NOTE that I am not using the unittest method and the class TestCase and a suite of test cases here
I will just enter arguments and see the results that the testing script gives when testing my initial script!
"""
from validations import validate_user
validate_user("", -1)

# For these values I get the output ValueError: minlen must be at least 1
# This is normal since I used invalid arguments
# the function validate_user successfully raised an error

from validations import validate_user
validate_user("", 1)

# For these values I get the output False

from validations import validate_user
validate_user("myuser", 1)

# For these values I get the output AttributeError: 'str' object has no attribute 'isalnm'
# I get an error because I have only letters and not letters+numbers