From 51fd119c02ea3e7cc80729f2ee756c91ed23642d Mon Sep 17 00:00:00 2001 From: Ryan Barrett Date: Fri, 26 May 2023 16:36:45 -0700 Subject: [PATCH] fix bug in models.reset_protocol_properties added in eaa4e5333a5421d15bac06da854036af1114adb8 --- models.py | 6 ++++-- pages.py | 7 ++++++- tests/test_pages.py | 4 ++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/models.py b/models.py index 24cf21b..70eccf4 100644 --- a/models.py +++ b/models.py @@ -59,8 +59,10 @@ class ProtocolUserMeta(type(ndb.Model)): def reset_protocol_properties(): """Recreates various protocol properties to include choices PROTOCOLS.""" - Target.protocol = ndb.StringProperty(choices=list(PROTOCOLS.keys()), required=True) - Object.source_protocol = ndb.StringProperty(choices=list(PROTOCOLS.keys())) + Target.protocol = ndb.StringProperty( + 'protocol', choices=list(PROTOCOLS.keys()), required=True) + Object.source_protocol = ndb.StringProperty( + 'source_protocol', choices=list(PROTOCOLS.keys())) def base64_to_long(x): diff --git a/pages.py b/pages.py index b122128..550f2c5 100644 --- a/pages.py +++ b/pages.py @@ -286,6 +286,11 @@ def nodeinfo(): """ https://nodeinfo.diaspora.software/schema.html """ + user_total = None + stat = KindStat.query(KindStat.kind_name == 'MagicKey').get() + if stat: + user_total = stat.count + return { 'version': '2.1', 'software': { @@ -305,7 +310,7 @@ def nodeinfo(): }, 'usage': { 'users': { - 'total': KindStat.query(KindStat.kind_name == 'MagicKey').get().count, + 'total': user_total, # 'activeMonth': # 'activeHalfyear': }, diff --git a/tests/test_pages.py b/tests/test_pages.py index f7cbb22..a87273d 100644 --- a/tests/test_pages.py +++ b/tests/test_pages.py @@ -226,3 +226,7 @@ class PagesTest(TestCase): got = self.client.get('/user/user.com/feed?format=rss') self.assert_equals(200, got.status_code) self.assert_equals(self.EXPECTED, contents(rss.to_activities(got.text))) + + def test_nodeinfo(self): + # just check that it doesn't crash + self.client.get('/nodeinfo.json')