Accept single snippet photos and derive post IDs from titles
This commit is contained in:
@@ -2,7 +2,7 @@ import io
|
||||
import json
|
||||
|
||||
from test_upload import AUTH, git, publisher, service
|
||||
from posts import content_similarity
|
||||
from posts import content_similarity, title_id
|
||||
|
||||
|
||||
BODY = "\n\n".join(f"Paragraph {i}: I walked beside the river and considered how memory changes our understanding of a place. The details matter more than the names we give them." for i in range(12))
|
||||
@@ -32,6 +32,7 @@ def test_content_update_preserves_url_date_and_no_duplicate(publisher, service,
|
||||
assert run().returncode == 0
|
||||
status = client.get(first.json["status_url"], headers=AUTH).json
|
||||
assert status["action"] == "created" and status["url"] == "/my-walk/"
|
||||
assert status["post_id"] == "my-walk"
|
||||
second = send(client, "# My revised walk\n\n" + BODY.replace("beside the river", "along the river", 1), "renamed.md")
|
||||
result = run()
|
||||
assert result.returncode == 0, result.stderr
|
||||
@@ -79,3 +80,25 @@ def test_similarity_requires_substantial_unambiguous_content():
|
||||
assert content_similarity("short shared title", "short shared title") == 0
|
||||
assert content_similarity(BODY, BODY.replace("river", "lake", 1)) >= 0.92
|
||||
assert content_similarity(BODY, "Completely unrelated writing.") == 0
|
||||
|
||||
|
||||
def test_title_derived_id_and_permalink(publisher):
|
||||
run, _, client = publisher
|
||||
response = send(client, "# My New_Post: Hello, World!\n\n" + BODY)
|
||||
assert run().returncode == 0
|
||||
state = client.get(response.json["status_url"], headers=AUTH).json
|
||||
assert state["post_id"] == "my-new-post-hello-world"
|
||||
assert state["url"] == "/my-new-post-hello-world/"
|
||||
assert title_id(" سفر به تهران! ") == "سفر-به-تهران"
|
||||
assert len(title_id("漢" * 100).encode()) <= 160
|
||||
|
||||
|
||||
def test_same_title_does_not_overwrite_unrelated_content(publisher):
|
||||
run, remote, client = publisher
|
||||
send(client, "# Shared title\n\n" + BODY)
|
||||
assert run().returncode == 0
|
||||
head = git(remote, "rev-parse", "master")
|
||||
response = send(client, "# Shared title\n\n" + "An unrelated essay about distant stars. " * 20)
|
||||
assert run().returncode != 0
|
||||
assert client.get(response.json["status_url"], headers=AUTH).json["status"] == "failed"
|
||||
assert git(remote, "rev-parse", "master") == head
|
||||
|
||||
Reference in New Issue
Block a user