Пример #1
0
    def assertXFluidDBHeaderForType(self, method, value, expectedTypeString):
        """
        Helper method to check if a resource is returning the appropriate
        C{X-FluidDB-Type} header for a given HTTP method.

        @param method: The HTTP method to use. Should be 'GET' or 'HEAD'.
        @param value: The value to test.
        @param expectedTypeString: The expected string that should be returned
            by C{X-FluidDB-Type}.
        """
        facadeClient = FakeFacade()
        session = FakeSession()

        # Tell our FakeFacade to preload some data for a given tag.
        facadeClient.values = {
            'fe2f50c8-997f-4049-a180-9a37543d001d': {
                'tag/test': value}}

        resource = TagInstanceResource(facadeClient, session,
                                       'fe2f50c8-997f-4049-a180-9a37543d001d',
                                       'tag/test')

        request = FakeRequest(method=method)
        yield getattr(resource, 'render_' + method)(request)
        typeValue = request.getResponseHeader(buildHeader('Type'))
        self.assertEqual(expectedTypeString, typeValue)
Пример #2
0
    def testInsecurePostIsRejected(self):
        """A C{POST} via HTTP is rejected if not in development mode."""
        self.config.set('service', 'development', 'false')
        with login(None, None, self.transact) as session:
            resource = VerifyUserPasswordResource(None, session, 'user')
            payload = ''
            headers = {'Content-Length': [str(len(payload))],
                       'Content-Type': ['application/json']}
            request = FakeRequest(method='POST', headers=Headers(headers),
                                  body=payload)
            self.assertEqual(NOT_DONE_YET, resource.render(request))

            yield resource.deferred
            self.assertEqual(request.code, http.BAD_REQUEST)
            self.assertEqual(
                request.getResponseHeader('X-FluidDB-Message'),
                '/users/<username>/verify requests must use HTTPS')