add unit test for positions and replace provideUtility() with getGlobalSiteManager().registerUtility() in unit tests
continuous-integration/drone/pr Build is failing
Details
continuous-integration/drone/pr Build is failing
Details
This commit is contained in:
parent
5bae89a9fd
commit
36def99b28
|
@ -0,0 +1,55 @@
|
||||||
|
from click.testing import CliRunner
|
||||||
|
from ceo.cli import cli
|
||||||
|
|
||||||
|
def test_positions(cli_setup):
|
||||||
|
runner = CliRunner()
|
||||||
|
|
||||||
|
# Setup test data
|
||||||
|
for i in range(5):
|
||||||
|
runner.invoke(cli, ['members', 'add', f'test_{i}', '--cn', f'Test {i}', '--program', 'Math', '--terms', '1' ], input='y\n')
|
||||||
|
runner.invoke(cli, ['groups', 'add', 'exec', '--description', 'Test Group'], input='y\n')
|
||||||
|
|
||||||
|
result = runner.invoke(cli, ['positions', 'set',
|
||||||
|
'--president', 'test_0',
|
||||||
|
'--vice-president', 'test_1',
|
||||||
|
'--sysadmin', 'test_2',
|
||||||
|
'--secretary', 'test_3',
|
||||||
|
'--webmaster', 'test_4',
|
||||||
|
], input='y\n')
|
||||||
|
|
||||||
|
assert result.exit_code == 0
|
||||||
|
assert result.output == \
|
||||||
|
'''
|
||||||
|
The positions will be updated:
|
||||||
|
president: test_0
|
||||||
|
vice_president: test_1
|
||||||
|
sysadmin: test_2
|
||||||
|
secretary: test_3
|
||||||
|
webmaster: test_4
|
||||||
|
treasurer:
|
||||||
|
cro:
|
||||||
|
librarian:
|
||||||
|
imapd:
|
||||||
|
offsck:
|
||||||
|
Do you want to continue? [y/N]: y
|
||||||
|
Update positions in LDAP... Done
|
||||||
|
Update executive group in LDAP... Done
|
||||||
|
Subscribe to mailing lists... Done
|
||||||
|
Transaction successfully completed.
|
||||||
|
'''[1:]
|
||||||
|
|
||||||
|
result = runner.invoke(cli, ['positions', 'get'])
|
||||||
|
assert result.exit_code == 0
|
||||||
|
assert result.output == \
|
||||||
|
'''
|
||||||
|
president: test_0
|
||||||
|
secretary: test_3
|
||||||
|
sysadmin: test_2
|
||||||
|
vice-president: test_1
|
||||||
|
webmaster: test_4
|
||||||
|
'''[1:]
|
||||||
|
|
||||||
|
# Cleanup test data
|
||||||
|
for i in range(5):
|
||||||
|
runner.invoke(cli, ['members', 'delete', f'test_{i}'], input='y\n')
|
||||||
|
runner.invoke(cli, ['groups', 'delete', 'exec'], input='y\n')
|
|
@ -51,7 +51,7 @@ def cfg(_drone_hostname_mock):
|
||||||
with importlib.resources.path('tests', 'ceod_test_local.ini') as p:
|
with importlib.resources.path('tests', 'ceod_test_local.ini') as p:
|
||||||
config_file = p.__fspath__()
|
config_file = p.__fspath__()
|
||||||
_cfg = Config(config_file)
|
_cfg = Config(config_file)
|
||||||
component.provideUtility(_cfg, IConfig)
|
component.getGlobalSiteManager().registerUtility(_cfg, IConfig)
|
||||||
return _cfg
|
return _cfg
|
||||||
|
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ def krb_srv(cfg):
|
||||||
else:
|
else:
|
||||||
principal = 'ceod/' + socket.getfqdn()
|
principal = 'ceod/' + socket.getfqdn()
|
||||||
krb = KerberosService(principal)
|
krb = KerberosService(principal)
|
||||||
component.provideUtility(krb, IKerberosService)
|
component.getGlobalSiteManager().registerUtility(krb, IKerberosService)
|
||||||
|
|
||||||
delete_test_princs(krb)
|
delete_test_princs(krb)
|
||||||
yield krb
|
yield krb
|
||||||
|
@ -160,7 +160,7 @@ def ldap_srv_session(cfg, krb_srv, ldap_conn):
|
||||||
conn.add(base_dn, 'organizationalUnit')
|
conn.add(base_dn, 'organizationalUnit')
|
||||||
|
|
||||||
_ldap_srv = LDAPService()
|
_ldap_srv = LDAPService()
|
||||||
component.provideUtility(_ldap_srv, ILDAPService)
|
component.getGlobalSiteManager().registerUtility(_ldap_srv, ILDAPService)
|
||||||
|
|
||||||
yield _ldap_srv
|
yield _ldap_srv
|
||||||
|
|
||||||
|
@ -180,7 +180,7 @@ def ldap_srv(ldap_srv_session, g_admin_ctx):
|
||||||
@pytest.fixture(scope='session')
|
@pytest.fixture(scope='session')
|
||||||
def file_srv(cfg):
|
def file_srv(cfg):
|
||||||
_file_srv = FileService()
|
_file_srv = FileService()
|
||||||
component.provideUtility(_file_srv, IFileService)
|
component.getGlobalSiteManager().registerUtility(_file_srv, IFileService)
|
||||||
members_home = cfg.get('members_home')
|
members_home = cfg.get('members_home')
|
||||||
clubs_home = cfg.get('clubs_home')
|
clubs_home = cfg.get('clubs_home')
|
||||||
|
|
||||||
|
@ -194,7 +194,7 @@ def file_srv(cfg):
|
||||||
@pytest.fixture(scope='session')
|
@pytest.fixture(scope='session')
|
||||||
def http_client(cfg):
|
def http_client(cfg):
|
||||||
_client = HTTPClient()
|
_client = HTTPClient()
|
||||||
component.provideUtility(_client, IHTTPClient)
|
component.getGlobalSiteManager().registerUtility(_client, IHTTPClient)
|
||||||
return _client
|
return _client
|
||||||
|
|
||||||
|
|
||||||
|
@ -210,7 +210,7 @@ def mock_mailman_server():
|
||||||
def mailman_srv(mock_mailman_server, cfg, http_client):
|
def mailman_srv(mock_mailman_server, cfg, http_client):
|
||||||
# TODO: test the RemoteMailmanService as well
|
# TODO: test the RemoteMailmanService as well
|
||||||
mailman = MailmanService()
|
mailman = MailmanService()
|
||||||
component.provideUtility(mailman, IMailmanService)
|
component.getGlobalSiteManager().registerUtility(mailman, IMailmanService)
|
||||||
return mailman
|
return mailman
|
||||||
|
|
||||||
|
|
||||||
|
@ -223,7 +223,7 @@ def uwldap_srv(cfg, ldap_conn):
|
||||||
|
|
||||||
conn.add(base_dn, 'organizationalUnit')
|
conn.add(base_dn, 'organizationalUnit')
|
||||||
_uwldap_srv = UWLDAPService()
|
_uwldap_srv = UWLDAPService()
|
||||||
component.provideUtility(_uwldap_srv, IUWLDAPService)
|
component.getGlobalSiteManager().registerUtility(_uwldap_srv, IUWLDAPService)
|
||||||
yield _uwldap_srv
|
yield _uwldap_srv
|
||||||
|
|
||||||
delete_subtree(conn, base_dn)
|
delete_subtree(conn, base_dn)
|
||||||
|
@ -240,21 +240,21 @@ def mock_mail_server():
|
||||||
@pytest.fixture(scope='session')
|
@pytest.fixture(scope='session')
|
||||||
def mail_srv(cfg, mock_mail_server):
|
def mail_srv(cfg, mock_mail_server):
|
||||||
_mail_srv = MailService()
|
_mail_srv = MailService()
|
||||||
component.provideUtility(_mail_srv, IMailService)
|
component.getGlobalSiteManager().registerUtility(_mail_srv, IMailService)
|
||||||
return _mail_srv
|
return _mail_srv
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='session')
|
@pytest.fixture(scope='session')
|
||||||
def mysql_srv(cfg):
|
def mysql_srv(cfg):
|
||||||
mysql_srv = MySQLService()
|
mysql_srv = MySQLService()
|
||||||
component.provideUtility(mysql_srv, IDatabaseService, 'mysql')
|
component.getGlobalSiteManager().registerUtility(mysql_srv, IDatabaseService, 'mysql')
|
||||||
return mysql_srv
|
return mysql_srv
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='session')
|
@pytest.fixture(scope='session')
|
||||||
def postgresql_srv(cfg):
|
def postgresql_srv(cfg):
|
||||||
psql_srv = PostgreSQLService()
|
psql_srv = PostgreSQLService()
|
||||||
component.provideUtility(psql_srv, IDatabaseService, 'postgresql')
|
component.getGlobalSiteManager().registerUtility(psql_srv, IDatabaseService, 'postgresql')
|
||||||
return psql_srv
|
return psql_srv
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue