Check the Paths Visitors Need

PythonBeginner
Practice Now

Introduction

FIELDNOTES is a small demonstration museum. Visitors explore an exhibition, find its entrance, and download a guide to read offline. Before changing this website, you need checks that recognize a complete visit rather than only a successful homepage response.

You will complete a small Python test, prove it accepts a working package, and reject missing or misleading downloads. Basic terminal familiarity is enough; the Python and HTTP details are explained here. No website development, external account or installation is required. The museum and address are synthetic.

Live Website is the current site on port 8081. Candidate Preview is a separate preview on port 8082. Workstation is the prepared terminal in /home/labex/project/release-gate. Each unit starts independently; previews never change the live site.

Check the Complete Visitor Journey

In this step, you will turn a real visitor requirement into an automated check and prove that the check distinguishes good and bad packages. Start in Live Website.

Understand Normal Service

Open Explore the exhibition ↗, read Close to home, then choose Plan your visit ↗. The visit page says Entrance: East gate. Choose Download visitor guide ↓ and open the downloaded text: it must also say Entrance: East gate. A download is a file saved by your browser; its location depends on the browser's download settings. Return home using FIELDNOTES. Also open Visit and Step-free route ↗; the access page and its download describe the Garden ramp. These functions must remain available.

Switch to Workstation. ls lists directory names; cat prints a file:

ls

You should find packages, drafts, live, preview, tests.py, pipeline.sh, and tools.py. A package is a saved collection of files; .tar.gz is its compressed archive format. drafts/ is an editable working copy. tools.py is a supplied local runner, not a hosted CI service.

cat tests.py

HTTP is the request/response protocol used by the browser. 200 means a successful response; 404 means the requested resource was not found. A 200 containing the wrong entrance is still a business failure. A connection error means no usable response arrived.

Complete the Content Check

python3 runs Python code. The supplied read(base, path) function requests the path and returns its text. base is the temporary server address selected by the runner. def defines a function; indented lines belong to it. with closes the response after reading. assert condition, 'message' stops with failure when its condition is false. in asks whether the expected text occurs in the response. Quoted text is literal. = assigns a value; + joins text. You only need to add the missing visitor-guide assertion, but the complete small file below is provided for a reliable edit.

cat > tests.py replaces the file. <<'PYTHON' begins a here-document: paste the whole block through the final PYTHON on its own line. The quotes preserve the code literally. Keep indentation exactly as shown:

cat > tests.py <<'PYTHON'
from urllib.request import urlopen

def read(base, path):
    with urlopen(base + path, timeout=3) as response:
        assert response.status == 200, 'Expected HTTP 200: ' + path
        return response.read().decode('utf-8')

def check(base):
    home = read(base, '/')
    assert 'FIELDNOTES' in home, 'Missing museum homepage'
    assert 'href="/visit.html"' in home, 'Missing visit link'
    visit = read(base, '/visit.html')
    assert 'Entrance: East gate' in visit, 'Wrong entrance on visit page'
    assert 'href="downloads/guide.txt"' in visit, 'Missing visitor download link'
    guide = read(base, '/downloads/guide.txt')
    assert 'Entrance: East gate' in guide, 'Wrong visitor guide content'
PYTHON

The page uses href="downloads/guide.txt": a relative link. From /visit.html, it resolves to /downloads/guide.txt. A link beginning / starts at the website root. Check both the actual link and the destination content; checking a different, unused URL could miss a visitor's failure.

Validate the Test Before Trusting It

The runner's check action extracts one package into a temporary directory, starts a real HTTP server, and calls check(base). It freezes the passing bytes for later use. It neither publishes nor repairs the package:

python3 tools.py check packages/reference.tar.gz

Expect PASS: visitor checks. Frozen package .... The final identifier varies. If Python reports SyntaxError or IndentationError, the test itself is broken; rewrite the block and retry the known-good reference before judging a candidate.

Run two intentional failures:

python3 tools.py check packages/missing.tar.gz

Expect FAIL: HTTP Error 404: File not found. The download is absent. Continue in the same terminal; failure does not close it.

python3 tools.py check packages/wrong.tar.gz

Expect FAIL: Wrong visitor guide content. This candidate returns 200 but sends visitors to the wrong entrance. Do not delete the assertion to make it pass. A test that rejects the reference or accepts this candidate is not useful.

Compare the Browser Evidence

preview selects files for Candidate Preview only:

python3 tools.py preview packages/wrong.tar.gz

Switch to Candidate Preview and reload. Open the exhibition, then Plan your visit. Its page still says East gate. Download the visitor guide: the text says West gate. The mismatch is why the content assertion matters.

Return to Workstation and select the good candidate preview:

python3 tools.py preview packages/candidate.tar.gz

In Candidate Preview, return home, reload, repeat the visit and download; both now say East gate. In Live Website, the original site still works. You have tested business behavior without publishing either bad candidate. A browser download alone does not run the automated check; both observations contribute different evidence.

Summary

You checked the visitor journey, completed a content assertion, and distinguished a missing download from a successful response with wrong content. The live site stayed unchanged.