mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-18 14:16:45 +00:00
Pass update fields when ticking last active date
This commit is contained in:
parent
a84a744e8d
commit
cfbe1b29cd
6 changed files with 36 additions and 28 deletions
|
@ -30,7 +30,7 @@ class Favorite(ActivityMixin, BookWyrmModel):
|
|||
def save(self, *args, **kwargs):
|
||||
"""update user active time"""
|
||||
self.user.last_active_date = timezone.now()
|
||||
self.user.save(broadcast=False)
|
||||
self.user.save(broadcast=False, update_fields=["last_active_date"])
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
if self.status.user.local and self.status.user != self.user:
|
||||
|
|
|
@ -30,7 +30,7 @@ class ReadThrough(BookWyrmModel):
|
|||
def save(self, *args, **kwargs):
|
||||
"""update user active time"""
|
||||
self.user.last_active_date = timezone.now()
|
||||
self.user.save(broadcast=False)
|
||||
self.user.save(broadcast=False, update_fields=["last_active_date"])
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
def create_update(self):
|
||||
|
@ -55,5 +55,5 @@ class ProgressUpdate(BookWyrmModel):
|
|||
def save(self, *args, **kwargs):
|
||||
"""update user active time"""
|
||||
self.user.last_active_date = timezone.now()
|
||||
self.user.save(broadcast=False)
|
||||
self.user.save(broadcast=False, update_fields=["last_active_date"])
|
||||
super().save(*args, **kwargs)
|
||||
|
|
|
@ -119,10 +119,12 @@ class AbstractConnector(TestCase):
|
|||
@responses.activate
|
||||
def test_get_or_create_author(self):
|
||||
"""load an author"""
|
||||
self.connector.author_mappings = [
|
||||
self.connector.author_mappings = (
|
||||
[ # pylint: disable=attribute-defined-outside-init
|
||||
Mapping("id"),
|
||||
Mapping("name"),
|
||||
]
|
||||
)
|
||||
|
||||
responses.add(
|
||||
responses.GET,
|
||||
|
|
|
@ -16,9 +16,12 @@ from bookwyrm.settings import DOMAIN
|
|||
|
||||
|
||||
def make_date(*args):
|
||||
"""helper function to easily generate a date obj"""
|
||||
return datetime.datetime(*args, tzinfo=pytz.UTC)
|
||||
|
||||
|
||||
# pylint: disable=consider-using-with
|
||||
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
|
||||
class GoodreadsImport(TestCase):
|
||||
"""importing from goodreads csv"""
|
||||
|
||||
|
@ -27,6 +30,7 @@ class GoodreadsImport(TestCase):
|
|||
self.importer = GoodreadsImporter()
|
||||
datafile = pathlib.Path(__file__).parent.joinpath("../data/goodreads.csv")
|
||||
self.csv = open(datafile, "r", encoding=self.importer.encoding)
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
|
||||
self.user = models.User.objects.create_user(
|
||||
"mouse", "mouse@mouse.mouse", "password", local=True
|
||||
)
|
||||
|
@ -49,7 +53,7 @@ class GoodreadsImport(TestCase):
|
|||
parent_work=work,
|
||||
)
|
||||
|
||||
def test_create_job(self):
|
||||
def test_create_job(self, _):
|
||||
"""creates the import job entry and checks csv"""
|
||||
import_job = self.importer.create_job(self.user, self.csv, False, "public")
|
||||
self.assertEqual(import_job.user, self.user)
|
||||
|
@ -65,7 +69,7 @@ class GoodreadsImport(TestCase):
|
|||
self.assertEqual(import_items[2].index, 2)
|
||||
self.assertEqual(import_items[2].data["Book Id"], "28694510")
|
||||
|
||||
def test_create_retry_job(self):
|
||||
def test_create_retry_job(self, _):
|
||||
"""trying again with items that didn't import"""
|
||||
import_job = self.importer.create_job(self.user, self.csv, False, "unlisted")
|
||||
import_items = models.ImportItem.objects.filter(job=import_job).all()[:2]
|
||||
|
@ -83,7 +87,7 @@ class GoodreadsImport(TestCase):
|
|||
self.assertEqual(retry_items[1].index, 1)
|
||||
self.assertEqual(retry_items[1].data["Book Id"], "52691223")
|
||||
|
||||
def test_start_import(self):
|
||||
def test_start_import(self, _):
|
||||
"""begin loading books"""
|
||||
import_job = self.importer.create_job(self.user, self.csv, False, "unlisted")
|
||||
MockTask = namedtuple("Task", ("id"))
|
||||
|
@ -95,7 +99,7 @@ class GoodreadsImport(TestCase):
|
|||
self.assertEqual(import_job.task_id, "7")
|
||||
|
||||
@responses.activate
|
||||
def test_import_data(self):
|
||||
def test_import_data(self, _):
|
||||
"""resolve entry"""
|
||||
import_job = self.importer.create_job(self.user, self.csv, False, "unlisted")
|
||||
book = models.Edition.objects.create(title="Test Book")
|
||||
|
@ -110,7 +114,7 @@ class GoodreadsImport(TestCase):
|
|||
import_item = models.ImportItem.objects.get(job=import_job, index=0)
|
||||
self.assertEqual(import_item.book.id, book.id)
|
||||
|
||||
def test_handle_imported_book(self):
|
||||
def test_handle_imported_book(self, _):
|
||||
"""goodreads import added a book, this adds related connections"""
|
||||
shelf = self.user.shelf_set.filter(identifier="read").first()
|
||||
self.assertIsNone(shelf.books.first())
|
||||
|
@ -141,7 +145,7 @@ class GoodreadsImport(TestCase):
|
|||
self.assertEqual(readthrough.start_date, make_date(2020, 10, 21))
|
||||
self.assertEqual(readthrough.finish_date, make_date(2020, 10, 25))
|
||||
|
||||
def test_handle_imported_book_already_shelved(self):
|
||||
def test_handle_imported_book_already_shelved(self, _):
|
||||
"""goodreads import added a book, this adds related connections"""
|
||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||
shelf = self.user.shelf_set.filter(identifier="to-read").first()
|
||||
|
@ -179,7 +183,7 @@ class GoodreadsImport(TestCase):
|
|||
self.assertEqual(readthrough.start_date, make_date(2020, 10, 21))
|
||||
self.assertEqual(readthrough.finish_date, make_date(2020, 10, 25))
|
||||
|
||||
def test_handle_import_twice(self):
|
||||
def test_handle_import_twice(self, _):
|
||||
"""re-importing books"""
|
||||
shelf = self.user.shelf_set.filter(identifier="read").first()
|
||||
import_job = models.ImportJob.objects.create(user=self.user)
|
||||
|
@ -212,7 +216,7 @@ class GoodreadsImport(TestCase):
|
|||
self.assertEqual(readthrough.finish_date, make_date(2020, 10, 25))
|
||||
|
||||
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
|
||||
def test_handle_imported_book_review(self, _):
|
||||
def test_handle_imported_book_review(self, *_):
|
||||
"""goodreads review import"""
|
||||
import_job = models.ImportJob.objects.create(user=self.user)
|
||||
datafile = pathlib.Path(__file__).parent.joinpath("../data/goodreads.csv")
|
||||
|
@ -234,7 +238,7 @@ class GoodreadsImport(TestCase):
|
|||
self.assertEqual(review.privacy, "unlisted")
|
||||
|
||||
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
|
||||
def test_handle_imported_book_rating(self, _):
|
||||
def test_handle_imported_book_rating(self, *_):
|
||||
"""goodreads rating import"""
|
||||
import_job = models.ImportJob.objects.create(user=self.user)
|
||||
datafile = pathlib.Path(__file__).parent.joinpath(
|
||||
|
@ -257,7 +261,7 @@ class GoodreadsImport(TestCase):
|
|||
self.assertEqual(review.published_date, make_date(2019, 7, 8))
|
||||
self.assertEqual(review.privacy, "unlisted")
|
||||
|
||||
def test_handle_imported_book_reviews_disabled(self):
|
||||
def test_handle_imported_book_reviews_disabled(self, _):
|
||||
"""goodreads review import"""
|
||||
import_job = models.ImportJob.objects.create(user=self.user)
|
||||
datafile = pathlib.Path(__file__).parent.joinpath("../data/goodreads.csv")
|
||||
|
|
|
@ -19,6 +19,8 @@ def make_date(*args):
|
|||
return datetime.datetime(*args, tzinfo=pytz.UTC)
|
||||
|
||||
|
||||
# pylint: disable=consider-using-with
|
||||
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
|
||||
class LibrarythingImport(TestCase):
|
||||
"""importing from librarything tsv"""
|
||||
|
||||
|
@ -51,7 +53,7 @@ class LibrarythingImport(TestCase):
|
|||
parent_work=work,
|
||||
)
|
||||
|
||||
def test_create_job(self):
|
||||
def test_create_job(self, _):
|
||||
"""creates the import job entry and checks csv"""
|
||||
import_job = self.importer.create_job(self.user, self.csv, False, "public")
|
||||
self.assertEqual(import_job.user, self.user)
|
||||
|
@ -67,7 +69,7 @@ class LibrarythingImport(TestCase):
|
|||
self.assertEqual(import_items[2].index, 2)
|
||||
self.assertEqual(import_items[2].data["Book Id"], "5015399")
|
||||
|
||||
def test_create_retry_job(self):
|
||||
def test_create_retry_job(self, _):
|
||||
"""trying again with items that didn't import"""
|
||||
import_job = self.importer.create_job(self.user, self.csv, False, "unlisted")
|
||||
import_items = models.ImportItem.objects.filter(job=import_job).all()[:2]
|
||||
|
@ -86,7 +88,7 @@ class LibrarythingImport(TestCase):
|
|||
self.assertEqual(retry_items[1].data["Book Id"], "5015319")
|
||||
|
||||
@responses.activate
|
||||
def test_import_data(self):
|
||||
def test_import_data(self, _):
|
||||
"""resolve entry"""
|
||||
import_job = self.importer.create_job(self.user, self.csv, False, "unlisted")
|
||||
book = models.Edition.objects.create(title="Test Book")
|
||||
|
@ -101,7 +103,7 @@ class LibrarythingImport(TestCase):
|
|||
import_item = models.ImportItem.objects.get(job=import_job, index=0)
|
||||
self.assertEqual(import_item.book.id, book.id)
|
||||
|
||||
def test_handle_imported_book(self):
|
||||
def test_handle_imported_book(self, _):
|
||||
"""librarything import added a book, this adds related connections"""
|
||||
shelf = self.user.shelf_set.filter(identifier="read").first()
|
||||
self.assertIsNone(shelf.books.first())
|
||||
|
@ -131,7 +133,7 @@ class LibrarythingImport(TestCase):
|
|||
self.assertEqual(readthrough.start_date, make_date(2007, 4, 16))
|
||||
self.assertEqual(readthrough.finish_date, make_date(2007, 5, 8))
|
||||
|
||||
def test_handle_imported_book_already_shelved(self):
|
||||
def test_handle_imported_book_already_shelved(self, _):
|
||||
"""librarything import added a book, this adds related connections"""
|
||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||
shelf = self.user.shelf_set.filter(identifier="to-read").first()
|
||||
|
@ -163,7 +165,7 @@ class LibrarythingImport(TestCase):
|
|||
self.assertEqual(readthrough.start_date, make_date(2007, 4, 16))
|
||||
self.assertEqual(readthrough.finish_date, make_date(2007, 5, 8))
|
||||
|
||||
def test_handle_import_twice(self):
|
||||
def test_handle_import_twice(self, _):
|
||||
"""re-importing books"""
|
||||
shelf = self.user.shelf_set.filter(identifier="read").first()
|
||||
import_job = models.ImportJob.objects.create(user=self.user)
|
||||
|
@ -216,7 +218,7 @@ class LibrarythingImport(TestCase):
|
|||
self.assertEqual(review.published_date, make_date(2007, 5, 8))
|
||||
self.assertEqual(review.privacy, "unlisted")
|
||||
|
||||
def test_handle_imported_book_reviews_disabled(self):
|
||||
def test_handle_imported_book_reviews_disabled(self, _):
|
||||
"""librarything review import"""
|
||||
import_job = models.ImportJob.objects.create(user=self.user)
|
||||
datafile = pathlib.Path(__file__).parent.joinpath("../data/librarything.tsv")
|
||||
|
|
|
@ -50,7 +50,7 @@ class Login(View):
|
|||
# successful login
|
||||
login(request, user)
|
||||
user.last_active_date = timezone.now()
|
||||
user.save(broadcast=False)
|
||||
user.save(broadcast=False, update_fields=["last_active_date"])
|
||||
return redirect(request.GET.get("next", "/"))
|
||||
|
||||
# login errors
|
||||
|
|
Loading…
Reference in a new issue