Ejemplo n.º 1
0
  def CreateSuccessfulRecord(self):
    """Returns a Record with a successful request/response pair.

    Returns:
      A (BidResopnse, Record) pair. The bid_response is returned for
      convenience so a test method can make a slight modification and serialize
      it into record.bid_response without parsing record.bid_response first.
    """
    bid_request = realtime_bidding_pb2.BidRequest()
    bid_request.id = 'id111'
    request_adslot = bid_request.adslot.add()
    request_adslot.id = 123
    request_adslot.height.append(468)
    request_adslot.width.append(60)
    status = 200
    bid_response = realtime_bidding_pb2.BidResponse()
    bid_response.processing_time_ms = 10
    ad = bid_response.ad.add()
    ad.click_through_url.append('http://url.com')
    ad.html_snippet = ('A snippet. <a href=\'%%CLICK_URL_UNESC%%'
                       'http://www.google.com\'>link</a>')
    adslot = ad.adslot.add()
    adslot.id = 123
    adslot.max_cpm_micros = 5000000
    record = log.Record(bid_request, status, bid_response.SerializeToString())
    return bid_response, record
Ejemplo n.º 2
0
 def testSummarizePingRequest(self):
   """Tests summarizing a ping request."""
   bid_request = realtime_bidding_pb2.BidRequest()
   bid_request.id = 'id111'
   bid_request.is_ping = True
   bid_response = realtime_bidding_pb2.BidResponse()
   bid_response.processing_time_ms = 0
   record = log.Record(bid_request, 200, bid_response.SerializeToString())
   self.records.append(record)
   self.summarizer = log.LogSummarizer(self.records)
   self.summarizer.Summarize()
   self.CheckNGoodRequests(1)
Ejemplo n.º 3
0
  def CreateSuccessfulTemplateRecord(self):
    """Returns a Record with a successful request/response for a template ad.

    Returns:
      A (BidResopnse, Record) pair. The bid_response is returned for
      convenience so a test method can make a slight modification and serialize
      it into record.bid_response without parsing record.bid_response first.
    """
    bid_request = realtime_bidding_pb2.BidRequest()
    bid_request.id = 'id111'
    request_adslot = bid_request.adslot.add()
    request_adslot.id = 123
    request_adslot.height.append(468)
    request_adslot.width.append(60)
    status = 200
    bid_response = realtime_bidding_pb2.BidResponse()
    bid_response.processing_time_ms = 10
    ad = bid_response.ad.add()
    ad.snippet_template = 'Template %%P0%%, %%P1%%.'
    param = ad.template_parameter.add()
    param.parameter_value = 'value0'
    param.left = 1
    param.right = 15
    param.top = 20
    param.bottom = 1
    param.click_through_url = 'http://url1.com'
    param.buyer_creative_id = '12345'
    param = ad.template_parameter.add()
    param.parameter_value = 'value1'
    param.left = 1
    param.right = 15
    param.top = 35
    param.bottom = 21
    param.click_through_url = 'http://url2.com'
    param.buyer_creative_id = '54321'
    adslot = ad.adslot.add()
    adslot.id = 123
    adslot.max_cpm_micros = 5000000
    record = log.Record(bid_request, status, bid_response.SerializeToString())
    return bid_response, record
Ejemplo n.º 4
0
  def CreateSuccessfulVideoRecord(self):
    """Returns a Record with a successful video request/response pair.

    Returns:
      A (BidResopnse, Record) pair. The bid_response is returned for
      convenience so a test method can make a slight modification and serialize
      it into record.bid_response without parsing record.bid_response first.
    """
    bid_request = realtime_bidding_pb2.BidRequest()
    bid_request.id = 'id111'
    bid_request.video.videoad_start_delay = 1000
    request_adslot = bid_request.adslot.add()
    request_adslot.id = 123
    status = 200
    bid_response = realtime_bidding_pb2.BidResponse()
    bid_response.processing_time_ms = 10
    ad = bid_response.ad.add()
    ad.click_through_url.append('http://url.com')
    ad.video_url = 'http://my.video.url.com'
    adslot = ad.adslot.add()
    adslot.id = 123
    adslot.max_cpm_micros = 5000000
    record = log.Record(bid_request, status, bid_response.SerializeToString())
    return bid_response, record
Ejemplo n.º 5
0
    def Summarize(self):
        """Collects and summarizes information from the logger."""
        for record in self._logger:
            self._requests_sent += 1
            if record.status == httplib.OK:
                self._responses_ok += 1
            else:
                # Responded with a non-OK code, don't to parse.
                record.problems.append(self.REQUEST_ERROR_MESSAGES['not-ok'])
                self._error.append(record)
                continue

            if not record.payload:
                record.problems.append(self.RESPONSE_ERROR_MESSAGES['empty'])
                self._invalid.append(record)
                # Empty response, don't try to parse.
                continue

            bid_response = realtime_bidding_pb2.BidResponse()
            try:
                bid_response.ParseFromString(record.payload)
            except google.protobuf.message.DecodeError:
                record.problems.append(
                    self.RESPONSE_ERROR_MESSAGES['parse-error'])
                self._invalid.append(record)
                # Unparseable response, don't check its validity.
                continue

            if not bid_response.IsInitialized():
                # It parsed but the message is not initialized which means it's not
                # well-formed, consider this unparseable.
                record.problems.append(
                    self.RESPONSE_ERROR_MESSAGES['uninitialized'])
                self._invalid.append(record)
                continue

            record.bid_response = bid_response

            if not bid_response.HasField('processing_time_ms'):
                record.problems.append(
                    self.RESPONSE_ERROR_MESSAGES['no-processing-time'])
            else:
                self._processing_time_count += 1
                self._processing_time_sum += bid_response.processing_time_ms

            if record.bid_request.is_ping:
                self.ValidatePing(record)
            else:
                if not bid_response.ad:
                    self._responses_successful_without_bids += 1
                    self._good.append(record)
                    continue
                    # No ads returned, don't validate ads.

                for i, ad in enumerate(bid_response.ad):
                    self.ValidateAd(ad, i, record)

            if record.problems:
                self._problematic.append(record)
            else:
                self._good.append(record)