Esempio n. 1
0
 def test_source_paths(self):
     """Static document source paths."""
     static_doc = static_document.StaticDocument(self.pod,
                                                 '/static-a/test-a.txt')
     self.assertEquals('/static-a/', static_doc.source_path)
     static_doc = static_document.StaticDocument(self.pod,
                                                 '/static-b/test-b.txt')
     self.assertEquals('/static-b/', static_doc.source_path)
Esempio n. 2
0
    def test_source_path(self):
        """Static document source path."""
        static_doc = static_document.StaticDocument(
            self.pod, '/static/test.txt')
        self.assertEquals('/static/', static_doc.source_path)

        static_doc = static_document.StaticDocument(
            self.pod, '/static/something.txt', locale='de')
        self.assertEquals('/static/intl/{locale}/', static_doc.source_path)
Esempio n. 3
0
    def test_exists(self):
        """Static document exists?"""
        static_doc = static_document.StaticDocument(
            self.pod, '/static/test.txt')
        self.assertTrue(static_doc.exists)

        static_doc = static_document.StaticDocument(
            self.pod, '/static/something.txt')
        self.assertFalse(static_doc.exists)
Esempio n. 4
0
    def test_source_pod_path(self):
        """Static document source path."""
        static_doc = static_document.StaticDocument(self.pod,
                                                    '/static/test.txt')
        self.assertEqual('/static/test.txt', static_doc.source_pod_path)

        static_doc = static_document.StaticDocument(self.pod,
                                                    '/static/test.txt',
                                                    locale='de')
        self.assertEqual('/static/intl/de/test.txt',
                         static_doc.source_pod_path)
Esempio n. 5
0
    def test_serving_path_parameterized(self):
        """Static document parameterized serving path."""
        static_doc = static_document.StaticDocument(
            self.pod, '/static/test.txt')
        self.assertEquals(
            '/app/static/test.txt', static_doc.serving_path_parameterized)

        static_doc = static_document.StaticDocument(
            self.pod, '/static/something.txt', locale='de')
        self.assertEquals(
            '/app/root/static/somepath/:locale/something.txt',
            static_doc.serving_path_parameterized)
Esempio n. 6
0
    def test_serving_path(self):
        """Static document serving path."""
        static_doc = static_document.StaticDocument(
            self.pod, '/static/test.txt')
        self.assertEquals(
            '/app/static/test-db3f6eaa28bac5ae1180257da33115d8.txt', static_doc.serving_path)

        static_doc = static_document.StaticDocument(
            self.pod, '/static/test.txt', locale='de')
        self.assertEquals(
            '/app/root/static/somepath/de/test-db3f6eaa28bac5ae1180257da33115d8.txt',
            static_doc.serving_path)
Esempio n. 7
0
    def test_path_format(self):
        """Static document path format."""
        static_doc = static_document.StaticDocument(
            self.pod, '/static/test.txt')
        self.assertEquals('/app/static/test.txt', static_doc.path_format)

        static_doc = static_document.StaticDocument(
            self.pod, '/static/something.txt')
        self.assertEquals('/app/static/something.txt', static_doc.path_format)

        static_doc = static_document.StaticDocument(
            self.pod, '/static/something.txt', locale='de')
        self.assertEquals(
            '/app/{root}/static/somepath/{locale}/something.txt', static_doc.path_format)
Esempio n. 8
0
    def test_serving_path(self):
        """Static document serving path."""
        static_doc = static_document.StaticDocument(self.pod,
                                                    '/static/test.txt')
        self.assertEqual(
            ('/app/static/test-180e03ea719ad14b0e02701048db567e231eb6fd'
             '0a23b6359f068b1e8bef135b.txt'), static_doc.serving_path)

        static_doc = static_document.StaticDocument(self.pod,
                                                    '/static/test.txt',
                                                    locale='de')
        self.assertEqual(
            ('/app/root/static/somepath/de/test-180e03ea719ad14b0e02701'
             '048db567e231eb6fd0a23b6359f068b1e8bef135b.txt'),
            static_doc.serving_path)
Esempio n. 9
0
 def get_static(self, pod_path, locale=None):
     """Returns a StaticFile, given the static file's pod path."""
     if self.use_reroute:
         document = static_document.StaticDocument(self,
                                                   pod_path,
                                                   locale=locale)
         if document.exists:
             return document
     else:
         for route in self.routes.static_routing_map.iter_rules():
             controller = route.endpoint
             if controller.KIND == messages.Kind.STATIC:
                 serving_path = controller.match_pod_path(pod_path)
                 if serving_path:
                     return grow_static.StaticFile(
                         pod_path,
                         serving_path,
                         locale=locale,
                         pod=self,
                         controller=controller,
                         fingerprinted=controller.fingerprinted,
                         localization=controller.localization)
     text = (
         'Either no file exists at "{}" or the "static_dirs" setting was '
         'not configured for this path in {}.'.format(
             pod_path, self.FILE_PODSPEC))
     raise grow_static.BadStaticFileError(text)
Esempio n. 10
0
    def test_source_path_multi_paths(self):
        """Static document source path with multiple source dirs."""
        static_doc = static_document.StaticDocument(self.pod,
                                                    '/static-a/test-a.txt')
        self.assertEquals('/static-a/', static_doc.source_path)

        static_doc = static_document.StaticDocument(self.pod,
                                                    '/static-b/test-b.txt')
        self.assertEquals('/static-b/', static_doc.source_path)

        static_doc = static_document.StaticDocument(self.pod,
                                                    '/static-a/test-a.txt',
                                                    locale='de')
        self.assertEquals('/static-a/intl/{locale}/', static_doc.source_path)

        static_doc = static_document.StaticDocument(self.pod,
                                                    '/static-b/test-b.txt',
                                                    locale='de')
        self.assertEquals('/static-b/intl/{locale}/', static_doc.source_path)
Esempio n. 11
0
File: pods.py Progetto: uxder/grow
    def get_static(self, pod_path, locale=None):
        """Returns a StaticFile, given the static file's pod path."""
        document = static_document.StaticDocument(
            self, pod_path, locale=locale)
        if document.exists:
            return document

        text = ('Either no file exists at "{}" or the "static_dirs" setting was '
                'not configured for this path in {}.'.format(
                    pod_path, self.FILE_PODSPEC))
        raise errors.DocumentDoesNotExistError(text)
Esempio n. 12
0
 def test_path_filter(self):
     """Static path filter."""
     static_doc = static_document.StaticDocument(
         self.pod, '/static/test.txt')
     self.assertTrue(static_doc.path_filter.is_valid(static_doc.serving_path))
Esempio n. 13
0
 def test_filter(self):
     """Static filter config."""
     static_doc = static_document.StaticDocument(
         self.pod, '/static/test.txt')
     self.assertEquals(static_doc.filter, {})