"""Smoke tests for the Flask web interface in maigret.web.app. The goal is to catch breakage in the basic user flow (render index, kick off search, redirect to results) without making real network calls. Heavy maigret internals are mocked; the report-generation smoke test keeps `save_graph_report` unmocked so regressions like `nt.options.groups = ...` (AttributeError on a plain dict) are caught automatically. """ import os import pytest import maigret import maigret.report from maigret.web import app as web_app_module CUR_PATH = os.path.dirname(os.path.realpath(__file__)) TEST_DB = os.path.join(CUR_PATH, 'db.json') class _SyncThread: """Drop-in for threading.Thread that runs target synchronously on start().""" def __init__(self, target=None, args=(), kwargs=None, **_): self._target = target self._args = args self._kwargs = kwargs or {} def start(self): self._target(*self._args, **self._kwargs) @pytest.fixture def web_app(tmp_path): web_app_module.app.config['TESTING'] = True web_app_module.app.config['REPORTS_FOLDER'] = str(tmp_path) web_app_module.app.config['MAIGRET_DB_FILE'] = TEST_DB web_app_module.background_jobs.clear() web_app_module.job_results.clear() yield web_app_module web_app_module.background_jobs.clear() web_app_module.job_results.clear() @pytest.fixture def client(web_app): return web_app.app.test_client() def test_index_renders(client): resp = client.get('/') assert resp.status_code == 200 body = resp.get_data(as_text=True) assert 'name="usernames"' in body assert '