server/info: add serverTime field

This commit is contained in:
rr- 2016-06-12 14:26:52 +02:00
parent 40565e82ae
commit 162904bfc3
3 changed files with 12 additions and 5 deletions

6
API.md
View file

@ -1373,14 +1373,16 @@ data.
"diskUsage": <disk-usage>, // in bytes
"featuredPost": <featured-post>,
"featuringTime": <time>,
"featuringUser": <user>
"featuringUser": <user>,
"serverTime": <server-time>
}
```
- **Description**
Retrieves simple statistics. `<featured-post>` is null if there is no
featured post yet.
featured post yet. `<server-time>` is pretty much the same as the `Date`
HTTP field, only formatted in a manner consistent with other dates.

View file

@ -20,6 +20,7 @@ class InfoApi(BaseApi):
'featuringTime': post_feature.time if post_feature else None,
'featuringUser': users.serialize_user(post_feature.user, ctx.user) \
if post_feature else None,
'serverTime': datetime.datetime.now(),
}
def _get_disk_usage(self):

View file

@ -1,3 +1,4 @@
from datetime import datetime
from szurubooru import api, db
def test_info_api(
@ -7,28 +8,31 @@ def test_info_api(
config_injector({'data_dir': str(directory)})
db.session.add_all([post_factory(), post_factory()])
info_api = api.InfoApi()
with fake_datetime('13:00'):
with fake_datetime('2016-01-01 13:00'):
assert info_api.get(context_factory()) == {
'postCount': 2,
'diskUsage': 3,
'featuredPost': None,
'featuringTime': None,
'featuringUser': None,
'serverTime': datetime(2016, 1, 1, 13, 0),
}
directory.join('test2.txt').write('abc')
with fake_datetime('13:59'):
with fake_datetime('2016-01-01 13:59'):
assert info_api.get(context_factory()) == {
'postCount': 2,
'diskUsage': 3, # still 3 - it's cached
'featuredPost': None,
'featuringTime': None,
'featuringUser': None,
'serverTime': datetime(2016, 1, 1, 13, 59),
}
with fake_datetime('14:01'):
with fake_datetime('2016-01-01 14:01'):
assert info_api.get(context_factory()) == {
'postCount': 2,
'diskUsage': 6, # cache expired
'featuredPost': None,
'featuringTime': None,
'featuringUser': None,
'serverTime': datetime(2016, 1, 1, 14, 1),
}