Add test sources for the tt* fields

This commit is contained in:
Tim Van Baak 2020-06-02 13:53:12 -07:00
parent 49fa1cf8df
commit 098f97f4d9
8 changed files with 90 additions and 17 deletions

View File

@ -145,6 +145,7 @@ def populate_new(source_name, item):
if 'id' not in item:
raise Exception(f'Source "{source_name}" returned an item with no id')
# source is auto-populated with the source name if missing
# Note: this allows sources to create items in other cells!
if 'source' not in item: item['source'] = source_name
# active is forced to True for new items
item['active'] = True

14
sources/dummy.py Normal file
View File

@ -0,0 +1,14 @@
"""
Generates a dummy item.
"""
# Standard library imports
from datetime import datetime
import random
def fetch_new(state):
item = {
'source': "dummy",
'id': '{:x}'.format(random.getrandbits(16 * 4)),
'title': str(datetime.now()),
}
return [item]

View File

@ -1,17 +0,0 @@
"""
An example itemsource that produces an item with the current date.
Fetch new items with `python inquisitor update --sources example`
"""
# Standard library imports
from datetime import date
import time
def fetch_new(state):
now = date.today()
item = {
'source': "example",
'id': '{}-{}-{}'.format(now.year, now.month, now.day),
'title': "Today is {}-{}-{}".format(now.year, now.month, now.day),
}
return [item]

17
sources/ttddemogen.py Normal file
View File

@ -0,0 +1,17 @@
"""
Demonstrates the behavior of the time-to-die item field.
On update, this source creates a new item with a ttd of 30 in the cell
for the source ttddemoupd.
"""
# Standard library imports
from datetime import datetime
import random
def fetch_new(state):
item = {
'source': "ttddemoupd",
'id': '{:x}'.format(random.getrandbits(16 * 4)),
'title': f"This item was created at {datetime.now()}",
'ttd': 30,
}
return [item]

12
sources/ttddemoupd.py Normal file
View File

@ -0,0 +1,12 @@
"""
Demonstrates the behavior of the time-to-die item field.
This source does not generate items. It is solely for use with the
ttddemogen source, which creats new items for it. This source can be
updated to cause a ttd check on the item created by ttddemogen.
"""
# Standard library imports
from datetime import datetime
import random
def fetch_new(state):
return []

17
sources/ttldemogen.py Normal file
View File

@ -0,0 +1,17 @@
"""
Demonstrates the behavior of the time-to-live item field.
On update, this source creates a new item with a ttl of 30 in the cell
for the source ttldemoupd.
"""
# Standard library imports
from datetime import datetime
import random
def fetch_new(state):
item = {
'source': "ttldemoupd",
'id': '{:x}'.format(random.getrandbits(16 * 4)),
'title': f"This item was created at {datetime.now()}",
'ttl': 30,
}
return [item]

13
sources/ttldemoupd.py Normal file
View File

@ -0,0 +1,13 @@
"""
Demonstrates the behavior of the time-to-live item field.
This source does not generate items. It is solely for use with the
ttldemogen source, which creats new items for it. This source can be
updated to cause a removal check on inactive items created by
ttldemogen.
"""
# Standard library imports
from datetime import datetime
import random
def fetch_new(state):
return []

16
sources/ttsdemo.py Normal file
View File

@ -0,0 +1,16 @@
"""
Demonstrates the behavior of the time-to-show item field.
On update, this source returns a new item with a tts of 30 seconds.
"""
# Standard library imports
from datetime import datetime
import random
def fetch_new(state):
item = {
'source': "ttsdemo",
'id': '{:x}'.format(random.getrandbits(16 * 4)),
'title': f"This item was created at {datetime.now()}",
'tts': 30,
}
return [item]