API - Make sure the watch "is viewed" attribute is correctly represented in the API output (#2009)

pull/2011/head
dgtlmoon 1 year ago committed by GitHub
parent d8ee5472f1
commit bbc18d8e80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -76,7 +76,7 @@ class Watch(Resource):
# Properties are not returned as a JSON, so add the required props manually # Properties are not returned as a JSON, so add the required props manually
watch['history_n'] = watch.history_n watch['history_n'] = watch.history_n
watch['last_changed'] = watch.last_changed watch['last_changed'] = watch.last_changed
watch['viewed'] = watch.viewed
return watch return watch
@auth.check_token @auth.check_token
@ -280,11 +280,14 @@ class CreateWatch(Resource):
if tag_limit and not any(v.get('title').lower() == tag_limit for k, v in tags.items()): if tag_limit and not any(v.get('title').lower() == tag_limit for k, v in tags.items()):
continue continue
list[uuid] = {'url': watch['url'], list[uuid] = {
'title': watch['title'], 'last_changed': watch.last_changed,
'last_checked': watch['last_checked'], 'last_checked': watch['last_checked'],
'last_changed': watch.last_changed, 'last_error': watch['last_error'],
'last_error': watch['last_error']} 'title': watch['title'],
'url': watch['url'],
'viewed': watch.viewed
}
if request.args.get('recheck_all'): if request.args.get('recheck_all'):
for uuid in self.datastore.data['watching'].keys(): for uuid in self.datastore.data['watching'].keys():

@ -113,7 +113,8 @@ class model(dict):
@property @property
def viewed(self): def viewed(self):
if int(self['last_viewed']) >= int(self.newest_history_key) : # Don't return viewed when last_viewed is 0 and newest_key is 0
if int(self['last_viewed']) and int(self['last_viewed']) >= int(self.newest_history_key) :
return True return True
return False return False

@ -96,7 +96,9 @@ def test_api_simple(client, live_server):
) )
assert watch_uuid in res.json.keys() assert watch_uuid in res.json.keys()
before_recheck_info = res.json[watch_uuid] before_recheck_info = res.json[watch_uuid]
assert before_recheck_info['last_checked'] != 0 assert before_recheck_info['last_checked'] != 0
#705 `last_changed` should be zero on the first check #705 `last_changed` should be zero on the first check
assert before_recheck_info['last_changed'] == 0 assert before_recheck_info['last_changed'] == 0
assert before_recheck_info['title'] == 'My test URL' assert before_recheck_info['title'] == 'My test URL'
@ -157,6 +159,18 @@ def test_api_simple(client, live_server):
# @todo how to handle None/default global values? # @todo how to handle None/default global values?
assert watch['history_n'] == 2, "Found replacement history section, which is in its own API" assert watch['history_n'] == 2, "Found replacement history section, which is in its own API"
assert watch.get('viewed') == False
# Loading the most recent snapshot should force viewed to become true
client.get(url_for("diff_history_page", uuid="first"), follow_redirects=True)
# Fetch the whole watch again, viewed should be true
res = client.get(
url_for("watch", uuid=watch_uuid),
headers={'x-api-key': api_key}
)
watch = res.json
assert watch.get('viewed') == True
# basic systeminfo check # basic systeminfo check
res = client.get( res = client.get(
url_for("systeminfo"), url_for("systeminfo"),

Loading…
Cancel
Save