예제 #1
0
def delete_project_route():

    # Get project id
    project_id = request.form.get("project_id")

    # Get user id from session
    user = session.get("user")
    user_id = str(user["sub"])

    # Validate project id
    temp = db.execute("SELECT user_id, search_id FROM projects WHERE id = ?",
                      project_id)
    if len(temp) != 1:
        return "Error 400: Bad request"

    # Ensure user owns project
    if temp[0]["user_id"] != user_id:
        return "Error 400: Bad request"

    # Get search id
    project_search_id = temp[0]["search_id"]

    delete_project(project_id, project_search_id)

    return redirect("/")
    def tearDown(self):
        print '\n\n\n --- TEARDOWN ---'
        if sys.exc_info()[0] is not None:
            make_screenshot(self.driver)
        print 'Provider exists: ', self.provider_exists
        if self.provider_exists:
            try:
                # Delete provider
                print 'Provider is going to be deleted.'
                delete_provider(self.driver, Settings.provider_name)
                self.provider_exists = False
                time.sleep(BaseSettings.click_time_wait)
                search_field = self.driver.find_element_by_css_selector(
                    '[ng-model="generalSearch"]')
                search_field.clear()
                search_field.send_keys(Settings.provider_name)
                time.sleep(BaseSettings.search_time_wait)
                assert not element_exists(
                    self.driver,
                    xpath='//span[contains(text(), "%s")]' %
                    Settings.provider_name
                ), ('Error: Provider with name "%s" was not deleted, it still exists'
                    % Settings.provider_name)
                print 'Provider was deleted successfully.'
            except Exception as e:
                print 'Provider cannot be deleted. Error: "%s"' % e

        if self.project_exists:
            try:
                # Delete project
                print 'Project is going to be deleted.'
                delete_project(self.driver, Settings.project_name)
                self.project_exists = False
                time.sleep(BaseSettings.click_time_wait)
                search_field = self.driver.find_element_by_css_selector(
                    '[ng-model="generalSearch"]')
                search_field.clear()
                search_field.send_keys(Settings.project_name)
                time.sleep(BaseSettings.search_time_wait)
                if element_exists(self.driver,
                                  xpath='//a[contains(text(), "%s")]' %
                                  Settings.project_name):
                    self.project_exists = True
                print 'Project was deleted successfully.'
            except Exception as e:
                print 'Project cannot be deleted. Error: "%s"' % e

        if self.resource_exists:
            print 'Warning! Test cannot unlink resource "%s". It has to be unlinked manually.' % Settings.resource_name
        if self.provider_exists:
            print 'Warning! Test cannot delete provider "%s". It has to be deleted manually.' % Settings.provider_name
        if self.project_exists:
            print 'Warning! Test cannot delete project "%s". It has to be deleted manually.' % Settings.project_name

        self.driver.quit()
    def tearDown(self):
        print '\n\n\n --- TEARDOWN ---'
        if sys.exc_info()[0] is not None:
            make_screenshot(self.driver)
        print 'Provider exists: ', self.provider_exists
        if self.provider_exists:
            try:
                # Delete provider
                print 'Provider is going to be deleted.'
                delete_provider(self.driver, Settings.provider_name)
                self.provider_exists = False
                time.sleep(BaseSettings.click_time_wait)
                search_field = self.driver.find_element_by_css_selector('[ng-model="generalSearch"]')
                search_field.clear()
                search_field.send_keys(Settings.provider_name)
                time.sleep(BaseSettings.search_time_wait)
                assert not element_exists(self.driver, xpath='//span[contains(text(), "%s")]' % Settings.provider_name), (
                    'Error: Provider with name "%s" was not deleted, it still exists' % Settings.provider_name)
                print 'Provider was deleted successfully.'
            except Exception as e:
                print 'Provider cannot be deleted. Error: "%s"' % e

        if self.project_exists:
            try:
                # Delete project
                print 'Project is going to be deleted.'
                delete_project(self.driver, Settings.project_name)
                self.project_exists = False
                time.sleep(BaseSettings.click_time_wait)
                search_field = self.driver.find_element_by_css_selector('[ng-model="generalSearch"]')
                search_field.clear()
                search_field.send_keys(Settings.project_name)
                time.sleep(BaseSettings.search_time_wait)
                if element_exists(self.driver, xpath='//a[contains(text(), "%s")]' % Settings.project_name):
                    self.project_exists = True
                print 'Project was deleted successfully.'
            except Exception as e:
                print 'Project cannot be deleted. Error: "%s"' % e

        if self.resource_exists:
            print 'Warning! Test cannot unlink resource "%s". It has to be unlinked manually.' % Settings.resource_name
        if self.provider_exists:
            print 'Warning! Test cannot delete provider "%s". It has to be deleted manually.' % Settings.provider_name
        if self.project_exists:
            print 'Warning! Test cannot delete project "%s". It has to be deleted manually.' % Settings.project_name

        self.driver.quit()
    def tearDown(self):
        print '\n\n\n --- TEARDOWN ---'
        if sys.exc_info()[0] is not None:
            make_screenshot(self.driver)
        if self.project_exists:
            try:
                # Delete project
                print 'Project is going to be deleted.'
                delete_project(self.driver, Settings.project_name)
                self.project_exists = False
                print 'Project exists: ', self.project_exists
                time.sleep(BaseSettings.click_time_wait)
                _search(self.driver, Settings.project_name)
                if element_exists(self.driver, xpath='//a[contains(text(), "%s")]' % Settings.project_name):
                    self.project_exists = True
                print 'Project was deleted successfully.'
            except Exception as e:
                print 'Project cannot be deleted. Error: "%s"' % e

        if self.ssh_key_exists:
            try:
                # Delete ssh key
                print 'Ssh key is going to be deleted.'
                delete_ssh_key(self.driver, Settings.key_name, Settings.user_full_name)
                self.ssh_key_exists = False
                print 'SSH key exists: ', self.ssh_key_exists
                _search(self.driver, Settings.key_name)
                assert not element_exists(self.driver, xpath='//span[contains(text(), "%s")]' % Settings.key_name), (
                    'Error: SSH key with name "%s" was not deleted, it still exists' % Settings.key_name)
                print 'SSH key was deleted successfully.'
            except Exception as e:
                print 'SSH key cannot be deleted. Error: %s' % e

        if self.resource_exists:
            print 'Warning! Test cannot delete resource %s. It has to be deleted manually.' % Settings.resource_name
        if self.project_exists:
            print 'Warning! Test cannot delete project %s. It has to be deleted manually.' % Settings.project_name
        if self.ssh_key_exists:
            print 'Warning! Test cannot delete ssh key %s. It has to be deleted manually.' % Settings.key_name

        self.driver.quit()
def projects_delete():
    token_response = helpers.validate_jwt(request)
    if not token_response["success"]:
        return jsonify(token_response), 401
    if helpers.delete_project(request.json.get("project_id")):
        return jsonify({
            "success": True,
        })

    return jsonify({
        "success": False,
        "msg": "Something went wrong deleting that project."
    })
    def tearDown(self):
        print '\n\n\n --- TEARDOWN ---'
        if sys.exc_info()[0] is not None:
            make_screenshot(self.driver)
        if self.application_project_exists:
            try:
                # Delete application project
                print 'Application project is going to be deleted.'
                delete_application_project(self.driver, Settings.project_name, Settings.application_project_name)
                self.application_project_exists = False
                print 'Application project exists: ', self.application_project_exists
                _search(self.driver, Settings.application_project_name)
                print 'Wait till application project will be deleted'
                try:
                    WebDriverWait(self.driver, Settings.time_wait_to_delete_application).until(
                        EC.invisibility_of_element_located((By.XPATH, '//a[contains(text(), "%s")]' % Settings.application_project_name)))
                except TimeoutException as e:
                    print 'Error: Application project with name "%s" was not deleted, it still exists' % Settings.application_project_name
                    raise e
                else:
                    print 'Application project was deleted successfully.'
            except Exception as e:
                print 'Application project cannot be deleted. Error: %s' % e

        if self.application_group_exists:
            try:
                # Delete application group
                print 'Application group is going to be deleted.'
                delete_application_group(self.driver, Settings.project_name, Settings.application_group_name)
                self.application_group_exists = False
                print 'Application group exists: ', self.application_group_exists
                _search(self.driver, Settings.application_group_name)
                print 'Wait till application group will be deleted'
                try:
                    WebDriverWait(self.driver, Settings.time_wait_to_delete_application).until(
                        EC.invisibility_of_element_located((By.XPATH, '//a[contains(text(), "%s")]' % Settings.application_group_name)))
                except TimeoutException as e:
                    print 'Error: Application group with name "%s" was not deleted, it still exists' % Settings.application_group_name
                    raise e
                else:
                    print 'Application group was deleted successfully.'
            except Exception as e:
                print 'Application group cannot be deleted. Error: %s' % e

        if self.project_exists:
            try:
                # Delete project
                print 'Project is going to be deleted.'
                delete_project(self.driver, Settings.project_name)
                self.project_exists = False
                print 'Project exists: ', self.project_exists
                time.sleep(BaseSettings.click_time_wait)
                _search(self.driver, Settings.project_name)
                if element_exists(self.driver, xpath='//a[contains(text(), "%s")]' % Settings.project_name):
                    self.project_exists = True
                print 'Project was deleted successfully.'
            except Exception as e:
                print 'Project cannot be deleted. Error: "%s"' % e

        if self.application_project_exists:
            print 'Warning! Test cannot delete application project %s. It has to be deleted manually.' % Settings.application_project_name
        if self.application_group_exists:
            print 'Warning! Test cannot delete application group %s. It has to be deleted manually.' % Settings.application_group_name
        if self.project_exists:
            print 'Warning! Test cannot delete project %s. It has to be deleted manually.' % Settings.project_name

        self.driver.quit()