# Copyright (c) 2018, InfluxFramework LLC
# License: MIT. See LICENSE
import json

import influxframework
from influxframework.tests.utils import InfluxFrameworkTestCase


class TestPreparedReport(InfluxFrameworkTestCase):
	def setUp(self):
		self.report = influxframework.get_doc({"doctype": "Report", "name": "Permitted Documents For User"})
		self.filters = {"user": "Administrator", "doctype": "Role"}
		self.prepared_report_doc = influxframework.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):
		influxframework.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)
