Exemplo n.º 1
0
def ftest_setUp(test):
    ututi.tests.setUp(test)

    # U-niversity and D-epartment
    # should be used in writing new functional tests

    uni = LocationTag(u'U-niversity', u'uni', u'', member_policy='PUBLIC')
    dep = LocationTag(u'D-epartment', u'dep', u'', uni, member_policy='PUBLIC')
    meta.Session.add(uni)
    meta.Session.add(dep)
    meta.Session.commit()

    # Admin user, named 'Adminas Adminovix' for backward compatibility
    create_user('Adminas Adminovix', '*****@*****.**', 'xnIVufqLhFFcgX+XjkkwGbrY6kBBk0vvwjA7', 'uni')

    # Below are old locations, users, groups and subjects for backward compatibility
    # Note: objects that didn't have their location specified are now assigned to U-niversity

    vu = LocationTag(u'Vilniaus universitetas', u'vu', u'Seniausias universitetas Lietuvoje.',
                     member_policy='PUBLIC')
    ef = LocationTag(u'Ekonomikos fakultetas', u'ef', u'', vu, member_policy='PUBLIC')
    gf = LocationTag(u'Geografijos fakultetas', u'gf', u'', vu, member_policy='PUBLIC')
    meta.Session.add(vu)
    meta.Session.add(ef)
    meta.Session.add(gf)

    region = Region(u'Mazowieckie', u'lt')
    meta.Session.add(region)

    # Users:

    first = User(u'Alternative user', '*****@*****.**', uni, 'password', True)
    meta.Session.add(first)
    email = Email('*****@*****.**')
    email.confirmed = True
    first.emails.append(email)

    second = User(u'Second user', '*****@*****.**', uni, 'password', True)
    meta.Session.add(second)
    email = Email('*****@*****.**')
    email.confirmed = True
    second.emails.append(email)
    second.phone_number = '+37067412345'
    second.phone_confirmed = True

    admin = User.get('*****@*****.**', uni)
    admin.phone_number = '+37067812375'
    admin.phone_confirmed = True

    # Third user has hist email uncofirmed
    third = User(u'Third user', '*****@*****.**', uni, 'password', True)
    meta.Session.add(third)
    email = Email('*****@*****.**')
    email.confirmed = False
    third.emails.append(email)

    # A verified teacher Benas
    benas = Teacher(fullname=u'Benas',
                    username='******',
                    location=uni,
                    password='******',
                    gen_password=True)
    benas.teacher_verified = True
    meta.Session.add(benas)
    email = Email('*****@*****.**')
    email.confirmed = True
    benas.emails.append(email)

    # Groups:

    meta.Session.execute("SET LOCAL ututi.active_user TO %d" % admin.id)

    moderators = Group('moderators', u'Moderatoriai', uni, date(date.today().year, 1, 1), u'U2ti moderatoriai.')
    meta.Session.add(moderators)

    moderators.add_member(admin, True)
    moderators.add_member(third)

    testgroup = Group('testgroup', u'Testing group', LocationTag.get(u'vu'), date(date.today().year, 1, 1), u'Testing group')
    meta.Session.add(testgroup)
    testgroup.mailinglist_enabled = False
    testgroup.add_member(admin, True)
    testgroup.add_member(second)

    # Subjects:

    math = Subject(u'mat_analize', u'Matematin\u0117 analiz\u0117', LocationTag.get(u'vu'), u'prof. E. Misevi\u010dius')
    meta.Session.add(math)
    third.watchSubject(math)

    # Tags:

    tag = SimpleTag(u'simple_tag')
    meta.Session.add(tag)

    meta.Session.commit()
Exemplo n.º 2
0
def teacher_subjects(teacher_id):
    from ututi.model import Teacher
    return len(Teacher.get_global(teacher_id).taught_subjects)