Skip to content

Commit 94e4d80

Browse files
authored
Merge branch 'client-complete' into client-start
2 parents 214a03c + b9c49cf commit 94e4d80

34 files changed

Lines changed: 2785 additions & 55 deletions
60 KB
Binary file not shown.

planventure-api/requirements.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ werkzeug==2.3.7
1212
bcrypt==4.0.1
1313

1414
# Database migrations
15-
Flask-Migrate==4.0.5
15+
Flask-Migrate==4.0.5
16+
17+
pytest==8.3.2
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import pytest
2+
from .validators import validate_email, validate_username
3+
4+
def test_valid_emails():
5+
"""Test validation of properly formatted email addresses"""
6+
valid_emails = [
7+
"test@example.com",
8+
"user.name@domain.com",
9+
"user+tag@example.co.uk",
10+
"123@domain.com",
11+
"user@sub.domain.com"
12+
]
13+
for email in valid_emails:
14+
assert validate_email(email) is True
15+
16+
def test_invalid_emails():
17+
"""Test validation of improperly formatted email addresses"""
18+
invalid_emails = [
19+
"test@.com",
20+
"@domain.com",
21+
"test@domain",
22+
"test@domain.",
23+
"test.domain.com",
24+
"test@domain@.com",
25+
"test space@domain.com"
26+
]
27+
for email in invalid_emails:
28+
assert validate_email(email) is False
29+
30+
def test_edge_cases():
31+
"""Test validation with edge cases"""
32+
assert validate_email("") is False
33+
with pytest.raises(TypeError):
34+
validate_email(None)
35+
36+
def test_valid_usernames():
37+
"""Test validation of properly formatted usernames"""
38+
valid_usernames = [
39+
"user123",
40+
"_user",
41+
"john_doe",
42+
"a123",
43+
"Developer42",
44+
"code_master",
45+
"Alice_Bob_123"
46+
]
47+
for username in valid_usernames:
48+
assert validate_username(username) is True
49+
50+
def test_invalid_usernames():
51+
"""Test validation of improperly formatted usernames"""
52+
invalid_usernames = [
53+
"ab", # too short
54+
"a" * 17, # too long
55+
"123user", # starts with number
56+
"__user", # multiple underscores at start
57+
"user name", # contains space
58+
"user@name", # special character
59+
"-user", # starts with hyphen
60+
"user-", # ends with hyphen
61+
]
62+
for username in invalid_usernames:
63+
assert validate_username(username) is False
64+
65+
def test_username_edge_cases():
66+
"""Test username validation with edge cases"""
67+
assert validate_username("") is False
68+
with pytest.raises(TypeError):
69+
validate_username(None)

planventure-api/utils/validators.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,42 @@ def validate_email(email: str) -> bool:
44
"""Validate email format using regex pattern"""
55
pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
66
return bool(re.match(pattern, email))
7+
8+
def validate_username(username: str) -> bool:
9+
"""
10+
Validates a username according to the following rules:
11+
- Between 3 and 16 characters
12+
- Starts with a letter or single underscore
13+
- Can contain letters, numbers, and underscores after first character
14+
- No spaces or special characters
15+
16+
Args:
17+
username: The username to validate
18+
19+
Returns:
20+
bool: True if username is valid, False otherwise
21+
22+
Raises:
23+
TypeError: If username is None
24+
"""
25+
if username is None:
26+
raise TypeError("Username cannot be None")
27+
28+
# Check for empty string
29+
if not username:
30+
return False
31+
32+
# Check length (3-16 characters)
33+
if len(username) < 3 or len(username) > 16:
34+
return False
35+
36+
# Pattern explanation:
37+
# ^ - Start of string
38+
# [a-zA-Z_] - First character must be letter or underscore
39+
# (?!_) - Negative lookahead to prevent multiple underscores at start
40+
# [a-zA-Z0-9_] - Remaining characters can be letters, numbers, or underscores
41+
# {2,15} - Length of remaining characters (2-15, plus first character = 3-16 total)
42+
# $ - End of string
43+
pattern = r'^[a-zA-Z_](?!_)[a-zA-Z0-9_]{2,15}$'
44+
45+
return bool(re.match(pattern, username))

planventure-client/package-lock.json

Lines changed: 143 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

planventure-client/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"dependencies": {
1313
"@emotion/react": "^11.14.0",
1414
"@emotion/styled": "^11.14.0",
15+
"@mui/icons-material": "^6.2.0",
1516
"@mui/material": "^6.2.0",
1617
"@mui/icons-material": "^6.2.0",
1718
"react": "^18.3.1",
@@ -30,4 +31,4 @@
3031
"globals": "^15.12.0",
3132
"vite": "^6.0.1"
3233
}
33-
}
34+
}

0 commit comments

Comments
 (0)