add ceod unit tests for valid usernames
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
Ohm Patel 2024-01-22 06:37:25 +00:00
parent f6cfcf5e29
commit d11bdc1a6f
Signed by: o32patel
GPG Key ID: 096A9E27B27F535C
2 changed files with 35 additions and 1 deletions

View File

@ -46,7 +46,7 @@ def create_user():
uid_validator = validate_username(body['uid'])
if not uid_validator.is_valid:
raise BadRequest(f"bad uid: {uid_validator.error_message}")
raise BadRequest("Attribute 'uid' is missing or invalid")
if terms:
logger.info(f"Creating member {body['uid']} for terms {terms}")

View File

@ -135,6 +135,40 @@ def test_api_create_user_without_forwarding_addresses(cfg, client):
assert data['error'] == "BadRequest: Attribute 'forwarding_addresses' is missing or empty"
def test_api_create_user_without_valid_username(cfg, client):
status, data = client.post('/api/members', json={
'uid': '4_test',
'cn': 'Test Four',
'given_name': 'Test',
'sn': 'Four',
'program': 'Math',
'terms': ['w2024'],
'forwarding_addresses': ['test4@uwaterloo.internal'],
})
try:
assert status == 400
assert data['error'] == "BadRequest: Attribute 'uid' is missing or invalid"
finally:
client.delete('/api/members/4_test')
def test_api_create_user_with_valid_username(cfg, client):
status, data = client.post('/api/members', json={
'uid': 'test-4',
'cn': 'Test Four',
'given_name': 'Test',
'sn': 'Four',
'program': 'Math',
'terms': ['w2024'],
'forwarding_addresses': ['test4@uwaterloo.internal'],
})
try:
assert status == 200
assert data[-1]['status'] == 'completed'
finally:
client.delete('/api/members/test-4')
def test_api_get_user(cfg, client, create_user_result):
old_data = create_user_result.copy()
uid = old_data['uid']