1
0
Fork 0

Merge branch 'main' into softblock

This commit is contained in:
Hugh Rundle 2023-11-22 20:06:02 +11:00 committed by GitHub
commit c6dea2523c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 972 additions and 76 deletions

View file

@ -86,3 +86,25 @@ class AdminThemesViews(TestCase):
with self.assertRaises(PermissionDenied):
view(request)
def test_test_theme(self):
"""Testing testing testing test"""
theme = models.Theme.objects.first()
self.assertIsNone(theme.loads)
request = self.factory.post("")
request.user = self.local_user
views.test_theme(request, theme.id)
theme.refresh_from_db()
self.assertTrue(theme.loads)
def test_test_theme_broken(self):
"""Testing test for testing when it's a bad theme"""
theme = models.Theme.objects.create(name="bad theme", path="dsf/sdf/sdf.sdf")
self.assertIsNone(theme.loads)
request = self.factory.post("")
request.user = self.local_user
views.test_theme(request, theme.id)
theme.refresh_from_db()
self.assertIs(False, theme.loads)

View file

@ -8,6 +8,7 @@ from django.contrib.contenttypes.models import ContentType
from django.template.response import TemplateResponse
from django.test import TestCase
from django.test.client import RequestFactory
from django.utils import timezone
from bookwyrm import forms, models, views
from bookwyrm.views.books.edit_book import add_authors
@ -209,6 +210,97 @@ class EditBookViews(TestCase):
book = models.Edition.objects.get(title="New Title")
self.assertEqual(book.parent_work.title, "New Title")
def test_published_date_timezone(self):
"""user timezone does not affect publication year"""
# https://github.com/bookwyrm-social/bookwyrm/issues/3028
self.local_user.groups.add(self.group)
create_book = views.CreateBook.as_view()
book_data = {
"title": "January 1st test",
"parent_work": self.work.id,
"last_edited_by": self.local_user.id,
"published_date_day": "1",
"published_date_month": "1",
"published_date_year": "2020",
}
request = self.factory.post("", book_data)
request.user = self.local_user
with timezone.override("Europe/Madrid"): # Ahead of UTC.
create_book(request)
book = models.Edition.objects.get(title="January 1st test")
self.assertEqual(book.edition_info, "2020")
def test_partial_published_dates(self):
"""create a book with partial publication dates, then update them"""
self.local_user.groups.add(self.group)
book_data = {
"title": "An Edition With Dates",
"parent_work": self.work.id,
"last_edited_by": self.local_user.id,
}
initial_pub_dates = {
# published_date: 2023-01-01
"published_date_day": "1",
"published_date_month": "01",
"published_date_year": "2023",
# first_published_date: 1995
"first_published_date_day": "",
"first_published_date_month": "",
"first_published_date_year": "1995",
}
updated_pub_dates = {
# published_date: full -> year-only
"published_date_day": "",
"published_date_month": "",
"published_date_year": "2023",
# first_published_date: add month
"first_published_date_day": "",
"first_published_date_month": "03",
"first_published_date_year": "1995",
}
# create book
create_book = views.CreateBook.as_view()
request = self.factory.post("", book_data | initial_pub_dates)
request.user = self.local_user
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
create_book(request)
book = models.Edition.objects.get(title="An Edition With Dates")
self.assertEqual("2023-01-01", book.published_date.partial_isoformat())
self.assertEqual("1995", book.first_published_date.partial_isoformat())
self.assertTrue(book.published_date.has_day)
self.assertTrue(book.published_date.has_month)
self.assertFalse(book.first_published_date.has_day)
self.assertFalse(book.first_published_date.has_month)
# now edit publication dates
edit_book = views.ConfirmEditBook.as_view()
request = self.factory.post("", book_data | updated_pub_dates)
request.user = self.local_user
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
result = edit_book(request, book.id)
self.assertEqual(result.status_code, 302)
book.refresh_from_db()
self.assertEqual("2023", book.published_date.partial_isoformat())
self.assertEqual("1995-03", book.first_published_date.partial_isoformat())
self.assertFalse(book.published_date.has_day)
self.assertFalse(book.published_date.has_month)
self.assertFalse(book.first_published_date.has_day)
self.assertTrue(book.first_published_date.has_month)
def test_create_book_existing_work(self):
"""create an entirely new book and work"""
view = views.ConfirmEditBook.as_view()