def test_content_node_edit_form_valid(self):
     """ Test that a form is valid
     :return: None
     """
     data = data_node(self.node_rev_front.node.page_type_id, self.admin)
     form = ContentNodeEditForm(data=data, user=self.admin)
     r = form.is_valid()
     self.assertEqual(r, True)
     self.assertEqual(form.cleaned_data['body'],
                      '<div> </div>&lt;script&gt;alert("This is a test.");&lt;/script&gt;')
    def test_content_node_edit_form_m2m_valid(self):
        """ Test that a node form's reverse m2m is valid
        :return: None
        """
        create_terms(())
        # assign 2 tags
        data = data_node(self.node_rev_front.node.page_type_id, self.admin)
        data['terms'] = (1, 2)
        form = ContentNodeEditForm(data=data, user=self.admin)
        r = form.is_valid()
        self.assertEqual(r, True)
        self.assertEqual(list(form.cleaned_data['terms']), list(TaxonomyTerm.objects.all()))
        form.save()
        self.assertEqual(len(form.errors), 0)
        self.assertEqual(len(form.instance.terms.all()), 2)

        # remove 1 tag
        data['terms'] = (1,)
        form = ContentNodeEditForm(data=data, user=self.admin, instance=form.instance)
        r = form.is_valid()
        self.assertEqual(r, True)
        form.save()
        self.assertEqual(len(form.errors), 0)
        self.assertEqual(len(form.instance.terms.all()), 1)
 def test_content_node_edit_form_invalid(self):
     """ Test that an empty form is invalid
     :return: None
     """
     form = ContentNodeEditForm()
     self.assertEqual(form.is_valid(), False)