Beispiel #1
0
    def test_create_page_with_slugified_url(self):
        form = PageUpdateForm(data={
            'title': 'test',
            'content': 'my content here'
        })

        self.assertTrue(form.is_valid())
        form.save()
        self.assertEqual(FlatPage.objects.count(), 3)
Beispiel #2
0
    def test_allows_page_to_be_created(self):
        form = PageUpdateForm(data={
            'title': 'test',
            'url': '/my-new-url/',
            'content': 'my content here'
        })

        self.assertTrue(form.is_valid())
        form.save()
        self.assertEqual(FlatPage.objects.count(), 3)
Beispiel #3
0
 def test_doesnt_allow_existing_pages_to_be_clobbered(self):
     form = PageUpdateForm(data={
         'title': 'test',
         'url': '/dashboard/pages/',
     })
     self.assertFalse(form.is_valid())
     self.assertEqual(
         form.errors['url'],
         ['Specified page already exists!']
     )
Beispiel #4
0
    def test_invalid_chars_in_url(self):
        form = PageUpdateForm(data={
            'url': '/%* /',
            'title': 'Title',
            'content': 'Content',
        })

        self.assertFalse(form.is_valid())
        self.assertEqual(
            form.errors['url'],
            ['This value must contain only letters, numbers, dots, underscores, dashes, slashes or tildes.']
        )
Beispiel #5
0
    def test_create_page_with_existing_url_does_not_work(self):
        form = PageUpdateForm(data={
            'title': 'test',
            'url': '/url1/',  # already exists
            'content': 'my content here'
        })

        self.assertFalse(form.is_valid())
        self.assertEqual(
            form.errors['url'],
            ['Specified page already exists!']
        )
Beispiel #6
0
    def test_invalid_url_length(self):
        form = PageUpdateForm(data={
            'url': '/this_url_is_more_than_100_characters_long_which_is_invalid'
                   '_because_the_model_field_has_a_max_length_of_100',
            'title': 'Title',
            'content': 'Content',
        })

        self.assertFalse(form.is_valid())
        self.assertEqual(
            form.errors['url'],
            ['Ensure this value has at most 100 characters (it has 107).']
        )
Beispiel #7
0
    def test_update_page_valid_url(self):
        form = PageUpdateForm(instance=self.flatpage_1, data={
            'title': 'test',
            'url': '/new/url/',
            'content': 'my content here'
        })

        form.save()

        self.flatpage_1.refresh_from_db()
        page = self.flatpage_1
        self.assertEqual(page.title, 'test')
        self.assertEqual(page.url, '/new/url/')
        self.assertEqual(page.content, "my content here")