Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Model:
- class Post(models.Model):
- title = models.CharField(max_length=255)
- machine_name = models.SlugField(max_length=255, unique=True)
- description = models.CharField(max_length=255, blank=True)
- content = models.TextField(blank=True)
- publication_date = models.DateTimeField()
- published = models.BooleanField(default=True)
- owner = models.ForeignKey(auth.models.User)
- tags=TaggableManager(blank=True)
- keywords = models.CharField(max_length=255, blank=True)
- images = models.ManyToManyField(Image, blank=True )
- tests.py
- """
- This file demonstrates writing tests using the unittest module. These will pass
- when you run "manage.py test".
- Replace this with more appropriate tests for your application.
- """
- from django.test import TestCase
- from posts.models import Post, Image
- from django.utils import timezone
- from django.contrib.auth.models import User
- class PostsTest(TestCase):
- def setUp(self):
- self.user = User.objects.create_user(username='testuser', email='testuser@test.com', password='top_secret')
- def create_image(self, name = 'test_image', image = 'test.jpg'):
- return Image.objects.create(name = name, image = image)
- # Tag list is using django-taggit, in the admin adding tag text separated by a comma adds the tags
- def create_post(self):
- return Post.objects.create(title = 'title',
- machine_name = 'machine_name',
- description = 'description',
- content = 'content',
- publication_date = timezone.now(),
- owner = self.user,
- keywords = 'key')
- def test_image_creation(self):
- i = self.create_image('testImage', 'test.jpg')
- self.assertTrue(isinstance(i, Image))
- self.assertEqual(i.__unicode__(), i.name)
- def test_post_creation(self):
- a = self.create_post()
- self.assertTrue(isinstance(a, Post))
- self.assertEqual(a.__unicode__(), a.title)
- def tearDown(self):
- self.user.delete()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement