# Copyright (c) 2018, XhiveFramework Technologies and Contributors
# License: MIT. See LICENSE
import json

import xhiveframework
from xhiveframework.tests.utils import XhiveFrameworkTestCase


class TestPreparedReport(XhiveFrameworkTestCase):
	def setUp(self):
		self.report = xhiveframework.get_doc({"doctype": "Report", "name": "Permitted Documents For User"})
		self.filters = {"user": "Administrator", "doctype": "Role"}
		self.prepared_report_doc = xhiveframework.get_doc(
			{
				"doctype": "Prepared Report",
				"report_name": self.report.name,
				"filters": json.dumps(self.filters),
				"ref_report_doctype": self.report.name,
			}
		).insert()

	def tearDown(self):
		xhiveframework.set_user("Administrator")
		self.prepared_report_doc.delete()

	def test_for_creation(self):
		self.assertTrue("QUEUED" == self.prepared_report_doc.status.upper())
		self.assertTrue(self.prepared_report_doc.report_start_time)
