예제 #1
0
class TenantStaticFilesStorageTestCase(TenantTestCase):
    def setUp(self):
        super().setUp()
        settings.STATIC_ROOT = "/staticfiles"
        settings.STATIC_URL = "/static/"
        settings.MULTITENANT_RELATIVE_STATIC_ROOT = "%s/other_dir"

        self.storage = TenantStaticFilesStorage()

    def test_relative_static_root_raises_exception_if_no_static_root_configured(
            self):
        with self.assertRaises(ImproperlyConfigured):
            del settings.STATIC_ROOT

            self.storage.relative_static_root  # noqa Lookup static root

    def test_base_location(self):
        self.assertEqual(
            self.storage.base_location,
            "{}/{}/other_dir".format(settings.STATIC_ROOT,
                                     self.tenant.schema_name),
        )

    def test_base_location_defaults_to_appending_tenant_to_static_root(self):
        del settings.MULTITENANT_RELATIVE_STATIC_ROOT

        self.assertEqual(
            self.storage.base_location,
            "{}/{}".format(settings.STATIC_ROOT, self.tenant.schema_name),
        )

    def test_base_url_uses_static_url(self):
        self.assertEqual(self.storage.base_url, "/static/")

    @override_settings(REWRITE_STATIC_URLS=True)
    def test_base_url_rewrites_static_url(self):
        self.assertEqual(
            self.storage.base_url,
            "/static/{}/other_dir/".format(connection.schema_name))

    def test_base_url_defaults_to_static_url(self):
        del settings.MULTITENANT_RELATIVE_STATIC_ROOT

        self.assertEqual(self.storage.base_url, "/static/")

    def test_path_raises_exception_if_no_static_root_configured(self):
        with self.assertRaises(ImproperlyConfigured):
            del settings.STATIC_ROOT

            self.storage.path("test")
예제 #2
0
    def test_format_string(self):
        settings.MULTITENANT_RELATIVE_STATIC_ROOT = "%s/other_dir"
        storage = TenantStaticFilesStorage()

        # location
        path_suffix = "/staticfiles/{}/other_dir".format(
            self.tenant.schema_name)
        self.assertEqual(storage.location[-len(path_suffix):], path_suffix)

        # path
        path_suffix = "/staticfiles/{}/other_dir/foo.txt".format(
            self.tenant.schema_name)
        self.assertEqual(
            storage.path("foo.txt")[-len(path_suffix):], path_suffix)

        # base_url
        self.assertEqual(
            storage.base_url,
            "/static/{}/other_dir/".format(self.tenant.schema_name))

        # url
        self.assertEqual(
            storage.url("foo.txt"),
            "/static/{}/other_dir/foo.txt".format(self.tenant.schema_name),
        )
예제 #3
0
    def test_default(self):
        storage = TenantStaticFilesStorage()

        # location
        path_suffix = "/staticfiles/{}".format(self.tenant.schema_name)
        self.assertEqual(storage.location[-len(path_suffix):], path_suffix)

        # path
        path_suffix = "/staticfiles/{}/foo.txt".format(self.tenant.schema_name)
        self.assertEqual(
            storage.path("foo.txt")[-len(path_suffix):], path_suffix)

        # base_url
        self.assertEqual(storage.base_url,
                         "/static/{}/".format(self.tenant.schema_name))

        # url
        self.assertEqual(storage.url("foo.txt"),
                         "/static/{}/foo.txt".format(self.tenant.schema_name))
예제 #4
0
    def test_default(self):
        storage = TenantStaticFilesStorage()

        # location
        path_suffix = "/staticfiles/{}".format(self.tenant.schema_name)
        self.assertEqual(storage.location[-len(path_suffix):], path_suffix)

        # path
        path_suffix = "/staticfiles/{}/foo.txt".format(self.tenant.schema_name)
        self.assertEqual(storage.path("foo.txt")[-len(path_suffix):], path_suffix)

        # base_url
        self.assertEqual(
            storage.base_url, "/static/{}/".format(self.tenant.schema_name)
        )

        # url
        self.assertEqual(
            storage.url("foo.txt"), "/static/{}/foo.txt".format(self.tenant.schema_name)
        )
예제 #5
0
    def test_format_string(self):
        settings.MULTITENANT_RELATIVE_STATIC_ROOT = "%s/other_dir"
        storage = TenantStaticFilesStorage()

        # location
        path_suffix = "/staticfiles/{}/other_dir".format(self.tenant.schema_name)
        self.assertEqual(storage.location[-len(path_suffix):], path_suffix)

        # path
        path_suffix = "/staticfiles/{}/other_dir/foo.txt".format(
            self.tenant.schema_name
        )
        self.assertEqual(storage.path("foo.txt")[-len(path_suffix):], path_suffix)

        # base_url
        self.assertEqual(
            storage.base_url, "/static/{}/other_dir/".format(self.tenant.schema_name)
        )

        # url
        self.assertEqual(
            storage.url("foo.txt"),
            "/static/{}/other_dir/foo.txt".format(self.tenant.schema_name),
        )