Beispiel #1
0
 def test_manga_page_formset_set_cover(self):
     self.page2.image = SimpleUploadedFile('sample.jpg', self.create_test_image_file().getvalue())
     self.page2.save()
     formset = MangaEditImagesView.get_formset_cls()(
         user=self.user,
         queryset=MangaPage.objects.filter(manga=self.manga),
         data={
             'form-TOTAL_FORMS': '3',
             'form-INITIAL_FORMS': '3',
             'form-MAX_NUM_FORMS': '100',
             'form-0-id': self.page1.id,
             'form-0-ORDER': '3',
             'form-1-id': self.page2.id,
             'form-1-ORDER': '1',
             'form-1-select': 'on',
             'form-2-id': self.page3.id,
             'form-2-ORDER': '2',
             'action': 'set_cover',
         },
     )
     self.assertTrue(formset.is_valid())
     formset.save(self.manga)
     self.assertEqual(MangaPage.objects.get(id=self.page1.id).page, 1)
     self.assertEqual(MangaPage.objects.get(id=self.page2.id).page, 2)
     self.assertEqual(MangaPage.objects.get(id=self.page3.id).page, 3)
     manga = Manga.objects.get(id=self.manga.id)
     self.assertNotEqual(manga.cover.path, self.page2.image.path)
     self.assertTrue(os.path.exists(manga.cover.path))
Beispiel #2
0
 def test_manga_page_formset_invalid_action(self):
     formset = MangaEditImagesView.get_formset_cls()(
         user=self.user,
         queryset=MangaPage.objects.filter(manga=self.manga),
         data={
             'form-TOTAL_FORMS': '3',
             'form-INITIAL_FORMS': '3',
             'form-MAX_NUM_FORMS': '100',
             'form-0-id': self.page1.id,
             'form-0-ORDER': '1',
             'form-1-id': self.page2.id,
             'form-1-ORDER': '2',
             'form-2-id': self.page3.id,
             'form-2-ORDER': '3',
         },
     )
     self.assertFalse(formset.is_valid())
     self.assertEqual(formset.non_form_errors(), ['The form was submitted without an action, please re-submit this form.'])
Beispiel #3
0
 def test_manga_page_formset_delete_non_selected(self):
     formset = MangaEditImagesView.get_formset_cls()(
         user=self.user,
         queryset=MangaPage.objects.filter(manga=self.manga),
         data={
             'form-TOTAL_FORMS': '3',
             'form-INITIAL_FORMS': '3',
             'form-MAX_NUM_FORMS': '100',
             'form-0-id': self.page1.id,
             'form-0-ORDER': '1',
             'form-1-id': self.page2.id,
             'form-1-ORDER': '2',
             'form-2-id': self.page3.id,
             'form-2-ORDER': '3',
             'action': 'delete',
         },
     )
     self.assertFalse(formset.is_valid())
     self.assertEqual(formset.non_form_errors(), ['Please select at least one image to delete.'])
Beispiel #4
0
 def test_manga_page_formset_set_cover_invalid(self):
     formset = MangaEditImagesView.get_formset_cls()(
         user=self.user,
         queryset=MangaPage.objects.filter(manga=self.manga),
         data={
             'form-TOTAL_FORMS': '3',
             'form-INITIAL_FORMS': '3',
             'form-MAX_NUM_FORMS': '100',
             'form-0-id': self.page1.id,
             'form-0-ORDER': '3',
             'form-1-id': self.page2.id,
             'form-1-ORDER': '1',
             'form-1-select': 'on',
             'form-2-id': self.page3.id,
             'form-2-ORDER': '2',
             'form-2-select': 'on',
             'action': 'set_cover',
         },
     )
     self.assertFalse(formset.is_valid())
     self.assertEqual(formset.non_form_errors(), ['Please select only a single image to set as the cover.'])
Beispiel #5
0
 def test_manga_page_formset_reorder(self):
     formset = MangaEditImagesView.get_formset_cls()(
         user=self.user,
         queryset=MangaPage.objects.filter(manga=self.manga),
         data={
             'form-TOTAL_FORMS': '3',
             'form-INITIAL_FORMS': '3',
             'form-MAX_NUM_FORMS': '100',
             'form-0-id': self.page1.id,
             'form-0-ORDER': '3',
             'form-1-id': self.page2.id,
             'form-1-ORDER': '1',
             'form-2-id': self.page3.id,
             'form-2-ORDER': '2',
             'action': 'reorder',
         },
     )
     self.assertTrue(formset.is_valid())
     formset.save(self.manga)
     self.assertEqual(MangaPage.objects.get(id=self.page1.id).page, 3)
     self.assertEqual(MangaPage.objects.get(id=self.page2.id).page, 1)
     self.assertEqual(MangaPage.objects.get(id=self.page3.id).page, 2)
Beispiel #6
0
 def test_manga_page_formset_unselected_forms(self):
     formset = MangaEditImagesView.get_formset_cls()(
         user=self.user,
         queryset=MangaPage.objects.filter(manga=self.manga),
         data={
             'form-TOTAL_FORMS': '3',
             'form-INITIAL_FORMS': '3',
             'form-MAX_NUM_FORMS': '100',
             'form-0-id': self.page1.id,
             'form-0-ORDER': '1',
             'form-0-select': 'on',
             'form-1-id': self.page2.id,
             'form-1-ORDER': '2',
             'form-2-id': self.page3.id,
             'form-2-ORDER': '3',
             'form-2-select': 'on',
             'action': 'reorder',
         },
     )
     self.assertTrue(formset.is_valid())
     self.assertEqual([f.instance for f in formset.unselected_forms], [self.page2])
     self.assertEqual([f.instance for f in formset.selected_forms], [self.page1, self.page3])