-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from pinax/slug-and-markup
Validate all fields when saving Post model
- Loading branch information
Showing
11 changed files
with
149 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,4 @@ Javyer DerDerian | |
Alexis Santos | ||
Joe di Stefano | ||
Enrique García Navalón | ||
Graham Ullrich |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.10.5 on 2017-02-13 10:35 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('blog', '0017_remove_post_tweet_text'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='post', | ||
name='slug', | ||
field=models.SlugField(max_length=90, verbose_name='Slug'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from __future__ import absolute_import | ||
|
||
from django.contrib.auth import get_user_model | ||
from django.test import TestCase | ||
|
||
from ..forms import PostForm | ||
from ..models import ( | ||
Blog, | ||
Post, | ||
Section, | ||
) | ||
from .tests import randomword | ||
|
||
|
||
class TestForms(TestCase): | ||
|
||
def setUp(self): | ||
super(TestForms, self).setUp() | ||
|
||
self.user = get_user_model().objects.create_user( | ||
username="patrick", | ||
password="password" | ||
) | ||
self.user.save() | ||
self.blog = Blog.objects.first() | ||
self.section = Section.objects.create(name="hello", slug="hello") | ||
self.content = "You won't believe what happened next!" | ||
self.teaser = "Only his dog knows the truth" | ||
self.title_len = Post._meta.get_field("title").max_length | ||
|
||
def test_max_slug(self): | ||
""" | ||
Ensure Post can be created with slug same length as title. | ||
""" | ||
title = randomword(self.title_len) | ||
form_data = { | ||
"section": self.section, | ||
"title": title, | ||
"content": self.content, | ||
"teaser": self.teaser, | ||
"state": 1 | ||
} | ||
form = PostForm(data=form_data) | ||
# slug field is not validated in form | ||
self.assertTrue(form.is_valid()) | ||
# slug field is set (from title) in model .save() method | ||
self.assertTrue(form.save(blog=self.blog, author=self.user)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters