Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.toolbox
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Gabriel Monnerat
slapos.toolbox
Commits
e9b3117f
Commit
e9b3117f
authored
Oct 07, 2016
by
Nicolas Wavrant
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
generatefeed: has been fixed to really delete older items
parent
62822166
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
3 deletions
+15
-3
slapos/generatefeed.py
slapos/generatefeed.py
+1
-1
slapos/test/test_generatefeed.py
slapos/test/test_generatefeed.py
+14
-2
No files found.
slapos/generatefeed.py
View file @
e9b3117f
...
@@ -71,7 +71,7 @@ def generateFeed(option):
...
@@ -71,7 +71,7 @@ def generateFeed(option):
# Reduces feed if number of items exceeds max_item
# Reduces feed if number of items exceeds max_item
if
len
(
item_dict
)
>
option
.
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
:
for
outdated_key
in
outdated_key_list
:
del
sorted_item_dict
[
outdated_key
]
del
sorted_item_dict
[
outdated_key
]
deleteFileList
(
outdated_key_list
)
deleteFileList
(
outdated_key_list
)
...
...
slapos/test/test_generatefeed.py
View file @
e9b3117f
...
@@ -87,7 +87,7 @@ class TestGenerateFeed(unittest.TestCase):
...
@@ -87,7 +87,7 @@ class TestGenerateFeed(unittest.TestCase):
def
test_generateFeedCleanStatusDirectoryIfTooManyItems
(
self
):
def
test_generateFeedCleanStatusDirectoryIfTooManyItems
(
self
):
option
=
self
.
getOptionObject
()
option
=
self
.
getOptionObject
()
option
.
max_item
=
10
option
.
max_item
=
3
# Creates items more than allowed
# Creates items more than allowed
item_dummy_content
=
{
item_dummy_content
=
{
...
@@ -96,9 +96,11 @@ class TestGenerateFeed(unittest.TestCase):
...
@@ -96,9 +96,11 @@ class TestGenerateFeed(unittest.TestCase):
'pubDate'
:
time
.
mktime
(
datetime
.
datetime
.
now
().
timetuple
()),
'pubDate'
:
time
.
mktime
(
datetime
.
datetime
.
now
().
timetuple
()),
'title'
:
'dummy title'
,
'title'
:
'dummy title'
,
}
}
for
i
in
range
(
1
5
):
for
i
in
range
(
5
):
filename
=
'%s.item'
%
i
filename
=
'%s.item'
%
i
self
.
saveAsStatusItem
(
filename
,
item_dummy_content
)
self
.
saveAsStatusItem
(
filename
,
item_dummy_content
)
time
.
sleep
(
1
)
item_dummy_content
[
'pubDate'
]
=
time
.
mktime
(
datetime
.
datetime
.
now
().
timetuple
())
content_feed
=
generateFeed
(
option
)
content_feed
=
generateFeed
(
option
)
feed
=
feedparser
.
parse
(
content_feed
)
feed
=
feedparser
.
parse
(
content_feed
)
...
@@ -111,5 +113,15 @@ class TestGenerateFeed(unittest.TestCase):
...
@@ -111,5 +113,15 @@ class TestGenerateFeed(unittest.TestCase):
# Status item directory should have been cleaned
# Status item directory should have been cleaned
self
.
assertEqual
(
len
(
os
.
listdir
(
self
.
item_directory
)),
option
.
max_item
)
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__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment