# Copyright (c) 2020, JINGROW and Contributors
# License: MIT. See LICENSE
import jingrow
from jingrow.tests.utils import JingrowTestCase


class TestModuleProfile(JingrowTestCase):
	def test_make_new_module_profile(self):
		if not jingrow.db.get_value("Module Profile", "_Test Module Profile"):
			jingrow.get_pg(
				{
					"pagetype": "Module Profile",
					"module_profile_name": "_Test Module Profile",
					"block_modules": [{"module": "Accounts"}],
				}
			).insert()

		# add to user and check
		if not jingrow.db.get_value("User", "test-for-module_profile@example.com"):
			new_user = jingrow.get_pg(
				{"pagetype": "User", "email": "test-for-module_profile@example.com", "first_name": "Test User"}
			).insert()
		else:
			new_user = jingrow.get_pg("User", "test-for-module_profile@example.com")

		new_user.module_profile = "_Test Module Profile"
		new_user.save()

		self.assertEqual(new_user.block_modules[0].module, "Accounts")
