def test_multiple_rules(self): publisher = lektor_s3.S3Publisher("", "") filename = r"font.woff2" have = publisher.create_headers(filename) want = { 'CacheControl': 'public,max-age=31536000', 'ContentType': 'application/font-woff2', } self.assertEqual(have, want)
def test_extensions(self): publisher = lektor_s3.S3Publisher("", "") filename = r"image.png" have = publisher.create_headers(filename) want = { 'CacheControl': 'public,max-age=259200', 'ContentType': 'image/png', } self.assertEqual(have, want)
def test_match(self): publisher = lektor_s3.S3Publisher("", "") filename = r"styles.css" have = publisher.create_headers(filename) want = { 'CacheControl': 'public,max-age=31536000', 'ContentType': 'text/css', } self.assertEqual(have, want)
def test_default(self): publisher = lektor_s3.S3Publisher("", "") filename = r"index.html" have = publisher.create_headers(filename) want = { 'CacheControl': 'public,max-age=3600', 'ContentType': 'text/html', } self.assertEqual(have, want)
def test_load_config_file(self): with TemporaryDirectory() as tempdir: os.mkdir(os.path.join(tempdir, "configs")) config = inifile.IniFile(os.path.join(tempdir, "configs", "s3.ini")) config["section.key"] = "value" config.save() publisher = lektor_s3.S3Publisher(MockEnvironment(tempdir), "") have = publisher.get_config().section_as_dict("section") self.assertEqual(have["key"], "value")
def test_compute_diff(self): publisher = lektor_s3.S3Publisher("", "") publisher.key_prefix = "/keyprefix/" local = [ "dir/present_on_both.txt", "dir/missing_remotely.txt", "dir/subdir/file.txt", "toplevel.txt", ] remote = { MockS3Object("/keyprefix/dir/present_on_both.txt"), MockS3Object("/keyprefix/dir/missing_locally.txt"), MockS3Object("/keyprefix/toplevel.txt"), MockS3Object("/keyprefix/dir/subdir/file.txt"), } have = publisher.compute_diff(local, remote) want = { 'add': ['dir/missing_remotely.txt'], 'update': [], 'delete': ['/keyprefix/dir/missing_locally.txt'], } self.assertEqual(have, want)
def test_no_config_file(self): publisher = lektor_s3.S3Publisher(MockEnvironment(""), "") self.assertEqual(len(publisher.get_config().sections()), 0)