from pathlib import Path from dataclasses import replace import grp import os import shutil import sys import pytest from aim_webgui.config import Settings from aim_webgui.auth.service import Auth @pytest.fixture def core_root(tmp_path): source=os.environ.get('AIM_TEST_CORE_ROOT') if not source: pytest.skip('Set AIM_TEST_CORE_ROOT to the extracted unmodified AIM 3.3.0rc8 source bundle.') root=tmp_path/'core' shutil.copytree(source,root,ignore=shutil.ignore_patterns('__pycache__','*.pyc')) config=root/'scripts/aim.yml' config.write_text(f'root_dir: {root}\nservice_user: svc_bf-ansible\nrequired_group: {grp.getgrgid(os.getegid()).gr_name}\naddons:\n execution_enabled: true\n') customer=root/'inventories/example';customer.mkdir(parents=True) (customer/'hosts.yml').write_text('''all: children: example: children: linux: children: lab: hosts: test01.example: ansible_host: 192.0.2.1 windows: hosts: win01.example: ansible_host: 192.0.2.2 ''') (customer/'group_vars/all').mkdir(parents=True) (customer/'group_vars/linux/.ssh').mkdir(parents=True) return root @pytest.fixture def settings(tmp_path,core_root): return Settings(aim_scripts=core_root/'scripts', state_dir=tmp_path/'state', core_transport='stdio',core_command=(sys.executable,str(core_root/'scripts/aimctl.py')), core_config=core_root/'scripts/aim.yml',host='127.0.0.1',public_url='https://aim.example.test', execution_enabled=True,execution_playbooks=('debug_test_connection','debug_detect_host_roles'), execution_require_approval=False,execution_transport_verified=True,credentials_enabled=True).validate() @pytest.fixture def auth(settings): a=Auth(settings);a.bootstrap() with a.store.transaction() as db: db.execute("UPDATE users SET must_change_password=0 WHERE username='admin'") return a @pytest.fixture def admin(auth): with auth.store.read() as db:return db.execute("SELECT id FROM users WHERE username='admin'").fetchone()[0]