diff --git a/app/routes.py b/app/routes.py index 2205d27..3e6c53e 100644 --- a/app/routes.py +++ b/app/routes.py @@ -380,9 +380,10 @@ def search(): elif search_util.widget == 'calculator' and not 'nojs' in request.args: response = add_calculator_card(html_soup) - # Update tabs content + # Update tabs content (fallback to the raw query if full_query isn't set) + full_query_val = getattr(search_util, 'full_query', query) tabs = get_tabs_content(app.config['HEADER_TABS'], - search_util.full_query, + full_query_val, search_util.search_type, g.user_config.preferences, translation) diff --git a/test/test_alts.py b/test/test_alts.py index e017a43..e18fdaf 100644 --- a/test/test_alts.py +++ b/test/test_alts.py @@ -3,6 +3,7 @@ import os from bs4 import BeautifulSoup +from app import app from app.filter import Filter from app.models.config import Config from app.utils.session import generate_key @@ -15,7 +16,8 @@ def build_soup(html: str): def make_filter(soup: BeautifulSoup): secret_key = generate_key() - cfg = Config(**{'alts': True}) + with app.app_context(): + cfg = Config(**{'alts': True}) f = Filter(user_key=secret_key, config=cfg) f.soup = soup return f @@ -99,7 +101,9 @@ def test_single_pass_description_replacement(monkeypatch): assert a['href'].startswith('https://nitter.example') # Ensure description got host swapped once, no double scheme or duplication - text = soup.find('div').get_text() + main_div = soup.find('div', id='main') + # The description div is the first inner div under #main in this fixture + text = main_div.find_all('div')[0].get_text().strip() assert text.startswith('https://nitter.example') assert 'https://https://' not in text assert 'nitter.examplenitter.example' not in text diff --git a/test/test_autocomplete_xml.py b/test/test_autocomplete_xml.py index b0f36f7..307fb25 100644 --- a/test/test_autocomplete_xml.py +++ b/test/test_autocomplete_xml.py @@ -1,3 +1,4 @@ +from app import app from app.request import Request from app.models.config import Config @@ -21,7 +22,8 @@ class FakeHttpClient: def test_autocomplete_parsing(): - cfg = Config(**{}) + with app.app_context(): + cfg = Config(**{}) req = Request(normal_ua='UA', root_path='http://localhost:5000', config=cfg, http_client=FakeHttpClient()) suggestions = req.autocomplete('who') assert 'whoogle' in suggestions diff --git a/test/test_tor.py b/test/test_tor.py index a764d6d..1a74819 100644 --- a/test/test_tor.py +++ b/test/test_tor.py @@ -1,5 +1,6 @@ import pytest +from app import app from app.request import Request, TorError from app.models.config import Config @@ -26,18 +27,24 @@ class FakeHttpClient: def build_config(tor: bool) -> Config: # Minimal config with tor flag - return Config(**{'tor': tor}) + with app.app_context(): + return Config(**{'tor': tor}) -def test_tor_validation_success(): +def test_tor_validation_success(monkeypatch): + # Prevent real Tor signal attempts + monkeypatch.setattr('app.request.send_tor_signal', lambda signal: True) cfg = build_config(tor=True) req = Request(normal_ua='TestUA', root_path='http://localhost:5000', config=cfg, http_client=FakeHttpClient(tor_ok=True)) + # Avoid sending a Tor NEWNYM/HEARTBEAT in unit tests by setting attempt>0 false path resp = req.send(base_url='https://example.com', query='') assert req.tor_valid is True assert resp.status_code == 200 -def test_tor_validation_failure(): +def test_tor_validation_failure(monkeypatch): + # Prevent real Tor signal attempts + monkeypatch.setattr('app.request.send_tor_signal', lambda signal: True) cfg = build_config(tor=True) req = Request(normal_ua='TestUA', root_path='http://localhost:5000', config=cfg, http_client=FakeHttpClient(tor_ok=False)) with pytest.raises(TorError):