def test_personnes(ldap: Ldap): ldap.connect() ldap_utils.run_ldif('data/default-personnes-short.ldif', ldap) personnes = ldap.search_personne() assert len(personnes) == 77 for person in personnes: assert isinstance(person, PersonneLdap) ldap.disconnect()
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_eleves(ldap: Ldap): ldap.connect() ldap_utils.run_ldif('data/default-personnes-short.ldif', ldap) eleves = ldap.search_eleve() assert len(eleves) > 0 for student in eleves: assert isinstance(student, EleveLdap) ldap.disconnect()
def reset(l: Ldap): l.connect() connection = l.connection try: _remove_all_in(connection, l.config.groupsDN) _remove_all_in(connection, l.config.personnesDN) _remove_all_in(connection, l.config.structuresDN) finally: l.disconnect()
def docker_config(config, docker_ip, docker_services): """ Configure l'application pour se connecter au container de test. S'assure également que les containers sont disponibles. :param config: :param docker_ip: :param docker_services: :return: """ docker_config = Config() docker_config.update(**json.loads( json.dumps(config, default=lambda o: getattr(o, '__dict__', str(o))))) docker_config.database.host = docker_ip now = datetime.datetime.now() timeout = 60 while True: docker_config.ldap.uri = "ldap://%s:%s" % ( docker_ip, docker_services.port_for('ldap-test', 389)) # Ensure ldap is available ldap = Ldap(docker_config.ldap) try: ldap.connect() except Exception as e: time.sleep(1) if (datetime.datetime.now() - now).seconds > timeout: raise e continue ldap.disconnect() break # Ensure database is available while True: docker_config.database.port = docker_services.port_for( 'moodle-db-test', 3306) db = Database(docker_config.database, docker_config.constantes) try: db.connect() except Exception as e: time.sleep(1) docker_config.database.host = docker_ip docker_config.database.port = docker_services.port_for( 'moodle-db-test', 3306) if (datetime.datetime.now() - now).seconds > timeout: raise e continue db.disconnect() break return docker_config
def test_structures(ldap: Ldap): ldap.connect() ldap_utils.run_ldif('data/default-structures.ldif', ldap) structures = ldap.search_structure() assert len(structures) == 2 for structure in structures: assert isinstance(structure, StructureLdap) getted_structure = ldap.get_structure(structure.uai) assert isinstance(getted_structure, StructureLdap) ldap.disconnect()
def manage_ldap(self, ldap: Ldap): ldap.connect() try: yield finally: ldap.disconnect()
def test_teachers_empty(ldap: Ldap): ldap.connect() enseignants = ldap.search_enseignant() assert len(enseignants) == 0 ldap.disconnect()
def test_eleves_empty(ldap: Ldap): ldap.connect() eleves = ldap.search_eleve() assert len(eleves) == 0 ldap.disconnect()
def test_personnes_empty(ldap: Ldap): ldap.connect() personnes = ldap.search_personne() assert len(personnes) == 0 ldap.disconnect()
def test_structures_empty(ldap: Ldap): ldap.connect() structures = ldap.search_structure() assert len(structures) == 0 ldap.disconnect()
def test_connection(ldap: Ldap): ldap.connect() assert isinstance(ldap.connection, Connection) ldap.disconnect() assert ldap.connection is None