Ejemplo n.º 1
0
 def test_non_auth_post(self):
     with mock.patch("latex.converter.Tex2ImgBase.get_converted_data_url"
                     ) as mock_convert:
         mock_convert.return_value = get_fake_data_url("foob=")
         with self.temporarily_switch_to_user(None):
             resp = self.post_latex_form_view(data=self.get_post_data(),
                                              follow=False)
         self.assertEqual(resp.status_code, 302)
         self.assertEqual(LatexImage.objects.all().count(), 0)
         self.assertEqual(mock_convert.call_count, 0)
Ejemplo n.º 2
0
    def test_post_success_no_convert_if_exist(self):
        self.post_latex_form_view(data=self.get_post_data())
        self.assertEqual(LatexImage.objects.all().count(), 1)

        with mock.patch("latex.converter.Tex2ImgBase.get_converted_data_url"
                        ) as mock_convert:
            mock_convert.return_value = get_fake_data_url("foob=")
            resp = self.post_latex_form_view(data=self.get_post_data())
            self.assertEqual(mock_convert.call_count, 0)

        self.assertEqual(resp.status_code, 200)
        self.assertEqual(LatexImage.objects.all().count(), 1)
Ejemplo n.º 3
0
    def test_post_errored_no_convert_if_exist_with_tex_key(self):
        tex_key = "what_ever_key_error"
        factories.LatexImageErrorFactory(tex_key=tex_key)
        self.assertEqual(LatexImage.objects.all().count(), 1)

        with mock.patch("latex.converter.Tex2ImgBase.get_converted_data_url"
                        ) as mock_convert:
            mock_convert.return_value = get_fake_data_url("foob=")
            resp = self.post_latex_form_view(data=self.get_post_data(
                tex_key=tex_key))

            self.assertEqual(resp.status_code, 400)
            self.assertEqual(LatexImage.objects.all().count(), 1)
            self.assertEqual(mock_convert.call_count, 0)
Ejemplo n.º 4
0
    def test_no_create_duplicate(self):
        first_object = self.create_n_instances()[0]

        with mock.patch("latex.converter.Tex2ImgBase.get_converted_data_url"
                        ) as mock_convert:
            mock_convert.return_value = get_fake_data_url("foob=")
            resp = self.client.post(
                self.get_list_url(),
                data=self.get_post_data(tex_key=first_object.tex_key),
                format='json')
            mock_convert.assert_not_called()

        self.assertEqual(resp.status_code, 200)
        self.assertEqual(LatexImage.objects.all().count(), self.n_new)
Ejemplo n.º 5
0
    def test_no_create_duplicate_errored(self):
        tex_key = "what_ever_key"
        factories.LatexImageErrorFactory(tex_key=tex_key,
                                         creator=self.test_user)

        with mock.patch("latex.converter.Tex2ImgBase.get_converted_data_url"
                        ) as mock_convert:
            mock_convert.return_value = get_fake_data_url("foob=")
            resp = self.client.post(self.get_list_url(),
                                    data=self.get_post_data(tex_key=tex_key),
                                    format='json')
            mock_convert.assert_not_called()

        self.assertEqual(resp.status_code, 400)
        self.assertEqual(LatexImage.objects.all().count(), 1)
Ejemplo n.º 6
0
 def test_clean_both_dataurl_and_compile_error(self):
     a = LatexImage(tex_key="foo",
                    data_url=get_fake_data_url("foob="),
                    compile_error="some error")
     with self.assertRaises(ValidationError):
         a.save()