From 846feb6e7e72c79c4de9f9dce00f21479aa2365f Mon Sep 17 00:00:00 2001 From: Soxoj <31013580+soxoj@users.noreply.github.com> Date: Tue, 5 May 2026 19:32:01 +0200 Subject: [PATCH] Add web interface tests (#2619) --- maigret/resources/db_meta.json | 4 +- tests/test_web.py | 172 +++++++++++++++++++++++++++++++++ 2 files changed, 174 insertions(+), 2 deletions(-) create mode 100644 tests/test_web.py diff --git a/maigret/resources/db_meta.json b/maigret/resources/db_meta.json index c2a24ca..d563902 100644 --- a/maigret/resources/db_meta.json +++ b/maigret/resources/db_meta.json @@ -1,7 +1,7 @@ { "version": 1, - "updated_at": "2026-05-05T11:30:38Z", - "sites_count": 3154, + "updated_at": "2026-05-05T17:17:59Z", + "sites_count": 3155, "min_maigret_version": "0.6.0", "data_sha256": "acf9d9fef8412bf05fa09d50c1ae363e5c8394597b1aaa3f98a9a1c4e31ca356", "data_url": "https://raw.githubusercontent.com/soxoj/maigret/main/maigret/resources/data.json" diff --git a/tests/test_web.py b/tests/test_web.py new file mode 100644 index 0000000..950327f --- /dev/null +++ b/tests/test_web.py @@ -0,0 +1,172 @@ +"""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 '