예제 #1
0
def _make_dummy_report_request(project_id, service_name):
    rules = report_request.ReportingRules()
    info = report_request.Info(consumer_project_id=project_id,
                               operation_id=u'an_op_id',
                               operation_name=u'an_op_name',
                               method=u'GET',
                               referer=u'a_referer',
                               service_name=service_name)
    return info.as_report_request(rules)
 def test_should_add_expected_label_as_report_request(self):
     timer = _DateTimeTimer()
     rules = report_request.ReportingRules(labels=[_EXPECTED_OK_LABEL])
     for info, want in _ADD_LABELS_TESTS:
         got = info.as_report_request(rules, timer=timer)
         # These additional properties have no well-defined order, so sort them.
         got.reportRequest.operations[0].labels.additionalProperties.sort(
             key=KEYGETTER)
         want.labels.additionalProperties.sort(key=KEYGETTER)
         expect(got.serviceName).to(equal(_TEST_SERVICE_NAME))
         expect(got.reportRequest.operations[0]).to(equal(want))
 def test_should_add_expected_logs_as_report_request(self):
     timer = _DateTimeTimer()
     rules = report_request.ReportingRules(logs=[u'endpoints-log'])
     for info, want in _ADD_LOG_TESTS:
         got = info.as_report_request(rules, timer=timer)
         expect(got.serviceName).to(equal(_TEST_SERVICE_NAME))
         # compare the log entry in detail to avoid instability when
         # comparing the operations directly
         wantLogEntry = want.logEntries[0]
         gotLogEntry = got.reportRequest.operations[0].logEntries[0]
         expect(gotLogEntry.name).to(equal(wantLogEntry.name))
         expect(gotLogEntry.timestamp).to(equal(wantLogEntry.timestamp))
         print(u'got timestamp', gotLogEntry.timestamp)
         print(u'want timestamp', wantLogEntry.timestamp)
         expect(gotLogEntry.severity).to(equal(wantLogEntry.severity))
         gotStruct = encoding.MessageToPyValue(gotLogEntry.structPayload)
         print(u'got struct', gotStruct)
         wantStruct = encoding.MessageToPyValue(wantLogEntry.structPayload)
         print(u'want struct', wantStruct)
         expect(gotStruct).to(equal(wantStruct))
 def test_should_fail_as_report_request_on_incomplete_info(self):
     timer = _DateTimeTimer()
     incomplete = report_request.Info()  # has no service_name
     rules = report_request.ReportingRules()
     testf = lambda: incomplete.as_report_request(rules, timer=timer)
     expect(testf).to(raise_error(ValueError))