#!/usr/share/ucs-test/runner python3
## -*- coding: utf-8 -*-
## desc: delete team in azure
## tags: [apptest]
## exposure: dangerous
## packages:
##   - univention-office365

import univention.testing.utils as utils
import univention.testing.ucr as ucr_test
import univention.testing.udm as udm_test
from univention.office365.api.graph import Graph
from univention.config_registry import handler_set

import helpers.office365_test_helpers as o365helpers


with utils.AutomaticListenerRestart():
	with ucr_test.UCSTestConfigRegistry() as ucr:
		with udm_test.UCSTestUDM() as udm:
			ucr.load()

			class _listener(object):
				configRegistry = ucr

			alias = 'o365domain'

			graph = Graph(
				ucr=ucr,
				name=__name__,
				connection_alias=alias
			)

			handler_set(["office365/groups/sync=yes"])
			utils.restart_listener()

			print("*** Creating members ***")
			user_dn, username = o365helpers.create_team_member(udm, ucr, alias)

			print("*** Creating Team ***")
			group_dn, group_name = o365helpers.create_team(udm, ucr, owner_dn=user_dn, users=[user_dn])

			print("*** Checking Team ***")
			created_team = o365helpers.check_team_created(graph, group_name)

		print("*** Checking Team Archived***")
		created_team = o365helpers.check_team_archived(graph, group_name)

		print("*** All went well.")
