コード例 #1
0
ファイル: test_reading.py プロジェクト: mmai/bookwyrm
    def test_start_reading(self):
        """ begin a book """
        shelf = self.local_user.shelf_set.get(identifier="reading")
        self.assertFalse(shelf.books.exists())
        self.assertFalse(models.Status.objects.exists())

        request = self.factory.post(
            "",
            {
                "post-status": True,
                "privacy": "followers",
                "start_date": "2020-01-05",
            },
        )
        request.user = self.local_user
        with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
            views.start_reading(request, self.book.id)

        self.assertEqual(shelf.books.get(), self.book)

        status = models.GeneratedNote.objects.get()
        self.assertEqual(status.user, self.local_user)
        self.assertEqual(status.mention_books.get(), self.book)
        self.assertEqual(status.privacy, "followers")

        readthrough = models.ReadThrough.objects.get()
        self.assertIsNotNone(readthrough.start_date)
        self.assertIsNone(readthrough.finish_date)
        self.assertEqual(readthrough.user, self.local_user)
        self.assertEqual(readthrough.book, self.book)
コード例 #2
0
ファイル: test_reading.py プロジェクト: tastytea/bookwyrm
    def test_start_reading(self):
        ''' begin a book '''
        shelf = self.local_user.shelf_set.get(identifier='reading')
        self.assertFalse(shelf.books.exists())
        self.assertFalse(models.Status.objects.exists())

        request = self.factory.post('', {
            'post-status': True,
            'privacy': 'followers',
            'start_date': '2020-01-05',
        })
        request.user = self.local_user
        with patch('bookwyrm.models.activitypub_mixin.broadcast_task.delay'):
            views.start_reading(request, self.book.id)

        self.assertEqual(shelf.books.get(), self.book)

        status = models.GeneratedNote.objects.get()
        self.assertEqual(status.user, self.local_user)
        self.assertEqual(status.mention_books.get(), self.book)
        self.assertEqual(status.privacy, 'followers')

        readthrough = models.ReadThrough.objects.get()
        self.assertIsNotNone(readthrough.start_date)
        self.assertIsNone(readthrough.finish_date)
        self.assertEqual(readthrough.user, self.local_user)
        self.assertEqual(readthrough.book, self.book)
コード例 #3
0
ファイル: test_reading.py プロジェクト: tastytea/bookwyrm
    def test_start_reading_reshelf(self):
        ''' begin a book '''
        to_read_shelf = self.local_user.shelf_set.get(identifier='to-read')
        with patch('bookwyrm.models.activitypub_mixin.broadcast_task.delay'):
            models.ShelfBook.objects.create(
                shelf=to_read_shelf, book=self.book, user=self.local_user)
        shelf = self.local_user.shelf_set.get(identifier='reading')
        self.assertEqual(to_read_shelf.books.get(), self.book)
        self.assertFalse(shelf.books.exists())
        self.assertFalse(models.Status.objects.exists())

        request = self.factory.post('')
        request.user = self.local_user
        with patch('bookwyrm.models.activitypub_mixin.broadcast_task.delay'):
            views.start_reading(request, self.book.id)

        self.assertFalse(to_read_shelf.books.exists())
        self.assertEqual(shelf.books.get(), self.book)
コード例 #4
0
    def test_start_reading_reshelf(self, _):
        """ begin a book """
        to_read_shelf = self.local_user.shelf_set.get(
            identifier=models.Shelf.TO_READ)
        with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
            models.ShelfBook.objects.create(shelf=to_read_shelf,
                                            book=self.book,
                                            user=self.local_user)
        shelf = self.local_user.shelf_set.get(identifier="reading")
        self.assertEqual(to_read_shelf.books.get(), self.book)
        self.assertFalse(shelf.books.exists())
        self.assertFalse(models.Status.objects.exists())

        request = self.factory.post("")
        request.user = self.local_user
        with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
            views.start_reading(request, self.book.id)

        self.assertFalse(to_read_shelf.books.exists())
        self.assertEqual(shelf.books.get(), self.book)