String formatting for status view tests

This commit is contained in:
Mouse Reeve 2021-09-22 10:51:44 -07:00
parent b1ff46a562
commit b7c2fb600a

View file

@ -101,7 +101,7 @@ class StatusViews(TestCase):
"""@mention a user in a post""" """@mention a user in a post"""
view = views.CreateStatus.as_view() view = views.CreateStatus.as_view()
user = models.User.objects.create_user( user = models.User.objects.create_user(
"rat@%s" % DOMAIN, f"rat@{DOMAIN}",
"rat@rat.com", "rat@rat.com",
"password", "password",
local=True, local=True,
@ -124,7 +124,7 @@ class StatusViews(TestCase):
self.assertEqual(list(status.mention_users.all()), [user]) self.assertEqual(list(status.mention_users.all()), [user])
self.assertEqual(models.Notification.objects.get().user, user) self.assertEqual(models.Notification.objects.get().user, user)
self.assertEqual( self.assertEqual(
status.content, '<p>hi <a href="%s">@rat</a></p>' % user.remote_id status.content, f'<p>hi <a href="{user.remote_id}">@rat</a></p>'
) )
def test_handle_status_reply_with_mentions(self, *_): def test_handle_status_reply_with_mentions(self, *_):
@ -224,13 +224,13 @@ class StatusViews(TestCase):
def test_find_mentions(self, *_): def test_find_mentions(self, *_):
"""detect and look up @ mentions of users""" """detect and look up @ mentions of users"""
user = models.User.objects.create_user( user = models.User.objects.create_user(
"nutria@%s" % DOMAIN, f"nutria@{DOMAIN}",
"nutria@nutria.com", "nutria@nutria.com",
"password", "password",
local=True, local=True,
localname="nutria", localname="nutria",
) )
self.assertEqual(user.username, "nutria@%s" % DOMAIN) self.assertEqual(user.username, f"nutria@{DOMAIN}")
self.assertEqual( self.assertEqual(
list(views.status.find_mentions("@nutria"))[0], ("@nutria", user) list(views.status.find_mentions("@nutria"))[0], ("@nutria", user)
@ -263,19 +263,19 @@ class StatusViews(TestCase):
self.assertEqual(list(views.status.find_mentions("@beep@beep.com")), []) self.assertEqual(list(views.status.find_mentions("@beep@beep.com")), [])
self.assertEqual( self.assertEqual(
list(views.status.find_mentions("@nutria@%s" % DOMAIN))[0], list(views.status.find_mentions(f"@nutria@{DOMAIN}"))[0],
("@nutria@%s" % DOMAIN, user), (f"@nutria@{DOMAIN}", user),
) )
def test_format_links_simple_url(self, *_): def test_format_links_simple_url(self, *_):
"""find and format urls into a tags""" """find and format urls into a tags"""
url = "http://www.fish.com/" url = "http://www.fish.com/"
self.assertEqual( self.assertEqual(
views.status.format_links(url), '<a href="%s">www.fish.com/</a>' % url views.status.format_links(url), f'<a href="{url}">www.fish.com/</a>'
) )
self.assertEqual( self.assertEqual(
views.status.format_links("(%s)" % url), views.status.format_links(f"({url})"),
'(<a href="%s">www.fish.com/</a>)' % url, f'(<a href="{url}">www.fish.com/</a>)',
) )
def test_format_links_paragraph_break(self, *_): def test_format_links_paragraph_break(self, *_):
@ -292,8 +292,8 @@ http://www.fish.com/"""
"""find and format urls into a tags""" """find and format urls into a tags"""
url = "http://www.fish.com/" url = "http://www.fish.com/"
self.assertEqual( self.assertEqual(
views.status.format_links("(%s)" % url), views.status.format_links(f"({url})"),
'(<a href="%s">www.fish.com/</a>)' % url, f'(<a href="{url}">www.fish.com/</a>)',
) )
def test_format_links_special_chars(self, *_): def test_format_links_special_chars(self, *_):
@ -301,27 +301,27 @@ http://www.fish.com/"""
url = "https://archive.org/details/dli.granth.72113/page/n25/mode/2up" url = "https://archive.org/details/dli.granth.72113/page/n25/mode/2up"
self.assertEqual( self.assertEqual(
views.status.format_links(url), views.status.format_links(url),
'<a href="%s">' f'<a href="{url}">'
"archive.org/details/dli.granth.72113/page/n25/mode/2up</a>" % url, "archive.org/details/dli.granth.72113/page/n25/mode/2up</a>",
) )
url = "https://openlibrary.org/search?q=arkady+strugatsky&mode=everything" url = "https://openlibrary.org/search?q=arkady+strugatsky&mode=everything"
self.assertEqual( self.assertEqual(
views.status.format_links(url), views.status.format_links(url),
'<a href="%s">openlibrary.org/search' f'<a href="{url}">openlibrary.org/search'
"?q=arkady+strugatsky&mode=everything</a>" % url, "?q=arkady+strugatsky&mode=everything</a>",
) )
url = "https://tech.lgbt/@bookwyrm" url = "https://tech.lgbt/@bookwyrm"
self.assertEqual( self.assertEqual(
views.status.format_links(url), '<a href="%s">tech.lgbt/@bookwyrm</a>' % url views.status.format_links(url), f'<a href="{url}">tech.lgbt/@bookwyrm</a>'
) )
url = "https://users.speakeasy.net/~lion/nb/book.pdf" url = "https://users.speakeasy.net/~lion/nb/book.pdf"
self.assertEqual( self.assertEqual(
views.status.format_links(url), views.status.format_links(url),
'<a href="%s">users.speakeasy.net/~lion/nb/book.pdf</a>' % url, f'<a href="{url}">users.speakeasy.net/~lion/nb/book.pdf</a>',
) )
url = "https://pkm.one/#/page/The%20Book%20which%20launched%20a%201000%20Note%20taking%20apps" url = "https://pkm.one/#/page/The%20Book%20launched%20a%201000%20Note%20apps"
self.assertEqual( self.assertEqual(
views.status.format_links(url), '<a href="%s">%s</a>' % (url, url[8:]) views.status.format_links(url), f'<a href="{url}">{url[8:]}</a>'
) )
def test_to_markdown(self, *_): def test_to_markdown(self, *_):