Ejemplo n.º 1
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)
Ejemplo n.º 2
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"))
Ejemplo n.º 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))
Ejemplo n.º 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