|
|
|
@ -7,8 +7,8 @@ def test_get_positions(client, ldap_user, g_admin_ctx): |
|
|
|
|
status, data = client.get('/api/positions') |
|
|
|
|
assert status == 200 |
|
|
|
|
expected = { |
|
|
|
|
'president': ldap_user.uid, |
|
|
|
|
'treasurer': ldap_user.uid, |
|
|
|
|
'president': [ldap_user.uid], |
|
|
|
|
'treasurer': [ldap_user.uid], |
|
|
|
|
} |
|
|
|
|
assert data == expected |
|
|
|
|
|
|
|
|
@ -20,7 +20,7 @@ def test_set_positions(cfg, client, g_admin_ctx, mock_mailman_server): |
|
|
|
|
|
|
|
|
|
users = [] |
|
|
|
|
with g_admin_ctx(): |
|
|
|
|
for uid in ['test_1', 'test_2', 'test_3', 'test_4']: |
|
|
|
|
for uid in ['test1', 'test2', 'test3', 'test4']: |
|
|
|
|
user = User(uid=uid, cn='Some Name', given_name='Some', sn='Name', |
|
|
|
|
terms=['s2021']) |
|
|
|
|
user.add_to_ldap() |
|
|
|
@ -31,23 +31,23 @@ def test_set_positions(cfg, client, g_admin_ctx, mock_mailman_server): |
|
|
|
|
try: |
|
|
|
|
# missing required position |
|
|
|
|
status, _ = client.post('/api/positions', json={ |
|
|
|
|
'vice-president': 'test_1', |
|
|
|
|
'vice-president': 'test1', |
|
|
|
|
}) |
|
|
|
|
assert status == 400 |
|
|
|
|
|
|
|
|
|
# non-existent position |
|
|
|
|
status, _ = client.post('/api/positions', json={ |
|
|
|
|
'president': 'test_1', |
|
|
|
|
'vice-president': 'test_2', |
|
|
|
|
'sysadmin': 'test_3', |
|
|
|
|
'no-such-position': 'test_3', |
|
|
|
|
'president': 'test1', |
|
|
|
|
'vice-president': 'test2', |
|
|
|
|
'sysadmin': 'test3', |
|
|
|
|
'no-such-position': 'test3', |
|
|
|
|
}) |
|
|
|
|
assert status == 400 |
|
|
|
|
|
|
|
|
|
status, data = client.post('/api/positions', json={ |
|
|
|
|
'president': 'test_1', |
|
|
|
|
'vice-president': 'test_2', |
|
|
|
|
'sysadmin': 'test_3', |
|
|
|
|
'president': 'test1', |
|
|
|
|
'vice-president': 'test2', |
|
|
|
|
'sysadmin': 'test3', |
|
|
|
|
}) |
|
|
|
|
assert status == 200 |
|
|
|
|
expected = [ |
|
|
|
@ -55,16 +55,16 @@ def test_set_positions(cfg, client, g_admin_ctx, mock_mailman_server): |
|
|
|
|
{"status": "in progress", "operation": "update_exec_group_ldap"}, |
|
|
|
|
{"status": "in progress", "operation": "subscribe_to_mailing_lists"}, |
|
|
|
|
{"status": "completed", "result": { |
|
|
|
|
"president": "test_1", |
|
|
|
|
"vice-president": "test_2", |
|
|
|
|
"sysadmin": "test_3", |
|
|
|
|
"president": ["test1"], |
|
|
|
|
"vice-president": ["test2"], |
|
|
|
|
"sysadmin": ["test3"], |
|
|
|
|
}}, |
|
|
|
|
] |
|
|
|
|
assert data == expected |
|
|
|
|
# make sure execs were added to exec group |
|
|
|
|
status, data = client.get('/api/groups/exec') |
|
|
|
|
assert status == 200 |
|
|
|
|
expected = ['test_1', 'test_2', 'test_3'] |
|
|
|
|
expected = ['test1', 'test2', 'test3'] |
|
|
|
|
assert sorted([item['uid'] for item in data['members']]) == expected |
|
|
|
|
# make sure execs were subscribed to mailing lists |
|
|
|
|
addresses = [f'{uid}@{base_domain}' for uid in expected] |
|
|
|
@ -72,20 +72,33 @@ def test_set_positions(cfg, client, g_admin_ctx, mock_mailman_server): |
|
|
|
|
assert sorted(mock_mailman_server.subscriptions[mailing_list]) == addresses |
|
|
|
|
|
|
|
|
|
_, data = client.post('/api/positions', json={ |
|
|
|
|
'president': 'test_1', |
|
|
|
|
'vice-president': 'test_2', |
|
|
|
|
'sysadmin': 'test_2', |
|
|
|
|
'treasurer': 'test_4', |
|
|
|
|
'president': 'test1', |
|
|
|
|
'vice-president': 'test2', |
|
|
|
|
'sysadmin': 'test2', |
|
|
|
|
'treasurer': 'test4', |
|
|
|
|
}) |
|
|
|
|
assert data[-1]['status'] == 'completed' |
|
|
|
|
# make sure old exec was removed from group |
|
|
|
|
expected = ['test_1', 'test_2', 'test_4'] |
|
|
|
|
expected = ['test1', 'test2', 'test4'] |
|
|
|
|
_, data = client.get('/api/groups/exec') |
|
|
|
|
assert sorted([item['uid'] for item in data['members']]) == expected |
|
|
|
|
# make sure old exec was removed from mailing lists |
|
|
|
|
addresses = [f'{uid}@{base_domain}' for uid in expected] |
|
|
|
|
for mailing_list in mailing_lists: |
|
|
|
|
assert sorted(mock_mailman_server.subscriptions[mailing_list]) == addresses |
|
|
|
|
|
|
|
|
|
# multiple users per position |
|
|
|
|
status, data = client.post('/api/positions', json={ |
|
|
|
|
'president': 'test1', |
|
|
|
|
'vice-president': ['test2', 'test3'], |
|
|
|
|
'sysadmin': 'test2, test3,test4', |
|
|
|
|
}) |
|
|
|
|
assert status == 200 |
|
|
|
|
assert data[-1] == {'status': 'completed', 'result': { |
|
|
|
|
'president': ['test1'], |
|
|
|
|
'vice-president': ['test2', 'test3'], |
|
|
|
|
'sysadmin': ['test2', 'test3', 'test4'], |
|
|
|
|
}} |
|
|
|
|
finally: |
|
|
|
|
with g_admin_ctx(): |
|
|
|
|
for user in users: |
|
|
|
|