# Copyright (c) 2019, JINGROW and Contributors
# License: MIT. See LICENSE
import jingrow
from jingrow.core.pagetype.session_default_settings.session_default_settings import (
	clear_session_defaults,
	set_session_default_values,
)
from jingrow.tests.utils import JingrowTestCase


class TestSessionDefaultSettings(JingrowTestCase):
	def test_set_session_default_settings(self):
		jingrow.set_user("Administrator")
		settings = jingrow.get_single("Session Default Settings")
		settings.session_defaults = []
		settings.append("session_defaults", {"ref_pagetype": "Role"})
		settings.save()

		set_session_default_values({"role": "Website Manager"})

		todo = jingrow.get_pg(
			dict(pagetype="ToDo", description="test session defaults set", assigned_by="Administrator")
		).insert()
		self.assertEqual(todo.role, "Website Manager")

	def test_clear_session_defaults(self):
		clear_session_defaults()
		todo = jingrow.get_pg(
			dict(pagetype="ToDo", description="test session defaults cleared", assigned_by="Administrator")
		).insert()
		self.assertNotEqual(todo.role, "Website Manager")
