Beispiel #1
0
    def __init__(self, apps=None, *args, **kwargs):
        # List of locations with static files
        self.locations = get_directories_in_tethys(('static', 'public'), with_app_name=True)

        # Maps dir paths to an appropriate storage instance
        self.storages = SortedDict()

        for prefix, root in self.locations:
            filesystem_storage = FileSystemStorage(location=root)
            filesystem_storage.prefix = prefix
            self.storages[root] = filesystem_storage

        super().__init__(*args, **kwargs)
Beispiel #2
0
    def test_get_directories_in_tethys_templates_apps_import_error(self, mock_harvester):
        # Mock the extension_modules variable with bad data, to throw an ImportError
        mock_harvester().app_modules = {'foo_invalid_foo': 'tethys_app.foo_invalid_foo'}

        result = utilities.get_directories_in_tethys(('templates',))
        self.assertGreaterEqual(len(result), 0)

        test_app = False

        for r in result:
            if '/tethysapp/foo_invalid_foo/templates' in r:
                test_app = True

        self.assertFalse(test_app)
Beispiel #3
0
    def __init__(self, apps=None, *args, **kwargs):
        # List of locations with static files
        self.locations = get_directories_in_tethys(('static', 'public'),
                                                   with_app_name=True)

        # Maps dir paths to an appropriate storage instance
        self.storages = SortedDict()

        for prefix, root in self.locations:
            filesystem_storage = FileSystemStorage(location=root)
            filesystem_storage.prefix = prefix
            self.storages[root] = filesystem_storage

        super().__init__(*args, **kwargs)
Beispiel #4
0
    def test_get_directories_in_tethys_templates(self):
        # Get the templates directories for the test_app and test_extension
        result = utilities.get_directories_in_tethys(('templates',))
        self.assertGreaterEqual(len(result), 2)

        test_app = False
        test_ext = False

        for r in result:
            if '/tethysapp/test_app/templates' in r:
                test_app = True
            if '/tethysext-test_extension/tethysext/test_extension/templates' in r:
                test_ext = True

        self.assertTrue(test_app)
        self.assertTrue(test_ext)
Beispiel #5
0
    def test_get_directories_in_tethys_templates(self):
        # Get the templates directories for the test_app and test_extension
        result = utilities.get_directories_in_tethys(('templates',))
        self.assertGreaterEqual(len(result), 2)

        test_app = False
        test_ext = False

        for r in result:
            if '/tethysapp/test_app/templates' in r:
                test_app = True
            if '/tethysext-test_extension/tethysext/test_extension/templates' in r:
                test_ext = True

        self.assertTrue(test_app)
        self.assertTrue(test_ext)
Beispiel #6
0
    def test_get_directories_in_tethys_foo_public(self):
        # Get the foo and public directories for the test_app and test_extension
        # foo doesn't exist, but public will
        result = utilities.get_directories_in_tethys(('foo', 'public'))
        self.assertGreaterEqual(len(result), 2)

        test_app = False
        test_ext = False

        for r in result:
            if '/tethysapp/test_app/public' in r:
                test_app = True
            if '/tethysext-test_extension/tethysext/test_extension/public' in r:
                test_ext = True

        self.assertTrue(test_app)
        self.assertTrue(test_ext)
Beispiel #7
0
    def test_get_directories_in_tethys_foo_public(self):
        # Get the foo and public directories for the test_app and test_extension
        # foo doesn't exist, but public will
        result = utilities.get_directories_in_tethys(('foo', 'public'))
        self.assertGreaterEqual(len(result), 2)

        test_app = False
        test_ext = False

        for r in result:
            if '/tethysapp/test_app/public' in r:
                test_app = True
            if '/tethysext-test_extension/tethysext/test_extension/public' in r:
                test_ext = True

        self.assertTrue(test_app)
        self.assertTrue(test_ext)
Beispiel #8
0
    def test_get_directories_in_tethys_templates_extension_import_error(self, mock_harvester):
        # Mock the extension_modules variable with bad data, to throw an ImportError
        mock_harvester().extension_modules = {'foo_invalid_foo': 'tethysext.foo_invalid_foo'}

        result = utilities.get_directories_in_tethys(('templates',))
        self.assertGreaterEqual(len(result), 1)

        test_app = False
        test_ext = False

        for r in result:
            if '/tethysapp/test_app/templates' in r:
                test_app = True
            if '/tethysext-test_extension/tethysext/test_extension/templates' in r:
                test_ext = True

        self.assertTrue(test_app)
        self.assertFalse(test_ext)
Beispiel #9
0
    def test_get_directories_in_tethys_templates_with_app_name(self):
        # Get the templates directories for the test_app and test_extension
        # Use the with_app_name argument, so that the app and extension names appear in the result
        result = utilities.get_directories_in_tethys(('templates',), with_app_name=True)
        self.assertGreaterEqual(len(result), 2)
        self.assertEqual(2, len(result[0]))
        self.assertEqual(2, len(result[1]))

        test_app = False
        test_ext = False

        for r in result:
            if 'test_app' in r and '/tethysapp/test_app/templates' in r[1]:
                test_app = True
            if 'test_extension' in r and '/tethysext-test_extension/tethysext/test_extension/templates' in r[1]:
                test_ext = True

        self.assertTrue(test_app)
        self.assertTrue(test_ext)
Beispiel #10
0
    def test_get_directories_in_tethys_templates_with_app_name(self):
        # Get the templates directories for the test_app and test_extension
        # Use the with_app_name argument, so that the app and extension names appear in the result
        result = utilities.get_directories_in_tethys(('templates',), with_app_name=True)
        self.assertGreaterEqual(len(result), 2)
        self.assertEqual(2, len(result[0]))
        self.assertEqual(2, len(result[1]))

        test_app = False
        test_ext = False

        for r in result:
            if 'test_app' in r and '/tethysapp/test_app/templates' in r[1]:
                test_app = True
            if 'test_extension' in r and '/tethysext-test_extension/tethysext/test_extension/templates' in r[1]:
                test_ext = True

        self.assertTrue(test_app)
        self.assertTrue(test_ext)
Beispiel #11
0
    def get_template_sources(self, template_name, template_dirs=None):
        """
        Return an Origin object pointing to an absolute path in each directory
        in template_dirs. For security reasons, if a path doesn't lie inside
        one of the template_dirs it is excluded from the result set.
        """
        if not template_dirs:
            template_dirs = get_directories_in_tethys(('templates', ))
        for template_dir in template_dirs:
            try:
                name = safe_join(template_dir, template_name)
            except SuspiciousFileOperation:
                # The joined path was located outside of this template_dir
                # (it might be inside another one, so this isn't fatal).
                continue

            yield Origin(
                name=name,
                template_name=template_name,
                loader=self,
            )
Beispiel #12
0
    def get_template_sources(self, template_name, template_dirs=None):
        """
        Return an Origin object pointing to an absolute path in each directory
        in template_dirs. For security reasons, if a path doesn't lie inside
        one of the template_dirs it is excluded from the result set.
        """
        if not template_dirs:
            template_dirs = get_directories_in_tethys(('templates',))
        for template_dir in template_dirs:
            try:
                name = safe_join(template_dir, template_name)
            except SuspiciousFileOperation:
                # The joined path was located outside of this template_dir
                # (it might be inside another one, so this isn't fatal).
                continue

            yield Origin(
                name=name,
                template_name=template_name,
                loader=self,
            )
Beispiel #13
0
 def test_get_directories_in_tethys_foo(self):
     # Get the foo directories for the test_app and test_extension
     # foo doesn't exist
     result = utilities.get_directories_in_tethys(('foo',))
     self.assertEqual(0, len(result))
Beispiel #14
0
 def test_get_directories_in_tethys_foo(self):
     # Get the foo directories for the test_app and test_extension
     # foo doesn't exist
     result = utilities.get_directories_in_tethys(('foo',))
     self.assertEqual(0, len(result))