示例#1
0
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"])
示例#2
0
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}
示例#3
0
def test_keys_should_access_a_link(doc):
    with pytest.raises(LinkLookupError):
        action(doc, "dict")
示例#4
0
def test_keys_should_be_valid_indexes(doc):
    with pytest.raises(LinkLookupError):
        action(doc, "dummy")
示例#5
0
def test_keys_should_be_a_list_of_strings_or_ints(doc):
    with pytest.raises(TypeError):
        action(doc, ["nested", {}])
示例#6
0
def test_keys_should_be_a_list_or_string(doc):
    with pytest.raises(TypeError):
        action(doc, True)