Beispiel #1
0
    async def test_post_render_config_with_clean_urls(self):
        with TemporaryDirectory() as output_directory_path:
            configuration = Configuration(output_directory_path,
                                          'http://example.com')
            configuration.plugins[Nginx] = {}
            configuration.clean_urls = True
            expected = r'''
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 $media_type_extension html;
    index index.$media_type_extension;

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

        try_files $uri $uri/ =404;
    }
}
''' % configuration.www_directory_path
            await self._assert_configuration_equals(expected, configuration)
Beispiel #2
0
    def test_post_render_config_with_clean_urls(self):
        with TemporaryDirectory() as output_directory_path:
            configuration = Configuration(
                output_directory_path, 'http://example.com')
            configuration.plugins[Nginx] = {}
            configuration.clean_urls = True
            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 $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())
Beispiel #3
0
    def test_post_render_config_with_clean_urls(self):
        self.maxDiff = None

        with TemporaryDirectory() as output_directory_path:
            configuration = Configuration(output_directory_path,
                                          'https://example.com')
            configuration.plugins[Nginx] = {}
            configuration.clean_urls = True
            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;
	}

	# Redirect */index.html to their parent directories for clean URLs.
	if ($request_uri ~ "^(.*)/index\.html$") {
		return 301 $1;
	}

	# 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())
Beispiel #4
0
 def test_clean_urls(self):
     sut = Configuration('~', 'https://example.com')
     clean_urls = True
     sut.clean_urls = clean_urls
     self.assertEquals(clean_urls, sut.clean_urls)
Beispiel #5
0
 def test_generate_with_clean_urls(self, expected: str, resource: str):
     configuration = Configuration('/tmp', 'https://example.com')
     configuration.clean_urls = True
     sut = LocalizedPathUrlGenerator(configuration)
     self.assertEquals(expected, sut.generate(resource, 'text/html'))