forked from github/pelican
Set "modified:" from "date:" when the latter was set from the filesystem (#2748)
Sets the `modified:` metadata from `date:` if the user asked us to use the filesystem for determining timestamps. Fixes #2497 * Added tests (ab)using the HTML reader a bit There seems to be no way to test this generically since we need to produce a valid document with meta information to be able to compare, hence I used the lightest reader out there to do the parsing of the samples. * Fixed tests for generators since there were 4 more articles introduced to the test content directory.
This commit is contained in:
parent
c8639fe547
commit
e6df353302
7 changed files with 113 additions and 0 deletions
|
|
@ -81,6 +81,50 @@ class DefaultReaderTest(ReaderTest):
|
|||
with self.assertRaises(TypeError):
|
||||
self.read_file(path='article_with_metadata.unknownextension')
|
||||
|
||||
def test_readfile_path_metadata_implicit_dates(self):
|
||||
test_file = 'article_with_metadata_implicit_dates.html'
|
||||
page = self.read_file(path=test_file, DEFAULT_DATE='fs')
|
||||
expected = {
|
||||
'date': SafeDatetime.fromtimestamp(
|
||||
os.stat(_path(test_file)).st_mtime),
|
||||
'modified': SafeDatetime.fromtimestamp(
|
||||
os.stat(_path(test_file)).st_mtime)
|
||||
}
|
||||
|
||||
self.assertDictHasSubset(page.metadata, expected)
|
||||
|
||||
def test_readfile_path_metadata_explicit_dates(self):
|
||||
test_file = 'article_with_metadata_explicit_dates.html'
|
||||
page = self.read_file(path=test_file, DEFAULT_DATE='fs')
|
||||
expected = {
|
||||
'date': SafeDatetime(2010, 12, 2, 10, 14),
|
||||
'modified': SafeDatetime(2010, 12, 31, 23, 59)
|
||||
}
|
||||
|
||||
self.assertDictHasSubset(page.metadata, expected)
|
||||
|
||||
def test_readfile_path_metadata_implicit_date_explicit_modified(self):
|
||||
test_file = 'article_with_metadata_implicit_date_explicit_modified.html'
|
||||
page = self.read_file(path=test_file, DEFAULT_DATE='fs')
|
||||
expected = {
|
||||
'date': SafeDatetime.fromtimestamp(
|
||||
os.stat(_path(test_file)).st_mtime),
|
||||
'modified': SafeDatetime(2010, 12, 2, 10, 14),
|
||||
}
|
||||
|
||||
self.assertDictHasSubset(page.metadata, expected)
|
||||
|
||||
def test_readfile_path_metadata_explicit_date_implicit_modified(self):
|
||||
test_file = 'article_with_metadata_explicit_date_implicit_modified.html'
|
||||
page = self.read_file(path=test_file, DEFAULT_DATE='fs')
|
||||
expected = {
|
||||
'date': SafeDatetime(2010, 12, 2, 10, 14),
|
||||
'modified': SafeDatetime.fromtimestamp(
|
||||
os.stat(_path(test_file)).st_mtime)
|
||||
}
|
||||
|
||||
self.assertDictHasSubset(page.metadata, expected)
|
||||
|
||||
@unittest.skipUnless(patch, 'Needs Mock module')
|
||||
def test_find_empty_alt(self):
|
||||
with patch('pelican.readers.logger') as log_mock:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue