Ejemplo n.º 1
0
def create_dummy_student():
    albino = Student(first_name='Albino',
                     last_name='Squirrel',
                     alternative_name='Albert',
                     ocmr='0000',
                     t_number='T00000000',
                     email_address='*****@*****.**')
    db_session.add(albino)
    db_session.commit()
Ejemplo n.º 2
0
def create_dummy_student():
    albino = Student(
        first_name='Albino',
        last_name='Squirrel',
        alternative_name='Albert',
        ocmr='0000',
        t_number='T00000000',
        email_address='*****@*****.**'
        )
    db_session.add(albino)
    db_session.commit()
Ejemplo n.º 3
0
def test_update_model():
    email_address = '*****@*****.**'
    password = bytes('zzz', 'ascii')
    verified = True
    role = 'employee'

    try:
        db_session = Session()

        # create dummy account
        account = Account(
            email_address=email_address,
            password=password,
            verified=False,  # to update 1
            role='student'  # to update 2
            )
        db_session.add(account)
        db_session.commit()

        # update account
        update_model(
            Account,
            Account.email_address.name,
            email_address,
            **{
                Account.verified.name: verified,
                Account.role.name: role
                }
            )

        # query updated dummy account
        account = db_session.query(
            Account
            ).filter_by(email_address=email_address).first()

        # test
        eq_(email_address, account.email_address)
        eq_(password, account.password)
        eq_(verified, account.verified)
        eq_(role, account.role)

    finally:
        # delete dummy account
        db_session.delete(account)
        db_session.commit()
Ejemplo n.º 4
0
def delete_dummy_student():
    student = db_session.query(Student).filter_by(ocmr='0000').first()
    db_session.delete(student)
    db_session.commit()
Ejemplo n.º 5
0
def test_update_model():
    email_address = '*****@*****.**'
    password = bytes('zzz', 'ascii')
    verified = True
    role = 'employee'

    try:
        db_session = Session()

        # create dummy account
        account = Account(
            email_address=email_address,
            password=password,
            verified=False,  # to update 1
            role='student'  # to update 2
        )
        db_session.add(account)
        db_session.commit()

        # update account
        update_model(
            Account, Account.email_address.name, email_address, **{
                Account.verified.name: verified,
                Account.role.name: role
            })

        # query updated dummy account
        account = db_session.query(Account).filter_by(
            email_address=email_address).first()

        # test
        eq_(email_address, account.email_address)
        eq_(password, account.password)
        eq_(verified, account.verified)
        eq_(role, account.role)

    finally:
        # delete dummy account
        db_session.delete(account)
        db_session.commit()
Ejemplo n.º 6
0
def delete_dummy_student():
    student = db_session.query(Student).filter_by(ocmr='0000').first()
    db_session.delete(student)
    db_session.commit()
Ejemplo n.º 7
0
def populate_student(csv_dictreader, db_session):
    for row in csv_dictreader:
        student = Student(
            first_name=row['first_name'],
            last_name=row['last_name'],
            # alternative_name='',
            ocmr=row['ocmr'],
            t_number='T01000000',
            email_address=row['email_id'] + '@oberlin.edu',
        )
        db_session.add(student)


if __name__ == '__main__':

    metadata = MetaData(bind=engine)

    with open(CSV_FILE) as f:
        # assume first line is header
        cf = csv.DictReader(f, delimiter=',')

        db_session = Session()
        try:
            populate_student(cf, db_session)
            db_session.commit()
        except:
            db_session.rollback()
            raise
        finally:
            db_session.close()
Ejemplo n.º 8
0
def populate_student(csv_dictreader, db_session):
    for row in csv_dictreader:
        student = Student(
            first_name=row['first_name'],
            last_name=row['last_name'],
            # alternative_name='',
            ocmr=row['ocmr'],
            t_number='T01000000',
            email_address=row['email_id']+'@oberlin.edu',
        )
        db_session.add(student)

if __name__ == '__main__':

    metadata = MetaData(bind=engine)

    with open(CSV_FILE) as f:
        # assume first line is header
        cf = csv.DictReader(f, delimiter=',')

        db_session = Session()
        try:
            populate_student(cf, db_session)
            db_session.commit()
        except:
            db_session.rollback()
            raise
        finally:
            db_session.close()
Ejemplo n.º 9
0
from flask import session as user_session

from getpost.hogwarts.fatlady import authenticate_user, deauthenticate_user
from getpost.hogwarts.fatlady import create_account
from getpost.models import Account, Student
from getpost.orm import Session

from .. import app, driver

email_address = '*****@*****.**'
password = '******'
remember_me = True
t_number = 'T01123456'

db_session = Session()


def test_authenticate_user():
    # test with non-existing account
    account = authenticate_user('*****@*****.**', password, remember_me)
    ok_(account is None)
    ok_('user_id' not in user_session)
    ok_('email_address' not in user_session)

    # test with existing account, wrong password
    account = authenticate_user(email_address, 'zzzz', remember_me)
    ok_(account is None)
    ok_('user_id' not in user_session)
    ok_('email_address' not in user_session)