Esempio n. 1
0
 async def test_configuration_should_return(self):
     configuration = Configuration(**self._MINIMAL_CONFIGURATION_ARGS)
     async with Site(configuration) as sut:
         self.assertEquals(configuration, sut.configuration)
Esempio n. 2
0
 def test(self, expected, template):
     with TemporaryDirectory() as www_directory_path:
         environment = create_environment(
             Site(Configuration(www_directory_path, 'https://example.com')))
         self.assertEquals(expected,
                           environment.from_string(template).render())
Esempio n. 3
0
 async def test_ancestry_should_return(self):
     configuration = Configuration(**self._MINIMAL_CONFIGURATION_ARGS)
     async with Site(configuration) as sut:
         self.assertIsInstance(sut.ancestry, Ancestry)
Esempio n. 4
0
 async def test_resources_without_assets_directory_path(self):
     configuration = Configuration(**self._MINIMAL_CONFIGURATION_ARGS)
     async with Site(configuration) as sut:
         self.assertEquals(1, len(sut.assets.paths))
Esempio n. 5
0
 async def test_with_multiple_plugins_with_cyclic_dependencies(self):
     configuration = Configuration(**self._MINIMAL_CONFIGURATION_ARGS)
     configuration.plugins[CyclicDependencyOnePlugin] = None
     with self.assertRaises(CyclicGraphError):
         async with Site(configuration):
             pass
Esempio n. 6
0
 def setUp(self):
     GenerateTestCase.setUp(self)
     configuration = Configuration(self._outputDirectory.name,
                                   'https://ancestry.example.com')
     self.site = Site(configuration)
Esempio n. 7
0
    def test_post_render_config_multilingual_with_content_negotiation(self):
        with TemporaryDirectory() as output_directory_path:
            configuration = Configuration(
                output_directory_path, 'http://example.com')
            configuration.content_negotiation = True
            configuration.plugins[Nginx] = {}
            configuration.locales.clear()
            configuration.locales['en-US'] = LocaleConfiguration('en-US', 'en')
            configuration.locales['nl-NL'] = LocaleConfiguration('nl-NL', 'nl')
            site = Site(configuration)
            render(site)
            expected = '''server {
	listen 80;
	server_name example.com;
	root %s;
	add_header Cache-Control "max-age=86400";
    gzip on;
    gzip_disable "msie6";
    gzip_vary on;
    gzip_types text/css application/javascript application/json application/xml;

        set_by_lua_block $content_type_extension {
            local available_content_types = {'text/html', 'application/json'}
            local content_type_extensions = {}
            content_type_extensions['text/html'] = 'html'
            content_type_extensions['application/json'] = 'json'
            local content_type = require('cone').negotiate(ngx.req.get_headers()['Accept'], available_content_types)
            return content_type_extensions[content_type]
        }
    index index.$content_type_extension;

        location ~ ^/(en|nl)(/|$) {
            set $locale $1;

            add_header Content-Language "$locale" always;

            # Handle HTTP error responses.
            error_page 401 /$locale/.error/401.$content_type_extension;
            error_page 403 /$locale/.error/403.$content_type_extension;
            error_page 404 /$locale/.error/404.$content_type_extension;
            location ~ ^/$locale/\.error {
                internal;
            }

            try_files $uri $uri/ =404;
        }
        location @localized_redirect {
                set_by_lua_block $locale_alias {
                    local available_locales = {'en-US', 'nl-NL'}
                    local locale_aliases = {}
                        locale_aliases['en-US'] = 'en'
                        locale_aliases['nl-NL'] = 'nl'
                    local locale = require('cone').negotiate(ngx.req.get_headers()['Accept-Language'], available_locales)
                    return locale_aliases[locale]
                }
            return 301 /$locale_alias$uri;
        }
        location / {
            try_files $uri @localized_redirect;
        }
}''' % configuration.www_directory_path  # noqa: E101 W191
            with open(join(configuration.output_directory_path, 'nginx', 'nginx.conf')) as f:  # noqa: E101
                self.assertEquals(expected, f.read())