Skip to content

Commit 5c7a09b

Browse files
committed
Added new test for special characters
1 parent afc8162 commit 5c7a09b

7 files changed

Lines changed: 27 additions & 2 deletions

File tree

__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import unittest
2+
import sys
3+
import os
4+
5+
PACKAGE_PARENT = '..'
6+
SCRIPT_DIR = os.path.dirname(os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__))))
7+
sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT)))
8+
9+
from classes.validator import Validator
10+
from tests import test_validator
165 Bytes
Binary file not shown.
739 Bytes
Binary file not shown.

classes/validator.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ def username_is_valid(self, username):
1111
if username.islower():
1212
return False
1313

14-
1514
if any(specialchar in username for specialchar in "$%^&*()#@"):
1615
return False
1716

163 Bytes
Binary file not shown.
2.09 KB
Binary file not shown.

tests/test_validator.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import unittest
2+
import sys
3+
import os
24

3-
from classes.validator import Validator
45

6+
PACKAGE_PARENT = '..'
7+
SCRIPT_DIR = os.path.dirname(os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__))))
8+
sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT)))
9+
10+
from classes.validator import Validator
511

612
class TestValidator(unittest.TestCase):
713

@@ -47,3 +53,13 @@ def test_it_will_accept_a_valid_username(self):
4753

4854
# Assert
4955
self.assertTrue(result)
56+
57+
def test_it_will_reject_username_if_there_is_a_special_character(self):
58+
# Assume
59+
username = 'Reval$%^&*()#@'
60+
61+
# Action
62+
result = self.validator.username_is_valid(username)
63+
64+
# Assert
65+
self.assertFalse(result)

0 commit comments

Comments
 (0)