Beispiel #1
0
    def test_deleted(self):
        """Ensures the entity is marked deleted when the instance doesn't exists."""
        def json_request(*args, **kwargs):
            raise net.NotFoundError('404', 404, '404')

        def send_machine_event(*args, **kwargs):
            pass

        self.mock(cleanup.net, 'json_request', json_request)
        self.mock(cleanup.metrics, 'send_machine_event', send_machine_event)

        key = models.Instance(
            key=instances.get_instance_key(
                'base-name',
                'revision',
                'zone',
                'instance-name',
            ),
            pending_deletion=True,
            url='url',
        ).put()

        cleanup.check_deleted_instance(key)

        self.failUnless(key.get().deleted)
Beispiel #2
0
    def test_entity_not_found(self):
        """Ensures nothing happens when the entity is not found."""
        key = ndb.Key(models.Instance, 'fake-key')

        cleanup.check_deleted_instance(key)

        self.failIf(key.get())
Beispiel #3
0
    def post(self):
        """Checks whether an instance has been deleted.

    Params:
      key: URL-safe key for a models.Instance.
    """
        key = ndb.Key(urlsafe=self.request.get('key'))
        assert key.kind() == 'Instance', key
        cleanup.check_deleted_instance(key)
Beispiel #4
0
    def test_no_url(self):
        """Ensures nothing happens when the entity has no URL."""
        key = models.Instance(
            key=instances.get_instance_key(
                'base-name',
                'revision',
                'zone',
                'instance-name',
            ),
            pending_deletion=True,
        ).put()

        cleanup.check_deleted_instance(key)

        self.failIf(key.get().deleted)
Beispiel #5
0
    def test_not_pending_deletion(self):
        """Ensures nothing happens when the entity is not pending deletion."""
        key = models.Instance(
            key=instances.get_instance_key(
                'base-name',
                'revision',
                'zone',
                'instance-name',
            ),
            url='url',
        ).put()

        cleanup.check_deleted_instance(key)

        self.failIf(key.get().deleted)
Beispiel #6
0
    def test_exists(self):
        """Ensures nothing happens when the instance still exists."""
        def json_request(*args, **kwargs):
            return {}

        self.mock(cleanup.net, 'json_request', json_request)

        key = models.Instance(
            key=instances.get_instance_key(
                'base-name',
                'revision',
                'zone',
                'instance-name',
            ),
            pending_deletion=True,
            url='url',
        ).put()

        cleanup.check_deleted_instance(key)

        self.failIf(key.get().deleted)