def test_error(monkeypatch, document): def mockreturn(method, url, headers): return MockResponse(b'{"_type": "error", "message": ["failed"]}') monkeypatch.setattr(requests, "request", mockreturn) with pytest.raises(coreapi.ErrorMessage): coreapi.action(document, ["next"])
def test_follow(monkeypatch, document): def mockreturn(method, url, headers): return MockResponse(b'{"_type": "document", "example": 123}') monkeypatch.setattr(requests, "request", mockreturn) doc = coreapi.action(document, ["next"]) assert doc == {"example": 123}
def test_keys_should_access_a_link(doc): with pytest.raises(LinkLookupError): action(doc, "dict")
def test_keys_should_be_valid_indexes(doc): with pytest.raises(LinkLookupError): action(doc, "dummy")
def test_keys_should_be_a_list_of_strings_or_ints(doc): with pytest.raises(TypeError): action(doc, ["nested", {}])
def test_keys_should_be_a_list_or_string(doc): with pytest.raises(TypeError): action(doc, True)