Files
devplacepy/tests/api/sync/projects.py
T
retoorandClaude Sonnet 5.5 02ab747cd0
DevPlace CI / test (push) Failing after 44m45s
Code Farm: per-plot auto-replant pause and crop-lock check; community sync and node work
Continuous Delivery could never be turned off once a crop was planted. Add a
one-shot per-plot "stop after harvest" flag (POST /game/plot/stop, Devii tool
game_plot_stop, game_plots.stop_after_harvest), cleared by the next plant,
autoreplant claim or Refactor. Autoreplant now also respects crop locks through
the shared _crop_lock predicate. Plan and measurements in happyplanting.md.

Also includes the pending community sync, node network and related work in the
tree; the full suite passed (4999) with all of it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-17 02:23:43 +02:00

65 lines
3.7 KiB
Python

# retoor <retoor@molodetz.nl>
from devplacepy.database import get_table
from tests.api.sync.conftest import post_record, project_record, sync_ok, unique, user_record
def seed(client, admin, origin):
sync_ok(client, admin, "users", origin, [user_record("u1", unique("pj"))])
def test_a_project_is_created_public_writable_and_without_side_effects(client, admin, origin):
seed(client, admin, origin)
before = get_table("notifications").count()
body = sync_ok(client, admin, "projects", origin, [project_record("pr1", project_type="game", stars=99)])
result = body["results"][0]
assert result["status"] == "created" and result["ignored"] == ["stars"]
row = get_table("projects").find_one(uid=result["local_uid"])
assert (row["is_private"], row["read_only"], row["stars"], row["project_type"]) == (0, 0, 0, "game")
assert row["slug"].endswith("synced-project") and row["deleted_at"] is None
assert get_table("notifications").count() == before
def test_replay_edit_and_tombstone(client, admin, origin):
seed(client, admin, origin)
created = sync_ok(client, admin, "projects", origin, [project_record("pr1")])["results"][0]
assert sync_ok(client, admin, "projects", origin, [project_record("pr1")])["results"][0]["status"] == "unchanged"
edited = sync_ok(client, admin, "projects", origin, [project_record("pr1", title="Renamed", updated_at="2025-02-01T00:00:00Z")])["results"][0]
assert edited["status"] == "updated"
assert get_table("projects").find_one(uid=created["local_uid"])["title"] == "Renamed"
gone = sync_ok(client, admin, "projects", origin, [project_record("pr1", title="Renamed", updated_at="2025-03-01T00:00:00Z", deleted=True)])["results"][0]
assert gone["status"] == "updated"
row = get_table("projects").find_one(uid=created["local_uid"])
assert row["deleted_at"] and row["deleted_by"] == "sync"
def test_unknown_author_and_bad_input(client, admin, origin):
body = sync_ok(client, admin, "projects", origin, [project_record("pr1", "ghost"), project_record("pr2", title="")])
assert body["results"][0]["status"] == "deferred"
assert body["results"][1]["status"] == "rejected" and body["results"][1]["reason"] == "invalid"
def test_unknown_type_falls_back_and_urls_are_cleaned(client, admin, origin):
seed(client, admin, origin)
result = sync_ok(client, admin, "projects", origin, [project_record("pr1", project_type="quantum", website_url="not a url at all", repo_url="example.org/r")])["results"][0]
row = get_table("projects").find_one(uid=result["local_uid"])
assert row["project_type"] == "software" and row["website_url"] == "" and row["repo_url"].startswith("http")
def test_a_post_links_to_its_project_and_waits_for_it(client, admin, origin):
seed(client, admin, origin)
waiting = sync_ok(client, admin, "posts", origin, [post_record("p1", "u1", project_uid="pr1")])["results"][0]
assert waiting["status"] == "deferred" and waiting["reason"] == "unknown_project"
body = sync_ok(client, admin, "projects", origin, [project_record("pr1")])
assert body["released"] == {"created": 1}
post = get_table("posts").find_one(title=None, content="a synced post with enough content", user_uid=get_table("sync_links").find_one(origin=origin, kind="users", origin_uid="u1")["local_uid"])
project = get_table("sync_links").find_one(origin=origin, kind="projects", origin_uid="pr1")["local_uid"]
assert post["project_uid"] == project
def test_a_post_without_a_project_keeps_the_old_fingerprint(client, admin, origin):
seed(client, admin, origin)
sync_ok(client, admin, "posts", origin, [post_record("p1", "u1")])
again = sync_ok(client, admin, "posts", origin, [post_record("p1", "u1", project_uid=None)])["results"][0]
assert again["status"] == "unchanged"