Пример #1
0
    def test_updates_when_already_created(self):
        """Ensures an instance template is updated when already created."""
        def create_instance_template(*args, **kwargs):
            raise net.Error('', 409, '')

        def get_instance_template(*args, **kwargs):
            return {'selfLink': 'url'}

        self.mock(
            instance_templates.gce.Project,
            'create_instance_template',
            create_instance_template,
        )
        self.mock(
            instance_templates.gce.Project,
            'get_instance_template',
            get_instance_template,
        )

        key = models.InstanceTemplateRevision(
            key=instance_templates.get_instance_template_revision_key(
                'base-name',
                'revision',
            ),
            image_name='image',
            project='project',
        ).put()
        expected_url = 'url'

        instance_templates.create(key)
        self.assertEqual(key.get().url, expected_url)
  def test_updates_when_already_created(self):
    """Ensures an instance template is updated when already created."""
    def create_instance_template(*args, **kwargs):
      raise net.Error('', 409, '')
    def get_instance_template(*args, **kwargs):
      return {'selfLink': 'url'}
    self.mock(
        instance_templates.gce.Project,
        'create_instance_template',
        create_instance_template,
    )
    self.mock(
        instance_templates.gce.Project,
        'get_instance_template',
        get_instance_template,
    )

    key = models.InstanceTemplateRevision(
        key=instance_templates.get_instance_template_revision_key(
            'base-name',
            'revision',
        ),
        image_name='image',
        project='project',
    ).put()
    expected_url = 'url'

    instance_templates.create(key)
    self.assertEqual(key.get().url, expected_url)
Пример #3
0
    def test_creates(self):
        """Ensures an instance template is created."""
        def create_instance_template(*args, **kwargs):
            return {'targetLink': 'url'}

        self.mock(
            instance_templates.gce.Project,
            'create_instance_template',
            create_instance_template,
        )

        key = models.InstanceTemplateRevision(
            key=instance_templates.get_instance_template_revision_key(
                'base-name',
                'revision',
            ),
            image_name='image',
            metadata={
                'key': 'value',
            },
            project='project',
            service_accounts=[
                models.ServiceAccount(
                    name='service-account',
                    scopes=[
                        'scope',
                    ],
                ),
            ],
        ).put()
        expected_url = 'url'

        instance_templates.create(key)
        self.assertEqual(key.get().url, expected_url)
  def test_creates(self):
    """Ensures an instance template is created."""
    def create_instance_template(*args, **kwargs):
      return {'targetLink': 'url'}
    self.mock(
        instance_templates.gce.Project,
        'create_instance_template',
        create_instance_template,
    )

    key = models.InstanceTemplateRevision(
        key=instance_templates.get_instance_template_revision_key(
            'base-name',
            'revision',
        ),
        image_name='image',
        metadata={
            'key': 'value',
        },
        project='project',
        service_accounts=[
            models.ServiceAccount(
                name='service-account',
                scopes=[
                    'scope',
                ],
            ),
        ],
    ).put()
    expected_url = 'url'

    instance_templates.create(key)
    self.assertEqual(key.get().url, expected_url)
Пример #5
0
    def post(self):
        """Creates an instance template for the given InstanceTemplateRevision.

    Params:
      key: URL-safe key for a models.InstanceTemplateRevision.
    """
        key = ndb.Key(urlsafe=self.request.get('key'))
        assert key.kind() == 'InstanceTemplateRevision', key
        instance_templates.create(key)
Пример #6
0
  def post(self):
    """Creates an instance template for the given InstanceTemplateRevision.

    Params:
      key: URL-safe key for a models.InstanceTemplateRevision.
    """
    key = ndb.Key(urlsafe=self.request.get('key'))
    assert key.kind() == 'InstanceTemplateRevision', key
    instance_templates.create(key)
Пример #7
0
    def test_project_unspecified(self):
        """Ensures nothing happens when project is unspecified."""
        key = models.InstanceTemplateRevision(
            key=instance_templates.get_instance_template_revision_key(
                'base-name',
                'revision',
            ), ).put()

        instance_templates.create(key)
        self.failIf(key.get().url)
  def test_project_unspecified(self):
    """Ensures nothing happens when project is unspecified."""
    key = models.InstanceTemplateRevision(
        key=instance_templates.get_instance_template_revision_key(
            'base-name',
            'revision',
        ),
    ).put()

    instance_templates.create(key)
    self.failIf(key.get().url)
Пример #9
0
    def test_url_specified(self):
        """Ensures nothing happens when URL is already specified."""
        key = models.InstanceTemplateRevision(
            key=instance_templates.get_instance_template_revision_key(
                'base-name',
                'revision',
            ),
            project='project',
            url='url',
        ).put()
        expected_url = 'url'

        instance_templates.create(key)
        self.assertEqual(key.get().url, expected_url)
  def test_url_specified(self):
    """Ensures nothing happens when URL is already specified."""
    key = models.InstanceTemplateRevision(
        key=instance_templates.get_instance_template_revision_key(
            'base-name',
            'revision',
        ),
        project='project',
        url='url',
    ).put()
    expected_url = 'url'

    instance_templates.create(key)
    self.assertEqual(key.get().url, expected_url)
Пример #11
0
    def test_entity_doesnt_exist(self):
        """Ensures nothing happens when the entity doesn't exist."""
        key = ndb.Key(models.InstanceTemplateRevision, 'fake-key')

        instance_templates.create(key)
        self.failIf(key.get())
  def test_entity_doesnt_exist(self):
    """Ensures nothing happens when the entity doesn't exist."""
    key = ndb.Key(models.InstanceTemplateRevision, 'fake-key')

    instance_templates.create(key)
    self.failIf(key.get())