PageRenderTime 17578ms CodeModel.GetById 17510ms app.highlight 8ms RepoModel.GetById 39ms app.codeStats 0ms

/tests/regressiontests/comment_tests/tests/__init__.py

https://code.google.com/p/mango-py/
Python | 90 lines | 81 code | 4 blank | 5 comment | 0 complexity | abe44235a8cdebc77197207206be0b92 MD5 | raw file
 1from django.contrib.auth.models import User
 2from django.contrib.comments.forms import CommentForm
 3from django.contrib.comments.models import Comment
 4from django.contrib.contenttypes.models import ContentType
 5from django.contrib.sites.models import Site
 6from django.test import TestCase
 7from regressiontests.comment_tests.models import Article, Author
 8
 9# Shortcut
10CT = ContentType.objects.get_for_model
11
12# Helper base class for comment tests that need data.
13class CommentTestCase(TestCase):
14    fixtures = ["comment_tests"]
15    urls = 'django.contrib.comments.urls'
16
17    def createSomeComments(self):
18        # Two anonymous comments on two different objects
19        c1 = Comment.objects.create(
20            content_type = CT(Article),
21            object_pk = "1",
22            user_name = "Joe Somebody",
23            user_email = "jsomebody@example.com",
24            user_url = "http://example.com/~joe/",
25            comment = "First!",
26            site = Site.objects.get_current(),
27        )
28        c2 = Comment.objects.create(
29            content_type = CT(Author),
30            object_pk = "1",
31            user_name = "Joe Somebody",
32            user_email = "jsomebody@example.com",
33            user_url = "http://example.com/~joe/",
34            comment = "First here, too!",
35            site = Site.objects.get_current(),
36        )
37
38        # Two authenticated comments: one on the same Article, and
39        # one on a different Author
40        user = User.objects.create(
41            username = "frank_nobody",
42            first_name = "Frank",
43            last_name = "Nobody",
44            email = "fnobody@example.com",
45            password = "",
46            is_staff = False,
47            is_active = True,
48            is_superuser = False,
49        )
50        c3 = Comment.objects.create(
51            content_type = CT(Article),
52            object_pk = "1",
53            user = user,
54            user_url = "http://example.com/~frank/",
55            comment = "Damn, I wanted to be first.",
56            site = Site.objects.get_current(),
57        )
58        c4 = Comment.objects.create(
59            content_type = CT(Author),
60            object_pk = "2",
61            user = user,
62            user_url = "http://example.com/~frank/",
63            comment = "You get here first, too?",
64            site = Site.objects.get_current(),
65        )
66
67        return c1, c2, c3, c4
68
69    def getData(self):
70        return {
71            'name'      : 'Jim Bob',
72            'email'     : 'jim.bob@example.com',
73            'url'       : '',
74            'comment'   : 'This is my comment',
75        }
76
77    def getValidData(self, obj):
78        f = CommentForm(obj)
79        d = self.getData()
80        d.update(f.initial)
81        return d
82
83from regressiontests.comment_tests.tests.app_api_tests import *
84from regressiontests.comment_tests.tests.feed_tests import *
85from regressiontests.comment_tests.tests.model_tests import *
86from regressiontests.comment_tests.tests.comment_form_tests import *
87from regressiontests.comment_tests.tests.templatetag_tests import *
88from regressiontests.comment_tests.tests.comment_view_tests import *
89from regressiontests.comment_tests.tests.moderation_view_tests import *
90from regressiontests.comment_tests.tests.comment_utils_moderators_tests import *