Example #1
0
 def test_get_object_or_404(self, db):
     WikiGroup.create(name='wiki group 1', db_name='wikigroup1')
     WikiGroup.create(name='wiki group 2', db_name='wikigroup2')
     wiki_group = get_object_or_404(
         WikiGroup.select(WikiGroup.id, WikiGroup.db_name),
         WikiGroup.name == 'wiki group 2')
     assert wiki_group.id == 2
Example #2
0
def super_admin():
    """Manage wiki groups."""
    all_wiki_groups = WikiGroup.select().execute()
    form = AddWikiGroupForm()

    # Create a new wiki group with its own database and static file directory
    if form.validate_on_submit():
        new_wiki_group_name = form.wiki_group_name.data
        new_db_name = new_wiki_group_name.replace(' ', '')

        # Save the name of the new wiki group in database `_admin`
        # Remove whitespaces in the wiki group name.
        # Then use it to name the database which is about to be initialized.
        try:
            new_wiki_group = WikiGroup.create(name=new_wiki_group_name,
                                              db_name=new_db_name,
                                              active=True)
            os.mkdir(os.path.join(DB_PATH, new_wiki_group.db_name))
            query = WikiGroup.select().where(WikiGroup.active == True)
            current_app.active_wiki_groups = [
                wiki_group.db_name for wiki_group in query.execute()
            ]

            db.close()
            db.pick(new_wiki_group.db_filename())
            db.create_tables([
                WikiPage, WikiPageIndex, WikiPageVersion, WikiReference,
                WikiFile, WikiKeypage
            ])

            # Create wiki group home page, and the id is 1.
            WikiPage.create(title='Home')
            flash('New wiki group added', 'info')
            return redirect(url_for('.super_admin'))

        except IntegrityError:
            flash('Wiki Group already exists', 'warning')
        except FileExistsError:
            flash('Upload directory already exists.', 'warning')

    else:
        flash_errors(form)

    return render_template('admin/super_admin.html',
                           form=form,
                           all_wiki_groups=all_wiki_groups)
Example #3
0
 def test_unique_constraint(self, db):
     WikiGroup.create(name='wiki group 1', db_name='wikigroup1')
     with pytest.raises(IntegrityError):
         WikiGroup.create(name='wiki group 1', db_name='wikigroup1')