コード例 #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)
コード例 #2
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)
コード例 #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)
コード例 #4
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)
コード例 #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)
コード例 #8
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)
コード例 #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)
コード例 #10
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)
コード例 #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())
コード例 #12
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())