summaryrefslogtreecommitdiffstats
path: root/forum/tests.py
blob: 8419dd8679c12bc47e571db47259f2123bc925a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from django.test import Client, TestCase
from django.contrib.auth.models import User
from forum import models
import datetime
from django.core.urlresolvers import reverse

class AnonymousVisitorTests(TestCase):
    fixtures = ['forum/fixtures/full_dump.json',]

    def test_index(self):
        #todo: merge this with all reader url tests
        print 'trying to reverse index'
        response = self.client.get(reverse('index'), follow=True)
        self.assertEqual(response.status_code, 200)
        self.failUnless(len(response.redirect_chain) == 1)
        self.failUnless(response.redirect_chain[0][0].endswith('/questions/'))
        c = response.context[0]
        t = response.template[0]
        self.assertEqual(t.name, 'questions.html')
        print 'index works'

    def test_reader_urls(self):
        #todo: test redirects better
        def try_url(
                url_name, status_code=200, template=None, 
                kwargs={}, redirect_url=None, follow=False
            ):
            url = reverse(url_name, kwargs = kwargs)
            print 'getting url %s' % url
            r = self.client.get(url, follow=follow)
            if hasattr(self.client, 'redirect_chain'):
                print self.client.redirect_chain
            self.assertEqual(r.status_code, status_code)
            if template:
                #asuming that there is more than one template
                self.assertEqual(r.template[0].name, template)
        try_url('sitemap')
        try_url('about', template='about.html')
        try_url('privacy', template='privacy.html')
        try_url('logout', template='logout.html')
        try_url('user_signin', template='authopenid/signin.html')
        try_url('tags', template='tags.html')
        try_url('badges', template='badges.html')
        try_url(
                'answer_revisions', 
                template='revisions_answer.html',
                kwargs={'id':38}
            )
        try_url(
                'questions',
                template='questions.html'
            )
        try_url(
                'question',
                kwargs={'id':1},
            )
        try_url(
                'question',
                kwargs={'id':2},
            )
        try_url(
                'question',
                kwargs={'id':3},
            )
        try_url(
                'question_revisions',
                kwargs={'id':17},
                template='revisions_question.html'
            )
        try_url(
                'users',
                template='users.html'
            )
        try_url(
                'edit_user',
                template='authopenid/signin.html',
                kwargs={'id':4},
                status_code=200,
                follow=True,
            )