Example #1
0
def _make_test_request(service_name, importance=None):
    if importance is None:
        importance = messages.Operation.ImportanceValueValuesEnum.LOW
    op = messages.Operation(consumerId=_TEST_CONSUMER_ID,
                            operationName=_TEST_OP_NAME,
                            importance=importance)
    check_request = messages.CheckRequest(operation=op)
    return messages.ServicecontrolServicesCheckRequest(
        serviceName=service_name, checkRequest=check_request)
def _make_test_request(service_name, importance=None, n=3, start=0):
    if importance is None:
        importance = messages.Operation.ImportanceValueValuesEnum.LOW
    op_names = _make_op_names(n, start=start)
    ops = [
        messages.Operation(consumerId=_TEST_CONSUMER_ID,
                           operationName=op_name,
                           importance=importance) for op_name in op_names
    ]
    if ops:
        ops[0].labels = encoding.PyValueToMessage(
            messages.Operation.LabelsValue,
            {u'key1': u'always add a label to the first op'})
    report_request = messages.ReportRequest(operations=ops)
    return messages.ServicecontrolServicesReportRequest(
        serviceName=service_name, reportRequest=report_request)
Example #3
0
 def test_should_fail_if_operation_has_no_consumer_id(self):
     op = messages.Operation(operationName=_TEST_OP_NAME)
     testf = lambda: check_request.sign(messages.CheckRequest(operation=op))
     expect(testf).to(raise_error(ValueError))
Example #4
0
 def test_should_fail_if_operation_has_no_operation_name(self):
     op = messages.Operation(consumerId=_TEST_CONSUMER_ID)
     testf = lambda: check_request.sign(messages.CheckRequest(operation=op))
     expect(testf).to(raise_error(ValueError))
Example #5
0
 def setUp(self):
     op = messages.Operation(consumerId=_TEST_CONSUMER_ID,
                             operationName=_TEST_OP_NAME)
     self.test_check_request = messages.CheckRequest(operation=op)
     self.test_op = op
Example #6
0
_WANTED_SERVICE_AGENT = label_descriptor.SERVICE_AGENT
_START_OF_EPOCH = timestamp.to_rfc3339(datetime.datetime(1970, 1, 1, 0, 0, 0))
_TEST_SERVICE_NAME = u'a_service_name'
_INFO_TESTS = [
    (check_request.Info(operation_id=u'an_op_id',
                        operation_name=u'an_op_name',
                        referer=u'a_referer',
                        service_name=_TEST_SERVICE_NAME),
     messages.Operation(
         importance=messages.Operation.ImportanceValueValuesEnum.LOW,
         labels=encoding.PyValueToMessage(
             messages.Operation.LabelsValue, {
                 u'servicecontrol.googleapis.com/user_agent':
                 _WANTED_USER_AGENT,
                 u'servicecontrol.googleapis.com/referer':
                 u'a_referer',
                 u'servicecontrol.googleapis.com/service_agent':
                 _WANTED_SERVICE_AGENT,
             }),
         operationId=u'an_op_id',
         operationName=u'an_op_name',
         startTime=_START_OF_EPOCH,
         endTime=_START_OF_EPOCH)),
    (check_request.Info(
        android_cert_fingerprint=u'an_android_cert_fingerprint',
        android_package_name=u'an_android_package_name',
        api_key=u'an_api_key',
        api_key_valid=True,
        ios_bundle_id=u'an_ios_bundle_id',
        operation_id=u'an_op_id',
        operation_name=u'an_op_name',
Example #7
0
_EARLY = timestamp.to_rfc3339(datetime.datetime(1980, 1, 1, 10, 0, 0))
_LATER = timestamp.to_rfc3339(datetime.datetime(1980, 2, 2, 10, 0, 0))
_LATER_STILL = timestamp.to_rfc3339(datetime.datetime(1981, 2, 2, 10, 0, 0))

_TEST_LABELS = {
    u'key1': u'value1',
    u'key2': u'value2',
}

# in tests, the description field is not currently used, but should be filled
_TESTS = [
    {
        u'description': u'update the start time to that of the earliest',
        u'kinds': None,
        u'initial': messages.Operation(
            startTime=_EARLY,
            endTime=_LATER
        ),
        u'ops': [
            messages.Operation(
                startTime=_REALLY_EARLY,
                endTime=_LATER
            ),
            messages.Operation(
                startTime=_LATER,
                endTime=_LATER
            ),
        ],
        u'want': messages.Operation(startTime=_REALLY_EARLY, endTime=_LATER)
    },
    {
        u'description': u'update the end time to that of the latest',
_EXPECTED_NOK_METRIC = metric_descriptor.KnownMetrics.CONSUMER_ERROR_COUNT
_ADD_LOG_TESTS = [
    (report_request.Info(operation_id=u'an_op_id',
                         operation_name=u'an_op_name',
                         method=u'GET',
                         referer=u'a_referer',
                         backend_time=_TEST_LATENCY,
                         overhead_time=_TEST_LATENCY,
                         request_time=_TEST_LATENCY,
                         request_size=_TEST_SIZE,
                         response_size=_TEST_SIZE,
                         service_name=_TEST_SERVICE_NAME),
     messages.Operation(
         importance=messages.Operation.ImportanceValueValuesEnum.LOW,
         logEntries=[_EXPECTED_OK_LOG_ENTRY],
         operationId=u'an_op_id',
         operationName=u'an_op_name',
         startTime=_START_OF_EPOCH_TIMESTAMP,
         endTime=_START_OF_EPOCH_TIMESTAMP)),
    (report_request.Info(response_code=404,
                         operation_id=u'an_op_id',
                         operation_name=u'an_op_name',
                         method=u'GET',
                         referer=u'a_referer',
                         backend_time=_TEST_LATENCY,
                         overhead_time=_TEST_LATENCY,
                         request_time=_TEST_LATENCY,
                         request_size=_TEST_SIZE,
                         response_size=_TEST_SIZE,
                         service_name=_TEST_SERVICE_NAME),
     messages.Operation(