def parent_child_resource(self): """A multitype concept spec with four types.""" project_shelf_book_resource = util.GetBookResource('book') project_shelf_resource = util.GetProjShelfResource('shelf') return multitype.MultitypeResourceSpec('book', project_shelf_book_resource, project_shelf_resource)
def SetUp(self): # The child. book_resource = util.GetBookResource(name='book') # Shelves are the parent - they contain books. shelf_resource = util.GetProjShelfResource(name='shelf') self.resource = multitype.MultitypeResourceSpec( 'shelfbook', book_resource, shelf_resource)
def two_way_shelf_case_book(self): project_shelf_book_resource = util.GetBookResource(name='shelfbook') project_case_book_resource = util.GetProjCaseBookResource( name='casebook') return multitype.MultitypeResourceSpec('book', project_shelf_book_resource, project_case_book_resource)
def testCreateMultiTypeResource(self): project_book_resource = util.GetBookResource(name='projectbook') organization_book_resource = util.GetOrgShelfBookResource( name='orgbook') resource = multitype.MultitypeResourceSpec('book', project_book_resource, organization_book_resource) expected_attributes = (project_book_resource.attributes + organization_book_resource.attributes[:1]) self.assertEqual(expected_attributes, resource.attributes) self.assertNotEqual(resource.type_enum['projectbook'], resource.type_enum['orgbook']) self.assertEqual( { 'project': [resource.type_enum['projectbook']], 'organization': [resource.type_enum['orgbook']], 'shelf': [ resource.type_enum['projectbook'], resource.type_enum['orgbook'] ], 'book': [ resource.type_enum['projectbook'], resource.type_enum['orgbook'] ] }, resource._attribute_to_types_map)
def SetUp(self): """Get resource with two possible top-level params.""" project_book_resource = util.GetBookResource(name='projectbook') organization_book_resource = util.GetOrgShelfBookResource( name='orgbook') self.resource = multitype.MultitypeResourceSpec( 'book', project_book_resource, organization_book_resource)
def testCompleterWithArbitraryArgFallthrough(self): collections = [ ('example.projects.shelves.books', True), ('example.projects.shelves', True), ('cloudresourcemanager.projects', True)] self.MockCRUDMethods(*collections) self.PatchBookResourceReturnTypes() parent_name = 'projects/exampleproject/shelves/s0' self.mock_client.projects_shelves_books.List.return_value = ( self.BuildBooksList(['{}/books/b0'.format(parent_name), '{}/books/b1'.format(parent_name)])) resource_spec = util.GetBookResource() resource_spec.attributes[1].fallthroughs.append( deps.ArgFallthrough('--other')) expected_results = ['b0', 'b1'] self.RunResourceCompleter( resource_spec, 'book', presentation_name='--book', dest='book', args={'--book-project': 'exampleproject', '--other': 's0'}, flag_name_overrides={'project': '--book-project'}, expected_completions=expected_results)
def testCreateMultiTypeConceptRenamesTypes(self): project_book_resource = util.GetBookResource() organization_book_resource = util.GetOrgShelfBookResource() resource = multitype.MultitypeConceptSpec('book', project_book_resource, organization_book_resource) self.assertNotEqual(resource.type_enum['book_project_shelf_book'], resource.type_enum['book_organization_shelf_book'])
def testCreateMultiTypeResourceRenamesTypes(self): project_book_resource = util.GetBookResource() organization_book_resource = util.GetOrgShelfBookResource() resource = multitype.MultitypeResourceSpec('book', project_book_resource, organization_book_resource) self.assertNotEqual( resource.type_enum['example.projects.shelves.books'], resource.type_enum['example.organizations.shelves.books'])
def four_way_parent_child_resource(self): """A multitype concept spec with four types.""" project_shelf_book_resource = util.GetBookResource() organization_shelf_book_resource = util.GetOrgShelfBookResource() project_shelf_resource = util.GetProjShelfResource() organization_shelf_resource = util.GetOrgShelfResource() return multitype.MultitypeResourceSpec( 'book', project_shelf_book_resource, organization_shelf_book_resource, project_shelf_resource, organization_shelf_resource)
def four_way_resource(self): """A multitype concept spec with four types.""" project_shelf_book_resource = util.GetBookResource(name='projectbook') organization_shelf_book_resource = util.GetOrgShelfBookResource( name='orgshelfbook') project_case_book_resource = util.GetProjCaseBookResource( name='projcasebook') organization_case_book_resource = util.GetOrgCaseBookResource( name='orgcasebook') return multitype.MultitypeResourceSpec( 'book', project_shelf_book_resource, organization_shelf_book_resource, project_case_book_resource, organization_case_book_resource)
def testCreateMultiTypeResourceFailsWithMismatchedAttribute(self): book_resource = util.GetBookResource() # Create a second resource with an attribute named "project" that doesn't # match the book resource's project attribute. project_resource = concepts.ResourceSpec( 'example.projects', 'project', projectsId=concepts.ResourceParameterAttributeConfig( name='project', help_text='The Cloud project of the {resource}.')) with self.assertRaisesRegexp(multitype.ConfigurationError, re.escape('[project]')): multitype.MultitypeResourceSpec('book', book_resource, project_resource)
def SetUpConceptParserWithFallthroughs(self, name, fallthroughs_map=None): resource_spec = util.GetBookResource() fallthroughs_map = fallthroughs_map or {} for attribute in resource_spec.attributes: fallthroughs = fallthroughs_map.get(attribute.name, []) attribute.fallthroughs = fallthroughs flag_name_overrides = {'project': '--book-project'} concept_parsers.ConceptParser([ presentation_specs.ResourcePresentationSpec( name, resource_spec, 'a resource', flag_name_overrides=flag_name_overrides) ]).AddToParser(self.parser)
def testCompleterForAttribute_DifferentVersions(self): collections = [ ('example.projects.shelves.books', True), ('example.projects.shelves', True), ('example.projects', True), ('example.projects.shelves.books', True, 'v1beta1'), ('example.projects.shelves', True, 'v1beta1'), ('example.projects', True, 'v1beta1')] self.MockCRUDMethods(*collections) book_collection = registry.GetAPICollection( 'example.projects.shelves.books', 'v1beta1') resource_spec = util.GetBookResource(api_version='v1beta1') expected_completer = completers.ResourceArgumentCompleter( resource_spec, book_collection, registry.GetMethod('example.projects.shelves.books', 'list', api_version='v1beta1'), param='booksId', static_params={}) completer = completers.CompleterForAttribute(self.resource_spec, 'book')() self.assertEqual(expected_completer, completer) expected_completer = completers.ResourceArgumentCompleter( resource_spec, registry.GetAPICollection('example.projects.shelves', 'v1beta1'), registry.GetMethod('example.projects.shelves', 'list', api_version='v1beta1'), param='shelvesId', static_params={}) completer = completers.CompleterForAttribute(self.resource_spec, 'shelf')() self.assertEqual(expected_completer, completer) expected_completer = completers.ResourceArgumentCompleter( self.resource_spec, registry.GetAPICollection('example.projects', 'v1beta1'), registry.GetMethod('example.projects', 'list', api_version='v1beta1'), param='projectsId', static_params={}) completer = completers.CompleterForAttribute( self.resource_spec, 'project')() self.assertEqual(expected_completer, completer)
def resource_spec_auto_completers(self): """A basic resource spec for the fake "book" resource with auto complete.""" # Lazy creation allows checking of the GetCollectionInfo mock. return util.GetBookResource(auto_completers=True)
def resource_spec_completers(self): """A basic resource spec for the fake "book" resource, with completers.""" return util.GetBookResource(with_completers=True)
def resource_spec(self): """A basic resource spec for the fake "book" resource.""" # Lazy creation allows checking of the GetCollectionInfo mock. return util.GetBookResource()
def multitype_extra_attribute_in_path(self): plain_resource = util.GetBookResource(name='book') # Shelves are the parent - they contain books. with_case_resource = util.GetProjCaseShelfBookResource(name='book') return multitype.MultitypeResourceSpec('book', plain_resource, with_case_resource)
def testCreateMultitypeResourceFailsWithDuplicateCollection(self): project_book_resource = util.GetBookResource() with self.assertRaisesRegexp(ValueError, 'projects.shelves.books'): multitype.MultitypeResourceSpec('book', project_book_resource, project_book_resource)
def two_way_resource(self): project_book_resource = util.GetBookResource(name='projectbook') organization_book_resource = util.GetOrgShelfBookResource( name='orgbook') return multitype.MultitypeResourceSpec('book', project_book_resource, organization_book_resource)