#!/usr/bin/python

import os
import sys

from xvfbwrapper import Xvfb
import pytest
import shutil

from univention.config_registry import ConfigRegistry
from univention.testing import selenium

os.environ['UCSTEST_SELENIUM'] = 'local'
os.environ['UCSTEST_SELENIUM_BROWSER'] = 'chrome'
os.environ['PATH'] = "%s:/usr/lib/chromium" % (os.environ['PATH'])

ucr = ConfigRegistry()
ucr.load()
hostname = '%s.%s' % (ucr.get('hostname'), ucr.get('domainname'))
username = ucr.get('tests/domainadmin/account').split(',')[0].split('=')[-1]
pwdfile = ucr.get('tests/domainadmin/pwdfile')
password = open(pwdfile).read().strip()

def test_info():
	with Xvfb():
		with selenium.UMCSeleniumTest() as s:
			s.driver.get('https://%s:%s@%s:4447' % (username, password, hostname))
			s.wait_for_text('opsiconfd info', timeout=10)

if __name__ == '__main__':
	fname = '/tmp/opsitest.py'
	shutil.copy2(__file__, fname)
	sys.exit(pytest.main([fname]))