예제 #1
0
    def test_save_tags_unchanged_tag_call_tutorial_on_edit(self):
        """_save_tags() should call tutorial's on_edit when tags
        has changed.
        """
        with mock.patch.object(self.object, "on_edit") as on_edit_mock:
            obj_dict = self.get_tutorial_dict()
            form = TutorialForm(obj_dict, instance=self.object)
            form.is_valid()
            form._save_tags()

            self.assertFalse(on_edit_mock.called)
예제 #2
0
    def test_clean_tags_valid_data(self):
        """Should split tags by `,` and turn each of them into
        a TutorialTag object when all tags are valid.
        """
        new_tags = self.generate_tags()
        obj_dict = self.get_tutorial_dict(new_tags=new_tags)

        form = TutorialForm(obj_dict)
        form.is_valid()

        self.assertTagsEquals(form.cleaned_data["tags"], new_tags)
예제 #3
0
    def test_save_tags_create_in_db(self):
        """_save_tags() should save all of the new tags for
        given tutorial.
        """
        new_tags = self.generate_tags()
        obj_dict = self.get_tutorial_dict(new_tags=new_tags)

        form = TutorialForm(obj_dict, instance=self.object)
        form.is_valid()
        form._save_tags()

        self.assertTagsEquals(new_tags, self.object.tags.all())
예제 #4
0
    def test_clean_tags_invalid_data(self):
        """Should not validate when a TutorialTag object is invalid."""
        tag_title_max_length = TutorialTag._meta.get_field("title").max_length
        invalid_tag = "a" * (tag_title_max_length + 1)

        obj_dict = self.get_tutorial_dict(new_tags=invalid_tag)
        form = TutorialForm(obj_dict)

        self.assertFalse(form.is_valid())