-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackend.py
More file actions
22 lines (16 loc) · 824 Bytes
/
Copy pathbackend.py
File metadata and controls
22 lines (16 loc) · 824 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
"""A fake HTTP-ish backend that serves articles in pages and logs each fetch.
The fetch log is the point: tests (and the demo) read it to *prove* the
client fetched only the pages iteration actually consumed.
"""
from __future__ import annotations
class FakeBackend:
"""Serves ``articles`` in pages of ``page_size``; records every request."""
def __init__(self, articles: list[str], page_size: int = 10) -> None:
self._articles = list(articles)
self._page_size = page_size
self.fetch_log: list[int] = []
def fetch(self, page_number: int) -> list[str]:
"""One page of articles; empty past the end. Every call is logged."""
self.fetch_log.append(page_number)
start = page_number * self._page_size
return self._articles[start : start + self._page_size]