#!/usr/share/ucs-test/runner python
## -*- coding: utf-8 -*-
## desc: computerroom module settings checks
## roles: [domaincontroller_master, domaincontroller_slave]
## tags: [apptest,ucsschool]
## exposure: dangerous
## packages: [ucs-school-umc-computerroom]

from essential.computerroom import Room, Computers
from univention.lib.umc_connection import UMCConnection
from univention.testing.network import NetworkRedirector
import univention.testing.ucr as ucr_test
import univention.testing.ucsschool as utu


def main():
	with utu.UCSTestSchool() as schoolenv:
		with ucr_test.UCSTestConfigRegistry() as ucr:
			with NetworkRedirector() as nethelper:
				school, oudn = schoolenv.create_ou()
				tea, tea_dn = schoolenv.create_user(school, is_teacher=True)
				open_ldap_co = schoolenv.open_ldap_connection()

				# importing random 2 computers
				computers = Computers(open_ldap_co, school, 2, 0, 0)
				created_computers = computers.create()

				# setting computer rooms contains the created computers
				room = Room(school, host_members=created_computers[0].dn)
				# Creating the rooms
				schoolenv.create_computerroom(
					school,
					name=room.name,
					description=room.description,
					host_members=room.host_members
					)

				# preparing the network loop
				nethelper.add_loop(
					created_computers[0].ip,
					created_computers[1].ip)

				umc_connection = UMCConnection(ucr.get('hostname'))
				umc_connection.auth(tea, 'univention')

				# the actual test
				room.test_settings(
					school,
					tea,
					tea_dn,
					created_computers[1].ip,
					ucr,
					umc_connection)


if __name__ == '__main__':
	main()
