Exemple #1
0
    def testApiCallPollOperationForcesOperationHandling(self):
        backing_data = {
            'api_call': {
                'poll_operation': True,
                'expect_request': {
                    'uri': 'https://example.com',
                    'method': 'GET',
                    'body': None,
                },
                'return_response': {
                    'body': {
                        'name': 'foo/bar/my-op'
                    },
                }
            }
        }
        rrr = reference_resolver.ResourceReferenceResolver()
        e = events.ApiCallEvent.FromData(backing_data)
        response = e.GetResponse()
        failures = e.HandleResponse(response,
                                    resource_ref_resolver=rrr,
                                    generate_extras=True)

        self.assertEqual(0, len(failures))
        self.assertEqual(rrr._extracted_ids, {
            'operation': 'foo/bar/my-op',
            'operation-basename': 'my-op'
        })
Exemple #2
0
 def testApiCallEventAddOptional(self):
     backing_data = {
         'api_call': {
             'poll_operation': False,
             'expect_request': {
                 'uri': 'https://example.com',
                 'method': 'GET',
                 'body': None,
             },
             'return_response': {
                 'body': {
                     'kind': 'sql#operation',
                     'name': '460b8ba8-34a9-4590-a3ca-7ce5b74cb8d5',
                     'status': 'PENDING',
                 }
             }
         }
     }
     e = events.ApiCallEvent.FromData(backing_data)
     # Setting the id as previous extracted means that this is a polling event
     # not an op creation event.
     rrr = reference_resolver.ResourceReferenceResolver()
     rrr.SetExtractedId('operation', '460b8ba8-34a9-4590-a3ca-7ce5b74cb8d5')
     response = e.GetResponse()
     failures = e.HandleResponse(response, rrr, generate_extras=True)
     self.assertEqual(2, len(failures))
     failures[0].Update([updates.Mode.API_REQUESTS])
     failures[1].Update([updates.Mode.API_REQUESTS])
     self.assertTrue(backing_data['api_call']['optional'])
     self.assertEqual({'body': {
         'json': {
             'status': 'PENDING'
         }
     }}, backing_data['api_call']['expect_response'])
Exemple #3
0
    def testReverseResolveResourceReferencesLongestFirst(self):
        rrr = reference_resolver.ResourceReferenceResolver()
        rrr.SetExtractedId('ref1', 'my-group-instance-subthing')
        rrr.SetExtractedId('ref2', 'my-group')
        rrr.SetExtractedId('ref3', 'my-group-instance')

        data = 'my-group-instance my-group my-group-instance-subthing'
        resolved = rrr.ReverseResolve(data)
        self.assertEqual(resolved, '$$ref3$$ $$ref2$$ $$ref1$$')
Exemple #4
0
 def __init__(self, spec_name, full_spec_path, spec_data, track,
              execution_mode, update_modes, stream_mocker, command_executor,
              debug=False):
   self.spec_name = spec_name
   self.full_spec_path = full_spec_path
   self.spec_data = spec_data
   self.track = track
   self.execution_mode = execution_mode
   self.update_modes = update_modes
   self.stream_mocker = stream_mocker
   self.command_executor = command_executor
   self.resource_ref_resolver = reference_resolver.ResourceReferenceResolver()
   self.debug = debug
Exemple #5
0
    def testResponseExtractRef(self):
        e = events.HTTPAssertion.ForResponse({
            'extract_references': [{
                'field': 'name',
                'reference': 'operation'
            }, {
                'field': 'name',
                'reference': 'operation-base',
                'modifiers': {
                    'basename': True
                }
            }]
        })

        rrr = reference_resolver.ResourceReferenceResolver()
        e.ExtractReferences(rrr, '{"name": "foo/bar/my-op"}')
        self.assertEqual(rrr._extracted_ids, {
            'operation': 'foo/bar/my-op',
            'operation-base': 'my-op'
        })
Exemple #6
0
 def testApiCallEventAddRefExtraction(self):
     backing_data = {
         'api_call': {
             'poll_operation': False,
             'expect_request': {
                 'uri': 'https://example.com',
                 'method': 'GET',
                 'body': None,
             },
             'return_response': {
                 'body': {
                     'kind': 'sql#operation',
                     'name': '460b8ba8-34a9-4590-a3ca-7ce5b74cb8d5',
                     'status': 'DONE',
                 }
             }
         }
     }
     e = events.ApiCallEvent.FromData(backing_data)
     headers, body = e.GetResponsePayload()
     failures = e.HandleResponse(
         headers,
         body,
         reference_resolver.ResourceReferenceResolver(),
         generate_extras=True)
     self.assertEqual(1, len(failures))
     failures[0].Update([updates.Mode.API_REQUESTS])
     self.assertEqual(
         {
             'extract_references': [{
                 'field': 'name',
                 'reference': 'operation'
             }],
             'body': {
                 'json': {}
             }
         }, backing_data['api_call']['expect_response'])