FeedsTestCase.atom_base()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
dl 0
loc 7
rs 10
1
from django.conf import settings
2
from django.utils.feedgenerator import rfc3339_date
3
4
from actstream.tests import base
5
6
7
class FeedsTestCase(base.DataTestCase):
8
    urls = 'actstream.urls'
9
10
    @property
11
    def rss_base(self):
12
        return ['<?xml version="1.0" encoding="utf-8"?>\n', '<rss ',
13
                'xmlns:atom="http://www.w3.org/2005/Atom"', 'version="2.0"',
14
                '<language>%s' % settings.LANGUAGE_CODE]
15
16
    @property
17
    def atom_base(self):
18
        return ['<?xml version="1.0" encoding="utf-8"?>\n',
19
                'xmlns="http://www.w3.org/2005/Atom"',
20
                'xml:lang="%s"' % settings.LANGUAGE_CODE,
21
                '<uri>http://example.com/detail/',
22
                '<id>tag:example.com,2000-01-01:/detail/']
23
24
    def test_feed(self):
25
        self.client.login(username='admin', password='admin')
26
        expected = [
27
            'Activity feed for your followed actors',
28
            'Public activities of actors you follow',
29
            'Two started following CoolGroup %s ago' % self.timesince,
30
            'Two joined CoolGroup %s ago' % self.timesince,
31
        ]
32
        rss = self.capture('actstream_feed')
33
        self.assertAllIn(self.rss_base + expected, rss)
34
        atom = self.capture('actstream_feed_atom')
35
        self.assertAllIn(self.atom_base + expected, atom)
36
        json = self.capture('actstream_feed_json')
37
38
    def test_model_feed(self):
39
        expected = [
40
            'Activity feed from %s' % self.User.__name__,
41
            'Public activities of %s' % self.User.__name__,
42
            'admin commented on CoolGroup %s ago' % self.timesince,
43
            'Two started following CoolGroup %s ago' % self.timesince,
44
            'Two joined CoolGroup %s ago' % self.timesince,
45
            'admin started following Two %s ago' % self.timesince,
46
            'admin joined CoolGroup %s ago' % self.timesince,
47
        ]
48
        rss = self.capture('actstream_model_feed', self.user_ct.pk)
49
        self.assertAllIn(self.rss_base + expected, rss)
50
        atom = self.capture('actstream_model_feed_atom', self.user_ct.pk)
51
        self.assertAllIn(self.atom_base + expected, atom)
52
        json = self.capture('actstream_model_feed_json', self.user_ct.pk)
53
54
    def test_object_feed(self):
55
        expected = [
56
            'Activity for Two',
57
            'admin started following Two %s ago' % self.timesince,
58
        ]
59
        rss = self.capture('actstream_object_feed',
60
                           self.user_ct.pk, self.user2.pk)
61
        self.assertAllIn(self.rss_base + expected, rss)
62
        atom = self.capture('actstream_object_feed_atom',
63
                            self.user_ct.pk, self.user2.pk)
64
        self.assertAllIn(self.atom_base + expected, atom)
65
        json = self.capture(
66
            'actstream_object_feed_json',
67
            self.user_ct.pk, self.user2.pk
68
        )
69