示例#1
0
    def test_get_value_for_org(self):
        """
        Test to get an specific value for a given org.
        """
        self.assertEqual(
            TenantSiteConfigProxy.get_value_for_org(
                org="test1-org",
                val_name="value-test",
                default=None,
            ),
            "Hello-World3",
        )

        self.assertEqual(
            TenantSiteConfigProxy.get_value_for_org(
                org="test3-org",
                val_name="value-test",
                default=None,
            ),
            "Hello-World2",
        )

        self.assertEqual(
            TenantSiteConfigProxy.get_value_for_org(
                org="test4-org",
                val_name="value-test",
                default="Default",
            ),
            "Default",
        )
示例#2
0
    def test_get_site_values_with_unserializable_settings(self):
        """
        Test that if the settings are **not** json serializable `site_values`
        returns a subset of the original settings.
        """
        settings = {
            "EDNX_TENANT_KEY": True,
            "EDNX_USE_SIGNAL": True,
            "unserializable_settings": {
                "integer": 1,
                "float": 1.0,
                "string": "str",
                "bool": False,
                "null": None,
                "list": [1, True, 1.0, None],
                "tuple": (2, False, 0.5, None),
                "dict": {
                    "string": "str",
                    "12": None
                },
                "exception": Exception,
            }
        }

        with self.settings(**settings):
            site_configuration = TenantSiteConfigProxy()
            unserializable_settings = settings['unserializable_settings']

            site_values = site_configuration.site_values[
                'unserializable_settings']

            with self.assertRaises(TypeError):
                json.dumps(unserializable_settings)
            self.assertDictContainsSubset(site_values, unserializable_settings)
示例#3
0
    def test_get_site_values_with_serializable_settings(self):
        """
        Test that if the settings are json serializable `site_values`
        returns a dict with the same values and json.dumps doesn't fail.
        """
        settings = {
            "EDNX_TENANT_KEY": True,
            "EDNX_USE_SIGNAL": True,
            "serializable_settings": {
                "integer": 1,
                "float": 1.0,
                "string": "str",
                "bool": False,
                "null": None,
                "list": [1, True, 1.0, None],
                "tuple": (2, False, 0.5, None),
                "dict": {
                    "string": "str",
                    "12": None
                },
            }
        }

        with self.settings(**settings):
            site_configuration = TenantSiteConfigProxy()
            serializable_settings = settings['serializable_settings']

            site_values = site_configuration.site_values[
                'serializable_settings']

            self.assertDictEqual(serializable_settings, site_values)
            self.assertEqual(json.dumps(serializable_settings, sort_keys=True),
                             json.dumps(site_values, sort_keys=True))
示例#4
0
 def process_request(self, request):
     """
     Get the current site for a given request a set the configuration.
     """
     site = get_current_site(request)
     site.configuration = TenantSiteConfigProxy()
     request.site = site
示例#5
0
    def test_get_all_orgs(self):
        """
        Test to get all the orgs for Microsite and TenantConfig objects.
        """
        org_list = set([
            "test1-org",
            "test2-org",
            "test3-org",
            "test4-org",
            "test5-org",
        ])

        self.assertTrue(org_list == TenantSiteConfigProxy.get_all_orgs())
示例#6
0
    def test_create_site_configuration(self):
        """
        Test that a new TenantSiteConfigProxy instance is created with
        the current settings.
        """
        with self.settings(EDNX_USE_SIGNAL=False):
            site_configuration = TenantSiteConfigProxy()
            self.assertFalse(site_configuration.enabled)
            self.assertFalse(site_configuration.get_value("EDNX_TENANT_KEY"))
            self.assertFalse(site_configuration.get_value("EDNX_USE_SIGNAL"))

        with self.settings(EDNX_TENANT_KEY="test-key", EDNX_USE_SIGNAL=True):
            site_configuration = TenantSiteConfigProxy()
            self.assertTrue(site_configuration.enabled)
            self.assertTrue(site_configuration.get_value("EDNX_TENANT_KEY"))
            self.assertTrue(site_configuration.get_value("EDNX_USE_SIGNAL"))