Updates user model test

This commit is contained in:
Mouse Reeve 2021-08-28 11:58:41 -07:00
parent e4b5890992
commit 1e675384bc

View file

@ -5,11 +5,12 @@ from django.test import TestCase
import responses import responses
from bookwyrm import models from bookwyrm import models
from bookwyrm.settings import DOMAIN from bookwyrm.settings import USE_HTTPS, DOMAIN
# pylint: disable=missing-class-docstring # pylint: disable=missing-class-docstring
# pylint: disable=missing-function-docstring # pylint: disable=missing-function-docstring
class User(TestCase): class User(TestCase):
protocol = "https://" if USE_HTTPS else "http://"
def setUp(self): def setUp(self):
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
self.user = models.User.objects.create_user( self.user = models.User.objects.create_user(
@ -24,13 +25,13 @@ class User(TestCase):
def test_computed_fields(self): def test_computed_fields(self):
"""username instead of id here""" """username instead of id here"""
expected_id = "https://%s/user/mouse" % DOMAIN expected_id = f"{self.protocol}{DOMAIN}/user/mouse"
self.assertEqual(self.user.remote_id, expected_id) self.assertEqual(self.user.remote_id, expected_id)
self.assertEqual(self.user.username, "mouse@%s" % DOMAIN) self.assertEqual(self.user.username, f"mouse@{DOMAIN}")
self.assertEqual(self.user.localname, "mouse") self.assertEqual(self.user.localname, "mouse")
self.assertEqual(self.user.shared_inbox, "https://%s/inbox" % DOMAIN) self.assertEqual(self.user.shared_inbox, f"{self.protocol}{DOMAIN}/inbox")
self.assertEqual(self.user.inbox, "%s/inbox" % expected_id) self.assertEqual(self.user.inbox, f"{expected_id}/inbox")
self.assertEqual(self.user.outbox, "%s/outbox" % expected_id) self.assertEqual(self.user.outbox, f"{expected_id}/outbox")
self.assertIsNotNone(self.user.key_pair.private_key) self.assertIsNotNone(self.user.key_pair.private_key)
self.assertIsNotNone(self.user.key_pair.public_key) self.assertIsNotNone(self.user.key_pair.public_key)