import uuid import pytest def unique(prefix): return f"{prefix}-{uuid.uuid4().hex[:8]}" def new_id(resp): """Id of a created record: replies are {"": record} or a record with "id".""" data = resp.json() if "id" in data and not isinstance(data["id"], dict): return str(data["id"]) return str(next(iter(data))) def find_id_by_field(listing, field, value): for obj_id, data in listing.items(): if isinstance(data, dict) and data.get(field) == value: return str(obj_id) raise AssertionError(f"Could not find id for {field}={value!r}") def missing(feature): """Mark a test for v1 behaviour v2 does not have yet; strict, so it fails once the feature lands.""" return pytest.mark.xfail(strict=True, reason=f"v2: {feature} not implemented")