mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 19:41:11 +00:00
Adds tests
This commit is contained in:
parent
cfcacb4797
commit
2f924faa05
1 changed files with 57 additions and 0 deletions
|
@ -67,6 +67,7 @@ class LinkViews(TestCase):
|
|||
form.data["filetype"] = "HTML"
|
||||
form.data["book"] = self.book.id
|
||||
form.data["added_by"] = self.local_user.id
|
||||
form.data["availability"] = "loan"
|
||||
|
||||
request = self.factory.post("", form.data)
|
||||
request.user = self.local_user
|
||||
|
@ -87,3 +88,59 @@ class LinkViews(TestCase):
|
|||
|
||||
self.book.refresh_from_db()
|
||||
self.assertEqual(self.book.file_links.first(), link)
|
||||
|
||||
def test_book_links(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.BookFileLinks.as_view()
|
||||
models.FileLink.objects.create(
|
||||
book=self.book,
|
||||
added_by=self.local_user,
|
||||
url="https://www.hello.com",
|
||||
)
|
||||
request = self.factory.get("")
|
||||
request.user = self.local_user
|
||||
result = view(request, self.book.id)
|
||||
self.assertEqual(result.status_code, 200)
|
||||
validate_html(result.render())
|
||||
|
||||
def test_book_links_post(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
link = models.FileLink.objects.create(
|
||||
book=self.book,
|
||||
added_by=self.local_user,
|
||||
url="https://www.hello.com",
|
||||
)
|
||||
view = views.BookFileLinks.as_view()
|
||||
form = forms.FileLinkForm()
|
||||
form.data["url"] = link.url
|
||||
form.data["filetype"] = "HTML"
|
||||
form.data["book"] = self.book.id
|
||||
form.data["added_by"] = self.local_user.id
|
||||
form.data["availability"] = "loan"
|
||||
|
||||
request = self.factory.post("", form.data)
|
||||
request.user = self.local_user
|
||||
view(request, self.book.id, link.id)
|
||||
|
||||
link.refresh_from_db()
|
||||
self.assertEqual(link.filetype, "HTML")
|
||||
self.assertEqual(link.availability, "loan")
|
||||
|
||||
def test_delete_link(self):
|
||||
"""remove a link"""
|
||||
link = models.FileLink.objects.create(
|
||||
book=self.book,
|
||||
added_by=self.local_user,
|
||||
url="https://www.hello.com",
|
||||
)
|
||||
form = forms.FileLinkForm()
|
||||
form.data["url"] = "https://www.example.com"
|
||||
form.data["filetype"] = "HTML"
|
||||
form.data["book"] = self.book.id
|
||||
form.data["added_by"] = self.local_user.id
|
||||
form.data["availability"] = "loan"
|
||||
|
||||
request = self.factory.post("", form.data)
|
||||
request.user = self.local_user
|
||||
views.delete_link(request, self.book.id, link.id)
|
||||
self.assertFalse(models.FileLink.objects.exists())
|
||||
|
|
Loading…
Reference in a new issue