Files
devplacepy/tests/api/game/farm.py
T
retoor ebf6bf7f82 feat: add Code Farm cooperative idle game with plot-based crop system and pub/sub notifications
Implement a Farmville-style cooperative idle game mounted at `/game` with member-only play and public farm viewing. The data layer is pure and timestamp-driven with no background tick: plot states are derived from `ready_at` vs current time, never stored. Key features include plantable software projects (shell script through kernel) that build over real time, harvest for coins and XP, CI tier upgrades for faster builds, plot purchasing with doubling cost, watering mechanics for friends' builds, daily quests, and prestige system. All game endpoints negotiate HTML or JSON and return full farm state for single-request client refresh. Pub/sub notifications broadcast farm updates on `public.game.farm.{username}` topics. Database schema adds `game_farms`, `game_plots`, and `game_quests` tables with appropriate indexes.
2026-06-22 16:41:53 +00:00

53 lines
1.8 KiB
Python

# retoor <retoor@molodetz.nl>
import requests
from devplacepy.services.game import store
from tests.api.game.index import JSON, _reset_farm, _signup
from tests.conftest import BASE_URL
def test_view_farm_public_json(app_server, seeded_db):
_reset_farm("alice_test")
response = requests.get(f"{BASE_URL}/game/farm/alice_test", headers=JSON)
assert response.status_code == 200
assert response.json()["farm"]["owner_username"] == "alice_test"
def test_view_unknown_farm_returns_404(app_server, seeded_db):
response = requests.get(f"{BASE_URL}/game/farm/nobody_xyz", headers=JSON)
assert response.status_code == 404
def test_water_requires_auth(app_server, seeded_db):
response = requests.post(
f"{BASE_URL}/game/farm/alice_test/water", data={"slot": 0}, headers=JSON
)
assert response.status_code == 401
def test_water_neighbour_build(app_server, seeded_db):
alice = _reset_farm("alice_test")
store.plant({"uid": alice["uid"], "username": "alice_test"}, 0, "python")
session, _ = _signup()
response = session.post(
f"{BASE_URL}/game/farm/alice_test/water", data={"slot": 0}, headers=JSON
)
assert response.status_code == 200
assert response.json()["farm"]["plots"][0]["watered_count"] == 1
def test_water_own_build_returns_400(app_server, seeded_db):
alice = _reset_farm("alice_test")
store.plant({"uid": alice["uid"], "username": "alice_test"}, 0, "python")
session = requests.Session()
session.post(
f"{BASE_URL}/auth/login",
data={"email": "alice@test.devplace", "password": "secret123"},
allow_redirects=True,
)
response = session.post(
f"{BASE_URL}/game/farm/alice_test/water", data={"slot": 0}, headers=JSON
)
assert response.status_code == 400