#!/usr/share/ucs-test/runner python
## -*- coding: utf-8 -*-
## desc: Test python interactive shell helper import
## tags: [apptest,ucsschool]
## roles: [domaincontroller_master]
## exposure: dangerous
## packages:
##   - ucs-school-import
## bugs: [41861]

import univention.testing.ucr
import univention.testing.ucsschool as utu
import univention.testing.strings as uts
import univention.testing.utils as utils

from ucsschool.importer.utils.shell import ImportStaff, ImportStudent, ImportTeacher, ImportTeachersAndStaff, logger, config


def main():
	if not isinstance(config, dict) or not isinstance(config["verbose"], bool):
		utils.fail("Import configuration has not been not setup.")
	with univention.testing.ucr.UCSTestConfigRegistry() as ucr:
		with utu.UCSTestSchool() as schoolenv:
			ou_name, ou_dn = schoolenv.create_ou(name_edudc=ucr.get('hostname'))
			lo = schoolenv.open_ldap_connection(admin=True)
			for kls in [ImportStaff, ImportStudent, ImportTeacher, ImportTeachersAndStaff]:
				user = kls(name=uts.random_username(), school=ou_name, firstname=uts.random_name(), lastname=uts.random_name())
				user.create(lo)
				utils.verify_ldap_object(user.dn, expected_attr={"uid": [user.name]}, strict=False, should_exist=True)
			logger.info("Test was successful.\n\n\n")


if __name__ == '__main__':
	main()
