Exemple #1
0
    def test_delete(self):
        from papyrus.protocol import Protocol
        from geojson import Feature
        from pyramid.response import Response

        MappedClass = self._get_mapped_class()

        # a mock session specific to this test
        class MockSession(object):
            def query(self, mapped_class):
                return {'a': mapped_class(Feature())}

            def delete(self, obj):
                pass

        # a before_update callback
        def before_delete(request, obj):
            request._log = dict(obj=obj)

        proto = Protocol(MockSession,
                         MappedClass,
                         "geom",
                         before_delete=before_delete)
        request = testing.DummyRequest()
        response = proto.delete(request, 'a')
        self.assertTrue(isinstance(response, Response))
        self.assertEqual(response.status_int, 204)

        # test before_delete
        self.assertTrue(hasattr(request, '_log'))
        self.assertTrue(isinstance(request._log["obj"], MappedClass))
Exemple #2
0
    def test_delete(self):
        from papyrus.protocol import Protocol
        from geojson import Feature
        from pyramid.response import Response

        MappedClass = self._get_mapped_class()

        # a mock session specific to this test
        class MockSession(object):
            def query(self, mapped_class):
                return {'a': mapped_class(Feature())}

            def delete(self, obj):
                pass

        # a before_update callback
        def before_delete(request, obj):
            request._log = dict(obj=obj)

        proto = Protocol(MockSession, MappedClass, "geom",
                         before_delete=before_delete)
        request = testing.DummyRequest()
        response = proto.delete(request, 'a')
        self.assertTrue(isinstance(response, Response))
        self.assertEqual(response.status_int, 204)

        # test before_delete
        self.assertTrue(hasattr(request, '_log'))
        self.assertTrue(isinstance(request._log["obj"], MappedClass))
Exemple #3
0
    def test_delete_notfound(self):
        from papyrus.protocol import Protocol

        # a mock session specific to this test
        class MockSession(object):
            def query(self, mapped_class):
                return {}

        proto = Protocol(MockSession, self._get_mapped_class(), "geom")
        request = testing.DummyRequest()
        response = proto.delete(request, 1)
        self.assertEqual(response.status_int, 404)
Exemple #4
0
    def test_delete_forbidden(self):
        from papyrus.protocol import Protocol

        engine = self._get_engine()
        Session = self._get_session(engine)
        MappedClass = self._get_mapped_class()

        proto = Protocol(Session, MappedClass, "geom", readonly=True)
        request = testing.DummyRequest()
        response = proto.delete(request, 1)
        self.assertTrue(response.headers.get('Allow') == "GET, HEAD")
        self.assertEqual(response.status_int, 405)
Exemple #5
0
    def test_delete_notfound(self):
        from papyrus.protocol import Protocol

        # a mock session specific to this test
        class MockSession(object):
            def query(self, mapped_class):
                return {}

        proto = Protocol(MockSession, self._get_mapped_class(), "geom")
        request = testing.DummyRequest()
        response = proto.delete(request, 1)
        self.assertEqual(response.status_int, 404)
Exemple #6
0
    def test_delete_forbidden(self):
        from papyrus.protocol import Protocol

        engine = self._get_engine()
        Session = self._get_session(engine)
        MappedClass = self._get_mapped_class()

        proto = Protocol(Session, MappedClass, "geom", readonly=True)
        request = testing.DummyRequest()
        response = proto.delete(request, 1)
        self.assertTrue(response.headers.get('Allow') == "GET, HEAD")
        self.assertEqual(response.status_int, 405)