def integration_test_profile(runner): """Creates a temporary profile to use for executing integration tests.""" host = os.environ.get("C42_HOST") or "http://127.0.0.1:4200" username = os.environ.get("C42_USER") or "*****@*****.**" password = os.environ.get("C42_PW") or "test_password" delete_test_profile = split_command(f"profile delete {TEST_PROFILE_NAME} -y") create_test_profile = split_command( f"profile create -n {TEST_PROFILE_NAME} -u {username} -s {host} --password {password} -y" ) runner.invoke(cli, delete_test_profile) result = runner.invoke(cli, create_test_profile) if result.exit_code != 0: pytest.exit(result.output) yield runner.invoke(cli, delete_test_profile)
def test_security_data_send_to_udp_return_success_return_code( runner, integration_test_profile, udp_dataserver): begin_date = datetime.utcnow() - timedelta(days=20) begin_date_str = begin_date.strftime("%Y-%m-%d") command = append_profile( f"security-data send-to localhost:5141 -p UDP -b '{begin_date_str}'") result = runner.invoke(cli, split_command(command)) assert result.exit_code == 0
def edit_notes(args, notes_paths): """ Actually calls user-preferred editor with specified note(s). """ if args.terminal: cmd = split_command(args.terminal_editor) else: cmd = split_command(args.editor) popen_kwargs = { "stdin": None, "stdout": None, "stderr": None, "close_fds": True } cmd += list(notes_paths) logging.debug("executing '%s'", ' '.join(cmd)) sub_process = Popen(cmd, **popen_kwargs) if args.terminal or args.wait: sub_process.wait()
def test_security_data_send_to_udp_return_success_return_code( runner, integration_test_profile, udp_dataserver): command = append_profile( f"security-data send-to localhost:5141 -p UDP -b '{begin_date_str}'") result = runner.invoke(cli, split_command(command)) assert result.exit_code == 0
def test_auditlogs_send_to_tcp_command_returns_success_return_code( runner, integration_test_profile, tcp_dataserver): command = append_profile( f"audit-logs send-to localhost:5140 -p TCP -b '{begin_date_str}'") result = runner.invoke(cli, split_command(command)) assert result.exit_code == 0
def run_command(command, dir=None): print(f'Excuting command: {command}\n') process = Popen(split_command(command), cwd=dir, bufsize=-1) process.wait()
def assert_test_is_successful(runner, command): result = runner.invoke(cli, split_command(command)) assert result.exit_code == 0