Guides: procedures written and read inside ShopDB
This commit is contained in:
@@ -266,3 +266,75 @@ def test_an_ip_search_links_to_the_matched_subnet(client, subnetrow):
|
||||
assert len(rows) == 1
|
||||
assert rows[0]['id'] == subnetrow
|
||||
assert rows[0]['url'] == f'/networks/{subnetrow}'
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Guides. A guide is not an asset either, so the generic asset search cannot see
|
||||
# one - and the draft rule makes the omission worse than invisibility: a
|
||||
# half-written procedure reachable through the search box is one somebody
|
||||
# follows.
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
@pytest.fixture
|
||||
def guides(db):
|
||||
"""One published guide and one draft, with distinctive text.
|
||||
|
||||
The published one carries its distinguishing words in the BODY, not the
|
||||
title, because that is how people look for a procedure - by something
|
||||
written halfway down it.
|
||||
"""
|
||||
from plugins.guides.models import Guide
|
||||
from plugins.guides.services import authoring
|
||||
|
||||
published = Guide(title='Zzmarker controller swap', slug='zzmarker-swap',
|
||||
status='draft')
|
||||
draft = Guide(title='Zzdraft unfinished procedure', slug='zzdraft-unfinished',
|
||||
status='draft')
|
||||
db.session.add_all([published, draft])
|
||||
db.session.flush()
|
||||
|
||||
authoring.save(published, title=published.title,
|
||||
summary='Restoring after a swap', tags='zztelesis, zzbackups',
|
||||
blocks=[{'id': 'g1', 'type': 'paragraph',
|
||||
'text': 'Check the zzmappeddrive before starting.'}])
|
||||
authoring.publish(published)
|
||||
authoring.save(draft, title=draft.title, summary='', tags='zztelesis',
|
||||
blocks=[{'id': 'g2', 'type': 'paragraph',
|
||||
'text': 'Half written zzmappeddrive notes.'}])
|
||||
db.session.commit()
|
||||
return {'published': published.guideid, 'draft': draft.guideid}
|
||||
|
||||
|
||||
def test_a_published_guide_is_found_by_title(client, guides):
|
||||
rows = [r for r in search(client, 'Zzmarker') if r['type'] == 'guide']
|
||||
assert len(rows) == 1
|
||||
assert rows[0]['id'] == guides['published']
|
||||
assert rows[0]['url'] == '/guides/zzmarker-swap'
|
||||
|
||||
|
||||
def test_a_guide_is_found_by_tag(client, guides):
|
||||
"""Tags are how a technician narrows to a family of procedures."""
|
||||
assert 'Zzmarker controller swap' in titles(client, 'zzbackups', 'guide')
|
||||
|
||||
|
||||
def test_a_guide_is_found_by_words_in_its_body(client, guides):
|
||||
"""People search for what they remember reading, not for the title.
|
||||
|
||||
The body is stored as a JSON blob of blocks, so this is the check that the
|
||||
blob is actually reachable rather than merely present.
|
||||
"""
|
||||
assert 'Zzmarker controller swap' in titles(client, 'zzmappeddrive', 'guide')
|
||||
|
||||
|
||||
def test_a_draft_guide_is_never_returned(client, guides):
|
||||
"""The draft rule has to hold on EVERY path that reaches the row.
|
||||
|
||||
A draft is deliberately invisible to readers, and search is where that rule
|
||||
would otherwise leak: somebody finds a half-written procedure through the
|
||||
search box and follows it. The draft here shares a tag and a body word with
|
||||
the published guide, so it would ride along on both queries if the filter
|
||||
were missing.
|
||||
"""
|
||||
assert 'Zzdraft unfinished procedure' not in titles(client, 'zzmappeddrive', 'guide')
|
||||
assert 'Zzdraft unfinished procedure' not in titles(client, 'zztelesis', 'guide')
|
||||
assert titles(client, 'Zzdraft', 'guide') == []
|
||||
|
||||
Reference in New Issue
Block a user