##// END OF EJS Templates
Partially fixed tests and model definition
neko259 -
r7:bb33ad66 default
parent child Browse files
Show More
@@ -12,7 +12,7 b' class PostManager(models.Manager):'
12 ip = NO_IP):
12 ip = NO_IP):
13 post = self.create(title = title,
13 post = self.create(title = title,
14 text = text,
14 text = text,
15 pub_date = timezone.now(),
15 pub_time = timezone.now(),
16 parent = parent_id,
16 parent = parent_id,
17 image = image,
17 image = image,
18 poster_ip = ip,
18 poster_ip = ip,
@@ -21,7 +21,7 b' class PostManager(models.Manager):'
21 return post
21 return post
22
22
23 def delete_post(self, post):
23 def delete_post(self, post):
24 children = self.filter(parent = post.parent)
24 children = self.filter(parent = post.id)
25 for child in children:
25 for child in children:
26 self.delete_post(child)
26 self.delete_post(child)
27 post.delete()
27 post.delete()
@@ -66,7 +66,7 b' class Post(models.Model):'
66 poster_ip = models.IPAddressField()
66 poster_ip = models.IPAddressField()
67 poster_user_agent = models.TextField()
67 poster_user_agent = models.TextField()
68 parent = models.BigIntegerField()
68 parent = models.BigIntegerField()
69 tags = models.ForeignKey(Tag)
69 tags = models.ManyToManyField(Tag)
70
70
71 def __unicode__(self):
71 def __unicode__(self):
72 return self.title + ' (' + self.text + ')' No newline at end of file
72 return self.title + ' (' + self.text + ')'
@@ -1,28 +1,29 b''
1 from django.test import TestCase
1 from django.test import TestCase
2 import boards
2
3
3 from boards.models import Post
4 from boards.models import Post
4
5
5 class BoardTests(TestCase):
6 class BoardTests(TestCase):
6
7
7 def create_post(self, parent_id):
8 def create_post(self):
8 return Post.objects.create_post(title = 'title',
9 return Post.objects.create_post(title = 'title',
9 text = 'text', parent_id = parent_id)
10 text = 'text')
10
11
11 def test_post_add(self):
12 def test_post_add(self):
12 post = self.create_post(Post.NO_PARENT)
13 post = self.create_post()
13
14
14 self.assertIsNotNone(post)
15 self.assertIsNotNone(post)
15 self.assertEqual(Post.NO_PARENT, post.parent)
16 self.assertEqual(boards.models.NO_PARENT, post.parent)
16
17
17 def test_delete_post(self):
18 def test_delete_post(self):
18 post = self.create_post(Post.NO_PARENT)
19 post = self.create_post()
19
20
20 Post.objects.delete_post(post)
21 Post.objects.delete_post(post)
21
22
22 self.assertIsNone(post)
23 self.assertIsNone(post)
23
24
24 def test_delete_posts_by_ip(self):
25 def test_delete_posts_by_ip(self):
25 post = self.create_post(Post.NO_PARENT)
26 post = self.create_post()
26
27
27 Post.objects.delete_posts_by_ip('0.0.0.0')
28 Post.objects.delete_posts_by_ip('0.0.0.0')
28
29
General Comments 0
You need to be logged in to leave comments. Login now