~ubuntu-branches/debian/sid/python-django/sid

« back to all changes in this revision

Viewing changes to tests/comment_tests/tests/__init__.py

  • Committer: Package Import Robot
  • Author(s): Luke Faraone
  • Date: 2013-11-07 15:33:49 UTC
  • mfrom: (1.3.12)
  • Revision ID: package-import@ubuntu.com-20131107153349-e31sc149l2szs3jb
Tags: 1.6-1
* New upstream version. Closes: #557474, #724637.
* python-django now also suggests the installation of ipython,
  bpython, python-django-doc, and libgdal1.
  Closes: #636511, #686333, #704203
* Set package maintainer to Debian Python Modules Team.
* Bump standards version to 3.9.5, no changes needed.

Show diffs side-by-side

added added

removed removed

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