Commit e9b3117f authored by Nicolas Wavrant's avatar Nicolas Wavrant

generatefeed: has been fixed to really delete older items

parent 62822166
Pipeline #2630 skipped
......@@ -71,7 +71,7 @@ def generateFeed(option):
# Reduces feed if number of items exceeds max_item
if len(item_dict) > option.max_item:
outdated_key_list = sorted_item_dict.keys()[option.max_item:]
outdated_key_list = sorted_item_dict.keys()[:-option.max_item]
for outdated_key in outdated_key_list:
del sorted_item_dict[outdated_key]
deleteFileList(outdated_key_list)
......
......@@ -87,7 +87,7 @@ class TestGenerateFeed(unittest.TestCase):
def test_generateFeedCleanStatusDirectoryIfTooManyItems(self):
option = self.getOptionObject()
option.max_item = 10
option.max_item = 3
# Creates items more than allowed
item_dummy_content = {
......@@ -96,9 +96,11 @@ class TestGenerateFeed(unittest.TestCase):
'pubDate': time.mktime(datetime.datetime.now().timetuple()),
'title': 'dummy title',
}
for i in range(15):
for i in range(5):
filename = '%s.item' % i
self.saveAsStatusItem(filename, item_dummy_content)
time.sleep(1)
item_dummy_content['pubDate'] = time.mktime(datetime.datetime.now().timetuple())
content_feed = generateFeed(option)
feed = feedparser.parse(content_feed)
......@@ -111,5 +113,15 @@ class TestGenerateFeed(unittest.TestCase):
# Status item directory should have been cleaned
self.assertEqual(len(os.listdir(self.item_directory)), option.max_item)
# Only "younger" items should still be there
remaining_status_item_list = os.listdir(self.item_directory)
expected_remaining_item_list = []
for i in range(5-3, 5): # older items (from 1 to 2) have been deleted
expected_remaining_item_list.append('%s.item' % i)
self.assertItemsEqual(remaining_status_item_list,
expected_remaining_item_list)
if __name__ == '__main__':
unittest.main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment