|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +import json |
| 4 | +from typing import TYPE_CHECKING |
| 5 | + |
| 6 | +if TYPE_CHECKING: |
| 7 | + from type_aliases import ConnDB |
| 8 | + |
| 9 | + |
| 10 | +def test_to_json_string_param_roundtrip(conn_db_empty: ConnDB) -> None: |
| 11 | + """to_json() with a JSON string parameter should store the parsed object, not a string literal.""" |
| 12 | + conn, _ = conn_db_empty |
| 13 | + conn.execute( |
| 14 | + """ |
| 15 | + INSTALL json; |
| 16 | + LOAD json; |
| 17 | + CREATE NODE TABLE User (id SERIAL PRIMARY KEY, meta JSON); |
| 18 | + """ |
| 19 | + ) |
| 20 | + |
| 21 | + data = { |
| 22 | + "id": "http://localhost:8000/actors/testuser", |
| 23 | + "ap_data": { |
| 24 | + "id": "http://localhost:8000/actors/testuser", |
| 25 | + "type": "Person", |
| 26 | + "name": "", |
| 27 | + "summary": "", |
| 28 | + "username": "testuser", |
| 29 | + "inbox": "http://localhost:8000/actors/testuser/inbox", |
| 30 | + "outbox": "http://localhost:8000/actors/testuser/outbox", |
| 31 | + "public_key": { |
| 32 | + "id": "http://localhost:8000/actors/testuser#main-key", |
| 33 | + "owner": "http://localhost:8000/actors/testuser", |
| 34 | + "public_key_pem": ( |
| 35 | + "-----BEGIN PUBLIC KEY-----\n" |
| 36 | + "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAni2p5Ni2mVmHKFlOFA5w\n" |
| 37 | + "zBLTZS3cEdiQ/IBqeSKYcKU4TFEhaFaVy3Be4pL+vFwX+iEXpvAznEhaC6oTU2zC\n" |
| 38 | + "EaXFhmVInsZ3kzrz2vTeXsOIwJ4auR8fFziwewXYXUgT0/KmSlNaYMz1PbXxPS+P\n" |
| 39 | + "DHL7E6ovJSau8Hj7UMDpF6W0Xty8PoU/Kw9Fyt3SXBHz6h5hvNXTiqS2HxWDbtz/\n" |
| 40 | + "j5tZlpvxiZ/sFN2w/bsotlbe2QOF5HuLA/w7B3E1Tan8jLNO4qXEHffdUZEl92ad\n" |
| 41 | + "dqnhsH9MJbRp6YfNnRMd1NaHu+rDUjTur34r5oVEz766oU/ZnGlGpJsvaQmUiMW8\n" |
| 42 | + "XQIDAQAB\n" |
| 43 | + "-----END PUBLIC KEY-----\n" |
| 44 | + ), |
| 45 | + }, |
| 46 | + "manually_approve_followers": False, |
| 47 | + "@context": [ |
| 48 | + "https://www.w3.org/ns/activitystreams", |
| 49 | + "https://w3id.org/security/v1", |
| 50 | + {"manuallyApprovesFollowers": "as:manuallyApprovesFollowers"}, |
| 51 | + ], |
| 52 | + }, |
| 53 | + "is_local": True, |
| 54 | + "created_at": "2026-02-25T00:54:29.987623Z", |
| 55 | + } |
| 56 | + |
| 57 | + response = conn.execute( |
| 58 | + """ |
| 59 | + CREATE (n:User {meta: to_json($meta)}) |
| 60 | + RETURN n.id as id, cast(n.meta AS STRING) as meta; |
| 61 | + """, |
| 62 | + parameters={"meta": json.dumps(data)}, |
| 63 | + ) |
| 64 | + |
| 65 | + response_data = json.loads(response.rows_as_dict().get_all()[0]["meta"]) |
| 66 | + assert response_data == data |
0 commit comments