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

from essential.computerroom import Computers
from essential.schoolroom import ComputerRoom
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:
			school, oudn = schoolenv.create_ou(name_edudc=ucr.get('hostname'))
			open_ldap_co = schoolenv.open_ldap_connection()

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

			room = ComputerRoom(school, host_members=[computers_dns[0]])
			room.add()
			room.verify_ldap(must_exist=True)
			room.get()

			room.check_query(room.name)

			new_attrs = {
					'name' : 'new_name',
					'description' : 'new_description',
					'computers': [computers_dns[1]]
					}
			room.check_put(new_attrs)

			# Test creating new room with the same name
			room2 = ComputerRoom(school, name=room.name, host_members=[computers_dns[1]])
			room2.add(accept_duplicated_name=True)

			room.remove()
			room.verify_ldap(must_exist=False)

if __name__ == '__main__':
	main()
