Esempio n. 1
0
 def setUp(self):
     op = sc_messages.Operation(
         consumerId=_TEST_CONSUMER_ID,
         operationName=_TEST_OP_NAME
     )
     self.test_check_request = sc_messages.CheckRequest(operation=op)
     self.test_op = op
Esempio n. 2
0
def _make_test_request(service_name, importance=None):
    if importance is None:
        importance = sc_messages.Operation.ImportanceValueValuesEnum.LOW
    op = sc_messages.Operation(
        consumerId=_TEST_CONSUMER_ID,
        operationName=_TEST_OP_NAME,
        importance=importance
    )
    check_request = sc_messages.CheckRequest(operation=op)
    return sc_messages.ServicecontrolServicesCheckRequest(
        serviceName=service_name,
        checkRequest=check_request)
Esempio n. 3
0
def _make_test_request(service_name, importance=None, n=3, start=0):
    if importance is None:
        importance = sc_messages.Operation.ImportanceValueValuesEnum.LOW
    op_names = _make_op_names(n, start=start)
    ops = [sc_messages.Operation(consumerId=_TEST_CONSUMER_ID,
                              operationName=op_name,
                              importance=importance) for op_name in op_names]
    if ops:
        ops[0].labels = encoding.PyValueToMessage(
            sc_messages.Operation.LabelsValue, {
                u'key1': u'always add a label to the first op'})
    report_request = sc_messages.ReportRequest(operations=ops)
    return sc_messages.ServicecontrolServicesReportRequest(
        serviceName=service_name,
        reportRequest=report_request)
Esempio n. 4
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': sc_messages.Operation(
            startTime=_EARLY,
            endTime=_LATER
        ),
        u'ops': [
            sc_messages.Operation(
                startTime=_REALLY_EARLY,
                endTime=_LATER
            ),
            sc_messages.Operation(
                startTime=_LATER,
                endTime=_LATER
            ),
        ],
        u'want': sc_messages.Operation(startTime=_REALLY_EARLY, endTime=_LATER)
    },
    {
        u'description': u'update the end time to that of the latest',
Esempio n. 5
0
_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),
     sc_messages.Operation(
         importance=sc_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,
Esempio n. 6
0
 def test_should_fail_if_operation_has_no_consumer_id(self):
     op = sc_messages.Operation(operationName=_TEST_OP_NAME)
     testf = lambda: check_request.sign(
         sc_messages.CheckRequest(operation=op))
     expect(testf).to(raise_error(ValueError))
Esempio n. 7
0
 def test_should_fail_if_operation_has_no_operation_name(self):
     op = sc_messages.Operation(consumerId=_TEST_CONSUMER_ID)
     testf = lambda: check_request.sign(
         sc_messages.CheckRequest(operation=op))
     expect(testf).to(raise_error(ValueError))
Esempio n. 8
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),
     sc_messages.Operation(
         importance=sc_messages.Operation.ImportanceValueValuesEnum.LOW,
         labels = encoding.PyValueToMessage(
             sc_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',
        referer=u'a_referer',