示例#1
0
    def test_should_not_send_requests_if_there_is_no_service(self):
        wrappee = _DummyWsgiApp()
        control_client = mock.MagicMock(spec=client.Client)

        given = {
            u'wsgi.url_scheme': u'http',
            u'PATH_INFO': u'/any',
            u'REMOTE_ADDR': u'192.168.0.3',
            u'HTTP_HOST': u'localhost',
            u'HTTP_REFERER': u'example.myreferer.com',
            u'REQUEST_METHOD': u'GET'}
        dummy_response = sc_messages.CheckResponse(
            operationId=u'fake_operation_id')
        wrapped = wsgi.Middleware(wrappee, self.PROJECT_ID, control_client)
        wrapped(given, _dummy_start_response)
        expect(control_client.check.called).to(be_false)
        expect(control_client.report.called).to(be_false)
        expect(control_client.allocate_quota.called).to(be_false)
示例#2
0
    def test_should_send_requests_using_the_client(self):
        wrappee = _DummyWsgiApp()
        control_client = mock.MagicMock(spec=client.Client)

        given = {
            u'wsgi.url_scheme': u'http',
            u'PATH_INFO': u'/any',
            u'REMOTE_ADDR': u'192.168.0.3',
            u'HTTP_HOST': u'localhost',
            u'HTTP_REFERER': u'example.myreferer.com',
            u'REQUEST_METHOD': u'GET'}
        dummy_response = sc_messages.CheckResponse(
            operationId=u'fake_operation_id')
        with_control = wsgi.Middleware(wrappee, self.PROJECT_ID, control_client)
        wrapped = wsgi.EnvironmentMiddleware(with_control,
                                             service.Loaders.SIMPLE.load())
        control_client.check.return_value = dummy_response
        wrapped(given, _dummy_start_response)
        expect(control_client.check.called).to(be_true)
        expect(control_client.report.called).to(be_true)
        # no quota definitions in this service config
        expect(control_client.allocate_quota.called).to(be_false)