コード例 #1
0
ファイル: test__init__.py プロジェクト: fxtmtrsine/betty
    def test_post_render_config_without_clean_urls(self):
        self.maxDiff = None

        with TemporaryDirectory() as output_directory_path:
            configuration = Configuration(output_directory_path,
                                          'https://example.com')
            configuration.plugins[Nginx] = {}
            site = Site(configuration)
            render(site)
            expected = '''server {
	# The port to listen to.
	listen 80;
	# The publicly visible hostname.
	server_name example.com;
	# The path to the local web root.
	root %s;
	# The cache lifetime.
	add_header Cache-Control "max-age=86400";

	# Handle HTTP error responses.
	error_page 401 /.error/401.html;
	error_page 403 /.error/403.html;
	error_page 404 /.error/404.html;
	location /.error {
		internal;
	}

	# When directories are requested, serve their index.html contents.
	location / {
		if ($request_method = OPTIONS) {
			add_header Allow "OPTIONS, GET";
			return 200;
		}
		index index.html;
		try_files $uri $uri/ =404;
	}
}''' % configuration.www_directory_path  # noqa: E101 W191
            with open(join(configuration.output_directory_path,
                           'nginx.conf')) as f:  # noqa: E101
                self.assertEquals(expected, f.read())
コード例 #2
0
    def test_post_render_config_with_https(self):
        with TemporaryDirectory() as output_directory_path:
            configuration = Configuration(
                output_directory_path, 'https://example.com')
            configuration.plugins[Nginx] = {}
            site = Site(configuration)
            render(site)
            expected = '''    server {
        listen 80;
        server_name example.com;
        return 301 https://$host$request_uri;
    }
server {
	listen 443 ssl http2;
	server_name example.com;
	root %s;
        add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
	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 $content_type_extension html;
    index index.$content_type_extension;

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

            try_files $uri $uri/ =404;
        }
}''' % 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())
コード例 #3
0
ファイル: test_jinja2.py プロジェクト: gholamiayub/betty
 def test(self):
     with TemporaryDirectory() as www_directory_path:
         configuration = Configuration(www_directory_path,
                                       'https://example.com')
         environment = create_environment(Site(configuration))
         template = '{{ data | sort_localizeds(localized_attribute="names", sort_attribute="name") }}'
         data = [
             self.WithLocalizedNames('third', [
                 LocalizedName('3', 'nl-NL'),
             ]),
             self.WithLocalizedNames('second', [
                 LocalizedName('2', 'en'),
                 LocalizedName('1', 'nl-NL'),
             ]),
             self.WithLocalizedNames('first', [
                 LocalizedName('2', 'nl-NL'),
                 LocalizedName('1', 'en-US'),
             ]),
         ]
         self.assertEquals(
             '[first, second, third]',
             environment.from_string(template).render(data=data))
コード例 #4
0
ファイル: test_site.py プロジェクト: fxtmtrsine/betty
 def test_configuration_should_return(self):
     configuration = Configuration(**self._MINIMAL_CONFIGURATION_ARGS)
     sut = Site(configuration)
     self.assertEquals(configuration, sut.configuration)
コード例 #5
0
ファイル: test_site.py プロジェクト: fxtmtrsine/betty
 def test_ancestry_should_return(self):
     configuration = Configuration(**self._MINIMAL_CONFIGURATION_ARGS)
     sut = Site(configuration)
     self.assertIsInstance(sut.ancestry, Ancestry)
コード例 #6
0
ファイル: test_site.py プロジェクト: fxtmtrsine/betty
 def test_resources_without_resources_directory_path(self):
     configuration = Configuration(**self._MINIMAL_CONFIGURATION_ARGS)
     sut = Site(configuration)
     self.assertEquals(1, len(sut.resources.paths))
コード例 #7
0
ファイル: test_site.py プロジェクト: fxtmtrsine/betty
 def test_with_multiple_plugins_with_cyclic_dependencies(self):
     configuration = Configuration(**self._MINIMAL_CONFIGURATION_ARGS)
     configuration.plugins[CyclicDependencyOnePlugin] = {}
     with self.assertRaises(CyclicGraphError):
         Site(configuration)
コード例 #8
0
ファイル: test_render.py プロジェクト: fxtmtrsine/betty
 def setUp(self):
     RenderTestCase.setUp(self)
     configuration = Configuration(self._outputDirectory.name,
                                   'https://ancestry.example.com')
     self.site = Site(configuration)
コード例 #9
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))
コード例 #10
0
ファイル: test_jinja2.py プロジェクト: gholamiayub/betty
 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())
コード例 #11
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())