Exemplo n.º 1
0
    def test_delete(self, config, db_session):
        config.include("kotti.rest")

        parent = Document(name="parent")
        child = Document(name="child")
        parent["child"] = child

        req = self._make_request(config, REQUEST_METHOD="DELETE")
        req.body = json.dumps({"data": {"id": "child", "type": "Document"}})

        db_session.add(parent)

        view = self._get_view(child, req)

        assert "child" in parent.keys()
        resp = view(child, req)
        assert resp.status == "204 No Content"
        assert "child" not in parent.keys()
Exemplo n.º 2
0
    def test_put(self, config):

        config.include("kotti.rest")

        req = self._make_request(config, REQUEST_METHOD="PUT")
        req.body = json.dumps(
            {"data": {"type": "Document", "attributes": {"title": u"Title here", "body": u"Body here"}}}
        )
        doc = Document(name="parent")
        view = self._get_view(doc, req)
        resp = view(doc, req)
        data = resp.json_body["data"]

        assert resp.status == "201 Created"
        assert data["attributes"]["title"] == u"Title here"
        assert data["id"] == "title-here"
        assert doc.keys() == ["title-here"]
Exemplo n.º 3
0
    def test_put(self, config):
        config.include('kotti.rest')
        req = self._make_request(config, REQUEST_METHOD='PUT')
        req.body = json.dumps({
            'data': {
                'type': 'Document',
                'attributes': {
                    'title': u"Title here",
                    'body': u"Body here"
                }
            }
        })
        doc = Document(name='parent')
        view = self._get_view(doc, req)
        data = view(doc, req).json_body['data']

        assert data['attributes']['title'] == u'Title here'
        assert data['id'] == 'title-here'

        assert doc.keys() == ['title-here']