Example #1
0
def load_development_data():
    for name, code in BERKELEY_DEPT_NAME_TO_CODE.items():
        UniversityDept.create(code, name, False)
    for test_user in _test_users:
        # This script can be run more than once. Do not create user if s/he exists in BOAC db.
        uid = test_user[0]
        csid = test_user[1]
        user = AuthorizedUser.find_by_uid(uid=uid)
        if uid != no_calnet_record_for_uid:
            # Put mock CalNet data in our json_cache for all users EXCEPT the test "no_calnet_record" user.
            first_name = ''.join(random.choices(string.ascii_uppercase, k=6))
            last_name = ''.join(random.choices(string.ascii_uppercase, k=6))
            calnet_feed = {
                'uid': uid,
                # Mock CSIDs are random unless we need them to correspond to test data elsewhere.
                'csid': csid or datetime.now().strftime('%H%M%S%f'),
                'firstName': first_name,
                'lastName': last_name,
                'name': f'{first_name} {last_name}',
            }
            if len(test_user) > 4:
                calnet_feed['departments'] = [
                    {
                        'code': test_user[4],
                        'name': BERKELEY_DEPT_CODE_TO_NAME.get(test_user[4]),
                    },
                ]
            insert_in_json_cache(f'calnet_user_for_uid_{uid}', calnet_feed)
        if not user:
            user = AuthorizedUser(uid=uid,
                                  is_admin=test_user[2],
                                  in_demo_mode=test_user[3])
            db.session.add(user)
    for dept_code, dept_membership in _university_depts.items():
        university_dept = UniversityDept.find_by_dept_code(dept_code)
        university_dept.automate_memberships = dept_membership[
            'automate_memberships']
        db.session.add(university_dept)
        for user in dept_membership['users']:
            authorized_user = AuthorizedUser.find_by_uid(user['uid'])
            UniversityDeptMember.create_membership(
                university_dept,
                authorized_user,
                user['is_advisor'],
                user['is_director'],
            )
    std_commit(allow_test_environment=True)
Example #2
0
def load_development_data():
    for name, code in BERKELEY_DEPT_NAME_TO_CODE.items():
        UniversityDept.create(code, name)
    for test_user in _test_users:
        # This script can be run more than once. Do not create user if s/he exists in BOAC db.
        user = AuthorizedUser.find_by_uid(uid=test_user[0])
        if not user:
            user = AuthorizedUser(uid=test_user[0], is_admin=test_user[1])
            db.session.add(user)
    for dept_code, users in _users_per_dept.items():
        university_dept = UniversityDept.find_by_dept_code(dept_code)
        for user in users:
            authorized_user = AuthorizedUser.find_by_uid(user['uid'])
            UniversityDeptMember.create_membership(
                university_dept,
                authorized_user,
                user['is_advisor'],
                user['is_director'],
            )
    std_commit(allow_test_environment=True)
Example #3
0
def _load_users_and_departments():
    for code, name in BERKELEY_DEPT_CODE_TO_NAME.items():
        UniversityDept.create(code, name)
    _create_users()
    _create_department_memberships()