def test_build_identifier_from_invalid_source_type(self): identifiers = [Parameter(target='Id', source='invalid')] parent = mock.Mock() params = {} response = {'Container': {'Frobs': []}} with pytest.raises(NotImplementedError): build_identifiers(identifiers, parent, params, response)
def test_build_identifier_from_parent_identifier(self): identifiers = [Parameter(target='Id', source='identifier', name='Id')] parent = mock.Mock() parent.id = 'identifier' params = {} response = {'Container': {'Frobs': []}} values = build_identifiers(identifiers, parent, params, response) # Verify identifier loaded from responsePath scalar set assert values[0][1] == 'identifier'
def test_build_identifier_from_parent_data_member(self): identifiers = [Parameter(target='Id', source='data', path='Member')] parent = mock.Mock() parent.meta = ResourceMeta('test', data={'Member': 'data-member'}) params = {} response = {'Container': {'Frobs': []}} values = build_identifiers(identifiers, parent, params, response) # Verify identifier loaded from responsePath scalar set assert values[0][1] == 'data-member'
def test_build_identifier_from_parent_data_member(self): identifiers = [Parameter(target='Id', source='data', path='Member')] parent = mock.Mock() parent.meta = ResourceMeta('test', data={'Member': 'data-member'}) params = {} response = {'Container': {'Frobs': []}} values = build_identifiers(identifiers, parent, params, response) self.assertEqual(values[0][1], 'data-member', 'Identifier loaded from parent data member not set')
def test_build_identifier_from_parent_identifier(self): identifiers = [Parameter(target='Id', source='identifier', name='Id')] parent = mock.Mock() parent.id = 'identifier' params = {} response = {'Container': {'Frobs': []}} values = build_identifiers(identifiers, parent, params, response) self.assertEqual(values[0][1], 'identifier', 'Identifier loaded from parent identifier not set')
def test_build_identifier_from_req_param(self): identifiers = [ Parameter(target='Id', source='requestParameter', path='Param') ] parent = mock.Mock() params = {'Param': 'request-param'} response = {'Container': {'Frobs': []}} values = build_identifiers(identifiers, parent, params, response) # Verify identifier loaded from responsePath scalar set assert values[0][1] == 'request-param'
def test_build_identifier_from_res_path_scalar(self): identifiers = [ Parameter(target='Id', source='response', path='Container.Frob.Id') ] parent = mock.Mock() params = {} response = {'Container': {'Frob': {'Id': 'response-path'}}} values = build_identifiers(identifiers, parent, params, response) # Verify identifier loaded from responsePath scalar set assert values[0][1] == 'response-path'
def test_build_identifier_from_req_param(self): identifiers = [ Parameter(target='Id', source='requestParameter', path='Param') ] parent = mock.Mock() params = {'Param': 'request-param'} response = {'Container': {'Frobs': []}} values = build_identifiers(identifiers, parent, params, response) self.assertEqual(values[0][1], 'request-param', 'Identifier loaded from request parameter not set')
def test_build_identifier_from_res_path_list(self): identifiers = [ Parameter(target='Id', source='response', path='Container.Frobs[].Id') ] parent = mock.Mock() params = {} response = {'Container': {'Frobs': [{'Id': 'response-path'}]}} values = build_identifiers(identifiers, parent, params, response) self.assertEqual(values[0][1], ['response-path'], 'Identifier loaded from responsePath list not set')