def test_resolve_loop(): included = { ("people", "1"): { "name": "Jean", "father": { "type": "people", "id": "2" }, }, ("people", "2"): { "name": "Luc", "son": { "type": "people", "id": "1" }, }, } data = {"title": "Article 1", "author": {"type": "people", "id": "1"}} doc = json_api_doc._resolve(data, included, set()) assert doc == { "title": "Article 1", "author": { "name": "Jean", "father": { "name": "Luc", "son": { "type": "people", "id": "1" } } } }
def test_resolve_nested(): included = { ("people", "9"): { "name": "Jean", "address": { "type": "location", "id": "2" }, }, ("location", "2"): { "street": "boulevard magenta", "city": { "type": "city", "id": "3" } }, ("city", "3"): { "name": "Paris" } } data = {"title": "Article 1", "author": {"type": "people", "id": "9"}} doc = json_api_doc._resolve(data, included, set()) assert doc == { "title": "Article 1", "author": { "name": "Jean", "address": { "street": "boulevard magenta", "city": { "name": "Paris" } } } }
def test_resolve_list_missing_items(): included = {} data = { "title": "Article 1", "authors": [ { "type": "people", "id": "9" }, { "type": "people", "id": "10" }, ] } doc = json_api_doc._resolve(data, included, set()) assert doc == { "title": "Article 1", "authors": [{ "id": "9", "type": "people" }, { "id": "10", "type": "people" }] }
def test_resolve_list(): included = { ("people", "9"): { "name": "Jean" }, ("people", "10"): { "name": "Luc" } } data = { "title": "Article 1", "authors": [ { "type": "people", "id": "9" }, { "type": "people", "id": "10" }, ] } doc = json_api_doc._resolve(data, included, set()) assert doc == { "title": "Article 1", "authors": [ { "name": "Jean" }, { "name": "Luc" }, ] }
def test_resolve_missing(): included = {} data = {"title": "Article 1", "author": {"type": "people", "id": "9"}} doc = json_api_doc._resolve(data, included, set()) assert doc == { "title": "Article 1", "author": { "type": "people", "id": "9" } }
def test_resolve_with_meta(): included = {("people", "9"): {"name": "Jean"}} data = { "title": "Article 1", "author": { "type": "people", "id": "9", "meta": { "index": 3 } } } doc = json_api_doc._resolve(data, included, set()) assert doc == { "title": "Article 1", "author": { "name": "Jean", "meta": { "index": 3 } } }
def test_resolve(): included = {("people", "9"): {"name": "Jean"}} data = {"title": "Article 1", "author": ("people", "9")} doc = json_api_doc._resolve(data, included, set()) assert doc == {"title": "Article 1", "author": {"name": "Jean"}}