Exemple #1
0
def delete_powertype(id):
    """
    Deletes a power type by the given id.

    :param id: The id of the power type to be deleted.
    :status 204: Power type successfully deleted.
    :status 400: Power type is referenced by systems.
    :status 404: Power type can not be found.
    """
    try:
        powertype = PowerType.by_id(id)
    except NoResultFound:
        raise NotFound404('Power type: %s does not exist' % id)

    systems_referenced = System.query.join(System.power).filter(
        Power.power_type == powertype).count()
    if systems_referenced:
        raise BadRequest400('Power type %s still referenced by %i systems' % (
            powertype.name, systems_referenced))

    session.delete(powertype)

    activity = Activity(identity.current.user, u'HTTP', u'Deleted', u'PowerType', powertype.name)
    session.add(activity)

    return '', 204
Exemple #2
0
def delete_powertype(id):
    """
    Deletes a power type by the given id.

    :param id: The id of the power type to be deleted.
    :status 204: Power type successfully deleted.
    :status 400: Power type is referenced by systems.
    :status 404: Power type can not be found.
    """
    try:
        powertype = PowerType.by_id(id)
    except NoResultFound:
        raise NotFound404('Power type: %s does not exist' % id)

    systems_referenced = System.query.join(
        System.power).filter(Power.power_type == powertype).count()
    if systems_referenced:
        raise BadRequest400('Power type %s still referenced by %i systems' %
                            (powertype.name, systems_referenced))

    session.delete(powertype)

    activity = Activity(identity.current.user, u'HTTP', u'Deleted',
                        u'PowerType', powertype.name)
    session.add(activity)

    return '', 204
 def test_token_is_ignored_if_proxy_does_not_exist(self):
     # As above, this should never actually happen.
     user = data_setup.create_user()
     proxy = data_setup.create_user()
     cookie = self.acquire_cookie(user, proxy)
     session.delete(proxy)
     session.flush()
     with app.test_request_context(headers={'Cookie': cookie}):
         identity.check_authentication()
         self.assertIsNone(identity.current.user)
         self.assertIsNone(identity.current.proxied_by_user)
 def test_token_is_ignored_if_user_does_not_exist(self):
     # This should be impossible since we don't allow deleting User objects.
     # But let's test it for completeness' sake.
     user = data_setup.create_user()
     cookie = self.acquire_cookie(user)
     session.delete(user)
     session.flush()
     with app.test_request_context(headers={'Cookie': cookie}):
         identity.check_authentication()
         self.assertIsNone(identity.current.user)
         self.assertIsNone(identity.current.proxied_by_user)
 def test_token_is_ignored_if_proxy_does_not_exist(self):
     # As above, this should never actually happen.
     user = data_setup.create_user()
     proxy = data_setup.create_user()
     cookie = self.acquire_cookie(user, proxy)
     session.delete(proxy)
     session.flush()
     with app.test_request_context(headers={'Cookie': cookie}):
         identity.check_authentication()
         self.assertIsNone(identity.current.user)
         self.assertIsNone(identity.current.proxied_by_user)
 def test_token_is_ignored_if_user_does_not_exist(self):
     # This should be impossible since we don't allow deleting User objects. 
     # But let's test it for completeness' sake.
     user = data_setup.create_user()
     cookie = self.acquire_cookie(user)
     session.delete(user)
     session.flush()
     with app.test_request_context(headers={'Cookie': cookie}):
         identity.check_authentication()
         self.assertIsNone(identity.current.user)
         self.assertIsNone(identity.current.proxied_by_user)
Exemple #7
0
    def lab_controller_remove(self, id):
        try:
            lca = LabControllerDistroTree.by_id(id)
        except NoResultFound:
            flash(_(u'Invalid lab_controller_assoc id %s') % id)
            redirect('.')

        session.delete(lca)
        lca.distro_tree.activity.append(DistroTreeActivity(
                user=identity.current.user, service=u'WEBUI',
                action=u'Removed', field_name=u'lab_controller_assocs',
                old_value=u'%s %s' % (lca.lab_controller, lca.url),
                new_value=None))
        flash(_(u'Deleted %s %s') % (lca.lab_controller, lca.url))
        redirect(str(lca.distro_tree.id))
Exemple #8
0
 def test_delete_non_existing_pool(self):
     with session.begin():
         pool = data_setup.create_system_pool()
     b = self.browser
     login(b)
     self.go_to_pool_edit(pool)
     session.delete(pool)
     session.flush()
     b.find_element_by_xpath('//button[contains(string(.), "Delete")]').click()
     modal = b.find_element_by_class_name('modal')
     modal.find_element_by_xpath('.//p[text()="Are you sure you want to '
             'delete this pool?"]')
     modal.find_element_by_xpath('.//button[text()="OK"]').click()
     self.assertIn('System pool %s does not exist' % pool.name,
             b.find_element_by_class_name('alert-error').text)
Exemple #9
0
    def lab_controller_remove(self, id):
        try:
            lca = LabControllerDistroTree.by_id(id)
        except NoResultFound:
            flash(_(u'Invalid lab_controller_assoc id %s') % id)
            redirect('.')

        session.delete(lca)
        lca.distro_tree.activity.append(DistroTreeActivity(
                user=identity.current.user, service=u'WEBUI',
                action=u'Removed', field_name=u'lab_controller_assocs',
                old_value=u'%s %s' % (lca.lab_controller, lca.url),
                new_value=None))
        flash(_(u'Deleted %s %s') % (lca.lab_controller, lca.url))
        redirect(str(lca.distro_tree.id))
 def test_delete_non_existing_pool(self):
     with session.begin():
         pool = data_setup.create_system_pool()
     b = self.browser
     login(b)
     self.go_to_pool_edit(pool)
     session.delete(pool)
     session.flush()
     b.find_element_by_xpath(
         '//button[contains(string(.), "Delete")]').click()
     modal = b.find_element_by_class_name('modal')
     modal.find_element_by_xpath('.//p[text()="Are you sure you want to '
                                 'delete this pool?"]')
     modal.find_element_by_xpath('.//button[text()="OK"]').click()
     self.assertIn('System pool %s does not exist' % pool.name,
                   b.find_element_by_class_name('alert-error').text)