MCPcopy
hub / github.com/eudicots/Cactus / test_cache_control

Method test_cache_control

cactus/tests/test_deploy.py:63–108  ·  view source on GitHub ↗

Ensure that the Cache control headers are properly set

(self)

Source from the content-addressed store, hash-verified

61 shutil.rmtree(self.test_dir)
62
63 def test_cache_control(self):
64 """
65 Ensure that the Cache control headers are properly set
66 """
67 # Test a fingerprinted file
68 content = 'abc'
69 h = hashlib.md5(content.encode('utf-8')).hexdigest()
70 filename = "file.{0}.data".format(h)
71
72 with open(os.path.join(self.build_path, filename), "w") as f:
73 f.write(content)
74
75 p = TestHeadersPlugin()
76 self.site.plugin_manager.loaders = [ObjectsPluginLoader([p, CacheDurationPlugin()])]
77 self.site.plugin_manager.reload()
78 self.site.plugin_manager.preDeploy(self.site)
79
80 f = TestFile(self.engine, filename)
81 f.upload()
82
83 self.assertEqual(p.file.cache_control, f.MAX_CACHE_EXPIRATION)
84
85
86 # Test a non fingerprinted file
87 with open(os.path.join(self.build_path, "123.html"), "w") as f:
88 f.write("abc")
89
90 # Prepare setup
91 p = TestHeadersPlugin()
92 self.site.plugin_manager.loaders = [ObjectsPluginLoader([p, CacheDurationPlugin()])]
93 self.site.plugin_manager.reload()
94 f = TestFile(self.engine, "123.html")
95
96 # Test with no configured cache duration
97 self.site.config.set("cache-duration", None)
98 self.site.plugin_manager.preDeploy(self.site)
99
100 f.upload()
101 self.assertEqual(p.file.cache_control, f.DEFAULT_CACHE_EXPIRATION)
102
103 # Test with a configured cache duration
104 self.site.config.set("cache-duration", 123)
105 self.site.plugin_manager.preDeploy(self.site)
106
107 f.upload()
108 self.assertEqual(p.file.cache_control, 123)

Callers

nothing calls this directly

Calls 10

ObjectsPluginLoaderClass · 0.90
CacheDurationPluginClass · 0.90
TestHeadersPluginClass · 0.85
formatMethod · 0.80
reloadMethod · 0.80
preDeployMethod · 0.80
TestFileClass · 0.70
writeMethod · 0.45
uploadMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected