def test_teachers(ldap: Ldap): ldap.connect() ldap_utils.run_ldif('data/default-personnes-short.ldif', ldap) enseignants = ldap.search_enseignant() assert len(enseignants) > 0 for enseignant in enseignants: assert isinstance(enseignant, EnseignantLdap) ldap.disconnect()
def test_maj_enseignant(self, ldap: Ldap, db: Database, config: Config): ldap_utils.run_ldif('data/default-structures.ldif', ldap) ldap_utils.run_ldif('data/default-personnes-short.ldif', ldap) ldap_utils.run_ldif('data/default-groups.ldif', ldap) db_utils.run_script('data/default-context.sql', db, connect=False) synchronizer = Synchronizer(ldap, db, config) synchronizer.initialize() structure = ldap.get_structure("0290009C") enseignants = ldap.search_enseignant(None, "0290009C") enseignant = enseignants[1] etab_context = synchronizer.handle_etablissement(structure.uai) synchronizer.handle_enseignant(etab_context, enseignant) db.mark.execute( "SELECT * FROM {entete}user WHERE username = %(username)s".format( entete=db.entete), params={'username': str(enseignant.uid).lower()}) result = db.mark.fetchone() assert result is not None assert result[10] == 'Jules' assert result[11] == 'PICARD' assert result[12] == '*****@*****.**' assert result[27] == '0290009c' enseignant_id = result[0] db.mark.execute( "SELECT * FROM {entete}role_assignments WHERE userid = %(userid)s". format(entete=db.entete), params={'userid': enseignant_id}) roles_results = db.mark.fetchall() assert len(roles_results) == 3 assert roles_results[0][1] == 2 assert roles_results[0][2] == 3 assert roles_results[1][1] == 2 assert roles_results[1][2] == 1184277 assert roles_results[2][1] == 5 assert roles_results[2][2] == 1184278
def test_course_backup(self, ldap: Ldap, db: Database, config: Config): ldap_utils.run_ldif('data/default-structures.ldif', ldap) ldap_utils.run_ldif('data/default-personnes-short.ldif', ldap) ldap_utils.run_ldif('data/default-groups.ldif', ldap) db_utils.run_script('data/default-context.sql', db, connect=False) os = platform.system() if os == "Linux": config.webservice.backup_cmd = "sh backup.sh --courseid=%courseid% --destination=/MoodleBackups" elif os == "Windows": config.webservice.backup_cmd = "backup.bat --courseid=%courseid% --destination=/MoodleBackups" synchronizer = Synchronizer(ldap, db, config) synchronizer.initialize() etab_context = synchronizer.handle_etablissement("0290009C") ldap_eleves = ldap.search_eleve(uai="0290009C") ldap_enseignants = ldap.search_enseignant(uai="0290009C") enseignant = ldap_enseignants[0] enseignant2 = ldap_enseignants[1] for eleve in ldap_eleves: synchronizer.handle_eleve(etab_context, eleve) for enseignant in ldap_enseignants: synchronizer.handle_enseignant(etab_context, enseignant) db.mark.execute( "SELECT id FROM {entete}user WHERE username = %(username)s".format( entete=db.entete), params={'username': str(enseignant.uid).lower()}) enseignant_db = db.mark.fetchone() db.mark.execute( "SELECT id FROM {entete}user WHERE username = %(username)s".format( entete=db.entete), params={'username': str(enseignant2.uid).lower()}) enseignant2_db = db.mark.fetchone() now = synchronizer.context.timestamp_now_sql db.mark.execute( "INSERT INTO {entete}course (fullname, timemodified) VALUES ('cours de test 1'," " %(timemodified)s)".format(entete=db.entete), params={'timemodified': now}) db.mark.execute( "INSERT INTO {entete}course (fullname, timemodified) VALUES ('cours de test 2'," " %(timemodified)s)".format(entete=db.entete), params={'timemodified': now - 31622400}) db.mark.execute( "INSERT INTO {entete}course (fullname, timemodified) VALUES ('cours de test 3'," " %(timemodified)s)".format(entete=db.entete), params={'timemodified': now - 31622400}) db.mark.execute( "SELECT id, fullname, timemodified FROM {entete}course ORDER BY id DESC LIMIT 3" .format(entete=db.entete)) courses = db.mark.fetchall() for course in courses: db.mark.execute( "INSERT INTO {entete}context (contextlevel, instanceid) VALUES (50, %(instanceid)s)" .format(entete=db.entete), params={'instanceid': course[0]}) db.mark.execute( "SELECT id FROM {entete}context ORDER BY id DESC LIMIT 1". format(entete=db.entete)) contextid = db.mark.fetchone() db.add_role_to_user(config.constantes.id_role_proprietaire_cours, contextid[0], enseignant_db[0]) db.mark.execute( "INSERT INTO {entete}context (contextlevel, instanceid) VALUES (60, %(instanceid)s)" .format(entete=db.entete), params={'instanceid': courses[1][0]}) db.mark.execute( "SELECT id FROM {entete}context ORDER BY id DESC LIMIT 1".format( entete=db.entete)) contextid = db.mark.fetchone() db.add_role_to_user(config.constantes.id_role_proprietaire_cours, contextid[0], enseignant2_db[0]) synchronizer.check_and_process_user_courses(enseignant_db[0]) db.mark.execute( "SELECT id FROM {entete}course WHERE fullname LIKE 'cours de test%'" .format(entete=db.entete)) new_courses = db.mark.fetchall() new_courses_ids = [new_course[0] for new_course in new_courses] assert len(new_courses_ids) == 2 assert courses[0][0] not in new_courses_ids
def test_anonymize_useless_users(self, ldap: Ldap, db: Database, config: Config): ldap_utils.run_ldif('data/default-structures.ldif', ldap) ldap_utils.run_ldif('data/default-personnes-short.ldif', ldap) ldap_utils.run_ldif('data/default-groups.ldif', ldap) db_utils.run_script('data/default-context.sql', db, connect=False) synchronizer = Synchronizer(ldap, db, config) synchronizer.initialize() etab_context = synchronizer.handle_etablissement("0290009C") ldap_eleves = ldap.search_eleve(uai="0290009C") ldap_enseignants = ldap.search_enseignant(uai="0290009C") for eleve in ldap_eleves: synchronizer.handle_eleve(etab_context, eleve) for enseignant in ldap_enseignants: synchronizer.handle_enseignant(etab_context, enseignant) ldap_users = ldap.search_personne() db_valid_users = db.get_all_valid_users() users_to_anon = [] for i in range(0, 3): users_to_anon.append(ldap_users[i]) for user_to_anon in users_to_anon: ldap_users.remove(user_to_anon) age = db.get_timestamp_now() - (config.delete.delay_anonymize_student * 86400) - 1 db_valid_users = [(db_valid_user[0], db_valid_user[1], age) for db_valid_user in db_valid_users] synchronizer._Synchronizer__webservice.delete_users = lambda arg: None synchronizer.anonymize_or_delete_users(ldap_users, db_valid_users) db.mark.execute( "SELECT username, deleted, firstname, lastname, email, skype, yahoo, aim, msn, phone1, phone2," " department, address, city, description, lastnamephonetic, firstnamephonetic, middlename," " alternatename" " FROM {entete}user ORDER BY id LIMIT 3".format(entete=db.entete)) db_users = db.mark.fetchall() assert db_users[0][0] == 'f1700ivg' assert db_users[1][0] == 'f1700ivh' assert db_users[2][0] == 'f1700ivi' for x in range(0, 3): assert db_users[x][2] == config.constantes.anonymous_name assert db_users[x][3] == config.constantes.anonymous_name assert db_users[x][4] == config.constantes.anonymous_mail assert db_users[x][5] == config.constantes.anonymous_name assert db_users[x][6] == config.constantes.anonymous_name assert db_users[x][7] == config.constantes.anonymous_name assert db_users[x][8] == config.constantes.anonymous_name assert db_users[x][9] == config.constantes.anonymous_phone assert db_users[x][10] == config.constantes.anonymous_phone assert db_users[x][11] == config.constantes.anonymous_name assert db_users[x][12] == config.constantes.anonymous_name assert db_users[x][13] == config.constantes.anonymous_name assert db_users[x][14] is None assert db_users[x][15] == config.constantes.anonymous_name assert db_users[x][16] == config.constantes.anonymous_name assert db_users[x][17] == config.constantes.anonymous_name assert db_users[x][18] == config.constantes.anonymous_name
def test_teachers_empty(ldap: Ldap): ldap.connect() enseignants = ldap.search_enseignant() assert len(enseignants) == 0 ldap.disconnect()