#!/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(name_edudc=ucr.get('hostname'))
				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()
				computers_dns = computers.get_dns(created_computers)
				computers_ips = computers.get_ips(created_computers)

				# setting computer rooms contains the created computers
				room = Room(school, host_members=computers_dns[0])
				# 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(computers_ips[0], computers_ips[1])

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

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

if __name__ == '__main__':
	main()
