Esempio n. 1
0
    def _SetupModules(self):
        """Compute and set the module(s) which this API belongs under."""
        # The containing module is based on the owner information.
        path = self.values.get('modulePath') or self.values.get('packagePath')
        self._containing_module = template_objects.Module(
            package_path=path,
            owner_name=self.values.get('owner'),
            owner_domain=self.values.get('ownerDomain'))
        self.SetTemplateValue('containingModule', self._containing_module)

        # The API is a child of the containing_module
        base = self.values['name']
        # TODO(user): Introduce a breaking change where we always prefer
        # canonicalName.
        if self.values.get('packagePath'):
            # Lowercase the canonical name only for non-cloud-endpoints Google APIs.
            # This is to avoid breaking changes to existing Google-owned Cloud
            # Endpoints APIs.
            if self.values.get('rootUrl').find('.googleapis.com') > 0:
                base = self.values.get('canonicalName').lower() or base
            else:
                base = self.values.get('canonicalName') or base
        if self.values.get('version_module'):
            base = '%s/%s' % (base, self.values['versionNoDots'])
        self._module = template_objects.Module(package_path=base,
                                               parent=self._containing_module)
        self.SetTemplateValue('module', self._module)

        # The default module for data models defined by this API.
        self._model_module = template_objects.Module(package_path=None,
                                                     parent=self._module)
Esempio n. 2
0
    def _SetupModules(self):
        """Compute and set the module(s) which this API belongs under."""
        # The containing module is based on the owner information.
        path = self.values.get('modulePath') or self.values.get('packagePath')
        self._containing_module = template_objects.Module(
            package_path=path,
            owner_name=self.values.get('owner'),
            owner_domain=self.values.get('ownerDomain'))
        self.SetTemplateValue('containingModule', self._containing_module)

        # The API is a child of the containing_module
        base = self.values['name']
        # TODO(user): Introduce a breaking change where we always prefer
        # canonicalName.
        if self.values.get('packagePath'):
            base = self.values.get('canonicalName') or base
        if self.values.get('version_module'):
            base = '%s/%s' % (base, self.values['versionNoDots'])
        self._module = template_objects.Module(package_path=base,
                                               parent=self._containing_module)
        self.SetTemplateValue('module', self._module)

        # The default module for data models defined by this API.
        self._model_module = template_objects.Module(package_path=None,
                                                     parent=self._module)
Esempio n. 3
0
  def testModuleNaming(self):
    p = template_objects.Module('hello/world',
                                language_model=self.language_model)
    foo = template_objects.CodeObject({'className': 'Foo'}, None,
                                      language_model=self.language_model)
    foo._module = p
    bar = template_objects.CodeObject({'className': 'Bar'}, None, parent=foo)
    baz = template_objects.CodeObject({'className': 'Baz'}, None, parent=bar)

    self.assertEquals('Foo|Bar|Baz', baz.packageRelativeClassName)
    self.assertEquals('hello|world|Foo|Bar|Baz', baz.fullClassName)
Esempio n. 4
0
  def testFullyQualifiedClassName(self):
    foo = template_objects.CodeObject({'className': 'Foo'}, None,
                                      language_model=self.language_model)
    foo._module = template_objects.Module('test',
                                          language_model=self.language_model)
    bar = template_objects.CodeObject({'className': 'Bar'}, None, parent=foo)
    baz = template_objects.CodeObject({'className': 'Baz'}, None, parent=bar)

    self.assertEquals('test|Foo|Bar|Baz', baz.fullClassName)
    self.assertEquals('', baz.RelativeClassName(baz))
    self.assertEquals('Baz', baz.RelativeClassName(bar))
    self.assertEquals('Bar|Baz', baz.RelativeClassName(foo))
Esempio n. 5
0
 def testModuleParenting(self):
   m = template_objects.Module('hello/world',
                               language_model=self.language_model)
   child = template_objects.Module('everyone', parent=m)
   self.assertEquals('hello|world|everyone', child.name)
   self.assertEquals('hello/world/everyone', child.path)
Esempio n. 6
0
 def testModule(self):
   m = template_objects.Module('hello/world',
                               language_model=self.language_model)
   self.assertEquals('hello|world', m.name)
   self.assertEquals('hello/world', m.path)