Beispiel #1
0
    def test_clean__recipients_and_include_following_cant_both_be_empty(self):
        form = ContentForm(data={
            "text": "barfoo",
            "visibility": Visibility.LIMITED.value
        },
                           user=self.user)
        form.full_clean()
        self.assertFalse(form.is_valid())

        form = ContentForm(
            data={
                "text": "barfoo",
                "visibility": Visibility.LIMITED.value,
                "recipients": self.user.profile.fid
            },
            user=self.user,
        )
        form.full_clean()
        self.assertTrue(form.is_valid())

        form = ContentForm(
            data={
                "text": "barfoo",
                "visibility": Visibility.LIMITED.value,
                "include_following": True
            },
            user=self.user,
        )
        form.full_clean()
        self.assertTrue(form.is_valid())
Beispiel #2
0
 def test_clean__recipients_ignored_if_not_limited(self, visibility):
     form = ContentForm(
         data={"text": "barfoo", "visibility": visibility.value, "recipients": "foobar"},
         user=self.user,
     )
     form.full_clean()
     self.assertTrue(form.is_valid())
Beispiel #3
0
 def test_clean__recipients_ignored_if_not_limited(self, visibility):
     form = ContentForm(
         data={"text": "barfoo", "visibility": visibility.value, "recipients": "foobar"},
         user=self.user,
     )
     form.full_clean()
     self.assertTrue(form.is_valid())
Beispiel #4
0
 def test_clean_text(self):
     form = ContentForm(
         data={"text": "<script>alert</script>", "visibility": Visibility.PUBLIC},
         user=self.user,
     )
     form.full_clean()
     self.assertTrue(form.is_valid())
     self.assertEqual(form.cleaned_data.get('text'), "&lt;script&gt;alert&lt;/script&gt;")
Beispiel #5
0
 def test_clean__recipients(self, values):
     recipients, result = values
     form = ContentForm(
         data={"text": "barfoo", "visibility": Visibility.LIMITED.value, "recipients": recipients},
         user=self.user,
     )
     form.full_clean()
     self.assertTrue(form.is_valid() is result, values)
Beispiel #6
0
 def test_clean_text(self):
     form = ContentForm(
         data={"text": "<script>alert</script>", "visibility": Visibility.PUBLIC},
         user=self.user,
     )
     form.full_clean()
     self.assertTrue(form.is_valid())
     self.assertEqual(form.cleaned_data.get('text'), "&lt;script&gt;alert&lt;/script&gt;")
Beispiel #7
0
 def test_clean__recipients(self, values):
     recipients, result = values
     form = ContentForm(
         data={"text": "barfoo", "visibility": Visibility.LIMITED.value, "recipients": recipients},
         user=self.user,
     )
     form.full_clean()
     self.assertTrue(form.is_valid() is result, values)
Beispiel #8
0
 def test_clean_text__trusted_editor(self):
     self.user.trusted_editor = True
     form = ContentForm(
         data={"text": "<script>alert</script>", "visibility": Visibility.PUBLIC},
         user=self.user,
     )
     form.full_clean()
     self.assertTrue(form.is_valid())
     self.assertEqual(form.cleaned_data.get('text'), "<script>alert</script>")
Beispiel #9
0
    def test_clean__recipients_and_include_following_cant_both_be_empty(self):
        form = ContentForm(data={"text": "barfoo", "visibility": Visibility.LIMITED.value}, user=self.user)
        form.full_clean()
        self.assertFalse(form.is_valid())

        form = ContentForm(
            data={"text": "barfoo", "visibility": Visibility.LIMITED.value, "recipients": self.user.profile.fid},
            user=self.user,
        )
        form.full_clean()
        self.assertTrue(form.is_valid())

        form = ContentForm(
            data={"text": "barfoo", "visibility": Visibility.LIMITED.value, "include_following": True},
            user=self.user,
        )
        form.full_clean()
        self.assertTrue(form.is_valid())
Beispiel #10
0
 def test_clean_text__trusted_editor(self):
     self.user.trusted_editor = True
     form = ContentForm(
         data={"text": "<script>alert</script>", "visibility": Visibility.PUBLIC},
         user=self.user,
     )
     form.full_clean()
     self.assertTrue(form.is_valid())
     self.assertEqual(form.cleaned_data.get('text'), "<script>alert</script>")
Beispiel #11
0
 def test_save__collects_recipients__reply_copies_from_parent(self):
     form = ContentForm(
         data={
             "text": "foobar",
         },
         user=self.user,
         is_reply=True,
     )
     form.full_clean()
     self.assertTrue(form.is_valid())
     content = form.save(parent=self.limited_content)
     self.assertEqual(
         set(content.limited_visibilities.all()),
         {self.profile, self.profile2},
     )
Beispiel #12
0
 def test_save__collects_recipients__reply_copies_from_parent(self):
     form = ContentForm(
         data={
             "text": "foobar",
         },
         user=self.user,
         is_reply=True,
     )
     form.full_clean()
     self.assertTrue(form.is_valid())
     content = form.save(parent=self.limited_content)
     self.assertEqual(
         set(content.limited_visibilities.all()),
         {self.profile, self.profile2},
     )
Beispiel #13
0
 def test_save__collects_recipients(self):
     form = ContentForm(
         data={
             "text": "foobar",
             "visibility": Visibility.LIMITED,
             "recipients": "[email protected],[email protected]"
         },
         user=self.user,
     )
     form.full_clean()
     self.assertTrue(form.is_valid())
     content = form.save()
     self.assertEqual(
         set(content.limited_visibilities.all()),
         {self.profile, self.profile2},
     )
Beispiel #14
0
 def test_save__collects_recipients(self):
     form = ContentForm(
         data={
             "text": "foobar",
             "visibility": Visibility.LIMITED,
             "recipients": "[email protected],[email protected]"
         },
         user=self.user,
     )
     form.full_clean()
     self.assertTrue(form.is_valid())
     content = form.save()
     self.assertEqual(
         set(content.limited_visibilities.all()),
         {self.profile, self.profile2},
     )