bookwyrm/bookwyrm/tests/models/test_link.py
Adeodato Simó 9d502f5ee2
Use setUpTestData() to speed up tests
Pylint's `bad-classmethod-argument` is disabled for each definition
to avoid rewriting the method bodies just to rename `self` → `cls`.
This can be done gradually, as the setUpTestData methods are modified
along the way.
2023-12-11 19:40:30 -03:00

31 lines
1.1 KiB
Python

""" testing models """
from unittest.mock import patch
from django.test import TestCase
from bookwyrm import models
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
class Link(TestCase):
"""some activitypub oddness ahead"""
def test_create_domain(self, _):
"""generated default name"""
domain = models.LinkDomain.objects.create(domain="beep.com")
self.assertEqual(domain.name, "beep.com")
self.assertEqual(domain.status, "pending")
def test_create_link_new_domain(self, _):
"""generates link and sets domain"""
link = models.Link.objects.create(url="https://www.hello.com/hi-there")
self.assertEqual(link.domain.domain, "www.hello.com")
self.assertEqual(link.name, "www.hello.com")
def test_create_link_existing_domain(self, _):
"""generate link with a known domain"""
domain = models.LinkDomain.objects.create(domain="www.hello.com", name="Hi")
link = models.Link.objects.create(url="https://www.hello.com/hi-there")
self.assertEqual(link.domain, domain)
self.assertEqual(link.name, "Hi")