# Copyright (c) 2019, JINGROW and Contributors
# License: MIT. See LICENSE
import jingrow
from jingrow.config import get_modules_from_all_apps_for_user
from jingrow.core.pagetype.user.test_user import test_user
from jingrow.tests.utils import JingrowTestCase


class TestDashboard(JingrowTestCase):
	def test_permission_query(self):
		for user in ["Administrator", "test@example.com"]:
			with self.set_user(user):
				jingrow.get_list("Dashboard")

		with test_user(roles=["_Test Role"]) as user:
			with self.set_user(user.name):
				jingrow.get_list("Dashboard")
				with self.set_user("Administrator"):
					all_modules = get_modules_from_all_apps_for_user("Administrator")
					for module in all_modules:
						user.append("block_modules", {"module": module.get("module_name")})
					user.save()
				jingrow.get_list("Dashboard")
