Example #1
0
def add_examinees(namelist):
    """Add examinees to the User table in the database.
    The namelist is a list of tuples. Each tuple contains the username,
    or user id, fullname, or real name, and exam id. If the username is
    None, a random username is generated.
    This function returns a list of tuples. Each tuple contains the username,
    password (randomly generated), fullname and exam id.
    """
    examinees = []
    for (username, fullname, exam_id) in namelist:
        username, password = get_user_id(username)
        user = User(username=username, role='examinee', fullname=fullname,
                exam_id=exam_id, answer_page='{}')
        user.hash_password(password)
        db.session.add(user)
        db.session.commit()
        examinees.append((username, password, fullname, exam_id))
    return examinees
Example #2
0
def add_admin(username, password, fullname):
    """Add an admin user to the User table in the database."""
    user = User(username=username, role='admin', fullname=fullname)
    user.hash_password(password)
    db.session.add(user)
    db.session.commit()
Example #3
0
import os
from website import db
from website.models import User
from website.admin import add_admin
from website.exam_admin import add_exam

db.reflect()
db.drop_all()
db.create_all()

os.chdir(os.path.join('tests', 'testdata'))
add_exam('silly1', 'Silly 1', os.path.join('exams', 'silly1.json'),
        os.path.join('exams', 'silly1_answers.json'))
add_admin('admin', 'pass', 'Admin')

user1 = User(username='******', role='examinee', fullname='Thomas Hardy', exam_id='silly1', answer_page='{}')
user1.hash_password('pass')
db.session.add(user1)
user2 = User(username='******', role='examinee', fullname='Franz Kafka', exam_id='silly1', answer_page='{}')
user2.hash_password('pass')
db.session.add(user2)
db.session.commit()
import os
from website import db
from website.models import User
from website.admin import add_admin
from website.exam_admin import add_exam

db.reflect()
db.drop_all()
db.create_all()

os.chdir(os.path.join('tests', 'testdata'))
add_exam('silly1', 'Silly 1', os.path.join('exams', 'silly1.json'),
         os.path.join('exams', 'silly1_answers.json'))
add_admin('admin', 'pass', 'Admin')

user1 = User(username='******',
             role='examinee',
             fullname='Thomas Hardy',
             exam_id='silly1',
             answer_page='{}')
user1.hash_password('pass')
db.session.add(user1)
user2 = User(username='******',
             role='examinee',
             fullname='Franz Kafka',
             exam_id='silly1',
             answer_page='{}')
user2.hash_password('pass')
db.session.add(user2)
db.session.commit()
def add_admin(username, password, fullname):
    """Add an admin user to the User table in the database."""
    user = User(username=username, role='admin', fullname=fullname)
    user.hash_password(password)
    db.session.add(user)
    db.session.commit()