fix tests
continuous-integration/drone/pr Build is passing
Details
continuous-integration/drone/pr Build is passing
Details
This commit is contained in:
parent
1cd07c228c
commit
25b7412366
|
@ -1,11 +1,11 @@
|
|||
import pytest
|
||||
import os
|
||||
|
||||
from click.testing import CliRunner
|
||||
from ceo.cli import cli
|
||||
|
||||
from mysql.connector import connect
|
||||
from mysql.connector.errors import ProgrammingError
|
||||
import pytest
|
||||
|
||||
from ceo.cli import cli
|
||||
|
||||
|
||||
def mysql_attempt_connection(host, username, password):
|
||||
|
@ -26,12 +26,13 @@ def test_mysql(cli_setup, cfg, ldap_user):
|
|||
runner = CliRunner()
|
||||
|
||||
username = ldap_user.uid
|
||||
os.makedirs(ldap_user.home_directory)
|
||||
host = cfg.get("mysql_host")
|
||||
info_file_path = os.path.join(ldap_user.home_directory, "ceo-mysql-info")
|
||||
assert not os.path.isfile(info_file_path)
|
||||
|
||||
# create database for user
|
||||
result = runner.invoke(cli, ['mysql', 'create', username])
|
||||
result = runner.invoke(cli, ['mysql', 'create', username], input='y\n')
|
||||
assert result.exit_code == 0
|
||||
assert os.path.isfile(info_file_path)
|
||||
|
||||
|
@ -40,22 +41,24 @@ def test_mysql(cli_setup, cfg, ldap_user):
|
|||
with open(info_file_path, 'r') as file:
|
||||
old_info = file.read()
|
||||
|
||||
expected = f"""MySQL database created
|
||||
expected = f"""Are you sure you want to create a MySQL database for {username}? [y/N]: y
|
||||
MySQL database created.
|
||||
Connection Information:
|
||||
|
||||
Connection Information:
|
||||
Database: {username}
|
||||
Username: {username}
|
||||
Password: {passwd}
|
||||
Host: {host}
|
||||
|
||||
Database: {username}
|
||||
Username: {username}
|
||||
Password: {passwd}
|
||||
Host: {host}
|
||||
|
||||
Settings and more info has been written to {info_file_path}"""
|
||||
These settings have been written to {info_file_path}.
|
||||
"""
|
||||
|
||||
assert result.output == expected
|
||||
mysql_attempt_connection(host, username, passwd)
|
||||
|
||||
# perform password reset for user
|
||||
result = runner.invoke(cli, ['mysql', 'pwreset', username], input="y\n")
|
||||
# confirm once to reset password, another to overwrite the file
|
||||
result = runner.invoke(cli, ['mysql', 'pwreset', username], input="y\ny\n")
|
||||
assert result.exit_code == 0
|
||||
|
||||
response_arr = result.output.split()
|
||||
|
@ -76,3 +79,4 @@ def test_mysql(cli_setup, cfg, ldap_user):
|
|||
mysql_attempt_connection(host, username, passwd)
|
||||
|
||||
os.remove(info_file_path)
|
||||
os.rmdir(ldap_user.home_directory)
|
||||
|
|
|
@ -28,12 +28,13 @@ def test_postgresql(cli_setup, cfg, ldap_user):
|
|||
runner = CliRunner()
|
||||
|
||||
username = ldap_user.uid
|
||||
os.makedirs(ldap_user.home_directory)
|
||||
host = cfg.get("postgresql_host")
|
||||
info_file_path = os.path.join(ldap_user.home_directory, "ceo-psql-info")
|
||||
info_file_path = os.path.join(ldap_user.home_directory, "ceo-postgresql-info")
|
||||
assert not os.path.isfile(info_file_path)
|
||||
|
||||
# create database for user
|
||||
result = runner.invoke(cli, ['postgresql', 'create', username])
|
||||
result = runner.invoke(cli, ['postgresql', 'create', username], input='y\n')
|
||||
assert result.exit_code == 0
|
||||
assert os.path.isfile(info_file_path)
|
||||
|
||||
|
@ -42,22 +43,24 @@ def test_postgresql(cli_setup, cfg, ldap_user):
|
|||
with open(info_file_path, 'r') as file:
|
||||
old_info = file.read()
|
||||
|
||||
expected = f"""PostgreSQL database created
|
||||
expected = f"""Are you sure you want to create a PostgreSQL database for {username}? [y/N]: y
|
||||
PostgreSQL database created.
|
||||
Connection Information:
|
||||
|
||||
Connection Information:
|
||||
Database: {username}
|
||||
Username: {username}
|
||||
Password: {passwd}
|
||||
Host: {host}
|
||||
|
||||
Database: {username}
|
||||
Username: {username}
|
||||
Password: {passwd}
|
||||
Host: {host}
|
||||
|
||||
Settings and more info has been written to {info_file_path}"""
|
||||
These settings have been written to {info_file_path}.
|
||||
"""
|
||||
|
||||
assert result.output == expected
|
||||
psql_attempt_connection(host, username, passwd)
|
||||
|
||||
# perform password reset for user
|
||||
result = runner.invoke(cli, ['postgresql', 'pwreset', username], input="y\n")
|
||||
# confirm once to reset password, another to overwrite the file
|
||||
result = runner.invoke(cli, ['postgresql', 'pwreset', username], input="y\ny\n")
|
||||
assert result.exit_code == 0
|
||||
|
||||
response_arr = result.output.split()
|
||||
|
@ -78,3 +81,4 @@ def test_postgresql(cli_setup, cfg, ldap_user):
|
|||
psql_attempt_connection(host, username, passwd)
|
||||
|
||||
os.remove(info_file_path)
|
||||
os.rmdir(ldap_user.home_directory)
|
||||
|
|
Loading…
Reference in New Issue