Пример #1
0
 def test_should_send_report_request_if_check_fails(self):
     wrappee = _DummyWsgiApp()
     control_client = mock.MagicMock(spec=client.Client)
     given = {
         'wsgi.url_scheme': 'http',
         'PATH_INFO': '/any/method',
         'REMOTE_ADDR': '192.168.0.3',
         'HTTP_HOST': 'localhost',
         'HTTP_REFERER': 'example.myreferer.com',
         'REQUEST_METHOD': 'GET'
     }
     dummy_response = messages.CheckResponse(
         operationId='fake_operation_id',
         checkErrors=[
             messages.CheckError(code=messages.CheckError.
                                 CodeValueValuesEnum.PROJECT_DELETED)
         ])
     wrapped = wsgi.add_all(wrappee,
                            self.PROJECT_ID,
                            control_client,
                            loader=service.Loaders.SIMPLE)
     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)
    def test_signals_resend_on_1st_call_after_flush_interval_with_errors(self):
        req = _make_test_request(self.SERVICE_NAME)
        failure_code = messages.CheckError.CodeValueValuesEnum.NOT_FOUND
        fake_response = messages.CheckResponse(
            operationId=self.FAKE_OPERATION_ID, checkErrors=[
                messages.CheckError(code=failure_code)
            ])
        agg = self.agg
        expect(agg.check(req)).to(be_none)
        agg.add_response(req, fake_response)
        expect(agg.check(req)).to(equal(fake_response))

        # Now flush interval is reached, but not the response expiry
        self.timer.tick() # now past the flush_interval
        expect(agg.check(req)).to(be_none)  # first response is null

        # until expiry, the response will continue to be returned
        expect(agg.check(req)).to(equal(fake_response))
        expect(agg.check(req)).to(equal(fake_response))

        # expire
        self.timer.tick()
        self.timer.tick() # now expired
        expect(agg.check(req)).to(be_none)
        expect(agg.check(req)).to(be_none) # 2nd check is None as well
 def test_should_include_project_id_in_error_text_when_needed(self):
     resp = messages.CheckResponse(checkErrors=[
         messages.CheckError(
             code=messages.CheckError.CodeValueValuesEnum.PROJECT_DELETED)
     ])
     code, got, _ = check_request.convert_response(resp, self.PROJECT_ID)
     want = 'Project %s has been deleted' % (self.PROJECT_ID, )
     expect(code).to(equal(httplib.FORBIDDEN))
     expect(got).to(equal(want))
 def test_should_include_detail_in_error_text_when_needed(self):
     detail = 'details, details, details'
     resp = messages.CheckResponse(checkErrors=[
         messages.CheckError(code=messages.CheckError.CodeValueValuesEnum.
                             IP_ADDRESS_BLOCKED,
                             detail=detail)
     ])
     code, got, _ = check_request.convert_response(resp, self.PROJECT_ID)
     expect(code).to(equal(httplib.FORBIDDEN))
     expect(got).to(equal(detail))