예제 #1
0
    def test_upload_cover_url(self):
        """add a cover via url"""
        self.assertFalse(self.book.cover)
        image_file = pathlib.Path(__file__).parent.joinpath(
            "../../static/images/default_avi.jpg"
        )
        image = Image.open(image_file)
        output = BytesIO()
        image.save(output, format=image.format)
        responses.add(
            responses.GET,
            "http://example.com",
            body=output.getvalue(),
            status=200,
        )

        form = forms.CoverForm(instance=self.book)
        form.data["cover-url"] = "http://example.com"

        request = self.factory.post("", form.data)
        request.user = self.local_user

        with patch(
            "bookwyrm.models.activitypub_mixin.broadcast_task.delay"
        ) as delay_mock:
            views.upload_cover(request, self.book.id)
            self.assertEqual(delay_mock.call_count, 1)

        self.book.refresh_from_db()
        self.assertTrue(self.book.cover)
예제 #2
0
    def test_upload_cover_url(self):
        """add a cover via url"""
        self.assertFalse(self.book.cover)
        form = forms.CoverForm(instance=self.book)
        form.data["cover-url"] = _setup_cover_url()

        request = self.factory.post("", form.data)
        request.user = self.local_user

        with patch(
                "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
        ) as delay_mock:
            views.upload_cover(request, self.book.id)
            self.assertEqual(delay_mock.call_count, 1)

        self.book.refresh_from_db()
        self.assertTrue(self.book.cover)
예제 #3
0
    def test_create_book_upload_cover_url(self):
        """create an entirely new book and work with cover url"""
        self.assertFalse(self.book.cover)
        self.local_user.groups.add(self.group)
        cover_url = _setup_cover_url()

        form = forms.EditionForm()
        form.data["title"] = "New Title"
        form.data["last_edited_by"] = self.local_user.id
        form.data["cover-url"] = cover_url
        request = self.factory.post("", form.data)
        request.user = self.local_user

        with patch(
                "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
        ) as delay_mock:
            views.upload_cover(request, self.book.id)
            self.assertEqual(delay_mock.call_count, 1)

        self.book.refresh_from_db()
        self.assertTrue(self.book.cover)
예제 #4
0
    def test_upload_cover_file(self):
        """ add a cover via file upload """
        self.assertFalse(self.book.cover)
        image_file = pathlib.Path(__file__).parent.joinpath(
            "../../static/images/default_avi.jpg")

        form = forms.CoverForm(instance=self.book)
        form.data["cover"] = SimpleUploadedFile(image_file,
                                                open(image_file, "rb").read(),
                                                content_type="image/jpeg")

        request = self.factory.post("", form.data)
        request.user = self.local_user

        with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"
                   ) as delay_mock:
            views.upload_cover(request, self.book.id)
            self.assertEqual(delay_mock.call_count, 1)

        self.book.refresh_from_db()
        self.assertTrue(self.book.cover)