add post tests
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
from datetime import timedelta
|
||||
|
||||
from django.test import TestCase
|
||||
from django.utils import timezone
|
||||
|
||||
from .models import Post
|
||||
from .forms import PostForm
|
||||
|
||||
|
||||
class PostTestCase(TestCase):
|
||||
def setUp(self):
|
||||
post = Post()
|
||||
post.title = "Informationen zur ÖH Wahl"
|
||||
post.post_type = "N"
|
||||
post.public_date = timezone.now().date()
|
||||
post.save()
|
||||
|
||||
def test_post(self):
|
||||
post = Post.objects.get(title="Informationen zur ÖH Wahl")
|
||||
slug_str = timezone.now().date().strftime("%Y-%m-%d")
|
||||
date_str = timezone.now().date().strftime("%d.%m.%Y")
|
||||
self.assertEqual(post.__str__(), "Post (%s-informationen-zur-oh-wahl, %s): Informationen zur ÖH Wahl" % (slug_str, date_str))
|
||||
|
||||
def test_date_sorted(self):
|
||||
post = Post()
|
||||
post.title = "zukünftiges FET Fest"
|
||||
post.post_type = "E"
|
||||
post.public_date = timezone.now().date()
|
||||
post.event_start = timezone.now() + timedelta(1)
|
||||
post.save()
|
||||
|
||||
post = Post()
|
||||
post.title = "vergangenes FET Fest"
|
||||
post.post_type = "E"
|
||||
post.public_date = timezone.now().date()
|
||||
post.event_start = timezone.now() - timedelta(1)
|
||||
post.save()
|
||||
|
||||
post_list = Post.objects.get_date_sorted_list()
|
||||
self.assertEqual(post_list[0].title, "zukünftiges FET Fest")
|
||||
self.assertEqual(post_list[1].title, "Informationen zur ÖH Wahl")
|
||||
self.assertEqual(post_list[2].title, "vergangenes FET Fest")
|
||||
|
||||
Reference in New Issue
Block a user