|
1
|
|
|
from datetime import datetime |
|
2
|
|
|
|
|
3
|
|
|
from django.core.exceptions import ImproperlyConfigured |
|
4
|
|
|
|
|
5
|
|
|
from actstream.signals import action |
|
6
|
|
|
from actstream.registry import register, unregister |
|
7
|
|
|
from actstream.models import Action, actor_stream, model_stream |
|
8
|
|
|
from actstream.tests.base import render, ActivityBaseTestCase |
|
9
|
|
|
from actstream.settings import USE_JSONFIELD |
|
10
|
|
|
|
|
11
|
|
|
from testapp.models import Abstract, Unregistered |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
class TestAppTests(ActivityBaseTestCase): |
|
15
|
|
|
def setUp(self): |
|
16
|
|
|
super(TestAppTests, self).setUp() |
|
17
|
|
|
self.user = self.User.objects.create(username='test') |
|
18
|
|
|
action.send(self.user, verb='was created') |
|
19
|
|
|
|
|
20
|
|
|
def test_accessor(self): |
|
21
|
|
|
self.assertEqual(len(Action.objects.testfoo(self.user)), 1) |
|
22
|
|
|
self.assertEqual( |
|
23
|
|
|
len(Action.objects.testfoo(self.user, datetime(1970, 1, 1))), |
|
24
|
|
|
0 |
|
25
|
|
|
) |
|
26
|
|
|
|
|
27
|
|
|
def test_mystream(self): |
|
28
|
|
|
self.assertEqual( |
|
29
|
|
|
len(self.user.actor_actions.testbar('was created')), |
|
30
|
|
|
1 |
|
31
|
|
|
) |
|
32
|
|
|
self.assertEqual( |
|
33
|
|
|
len(self.user.action_object_actions.testbar('was created')), |
|
34
|
|
|
0 |
|
35
|
|
|
) |
|
36
|
|
|
|
|
37
|
|
|
def test_registration(self): |
|
38
|
|
|
instance = Unregistered.objects.create(name='fubar') |
|
39
|
|
|
self.assertRaises(ImproperlyConfigured, actor_stream, instance) |
|
40
|
|
|
register(Unregistered) |
|
41
|
|
|
self.assertEqual(actor_stream(instance).count(), 0) |
|
42
|
|
|
|
|
43
|
|
|
self.assertRaises(RuntimeError, model_stream, Abstract) |
|
44
|
|
|
self.assertRaises(ImproperlyConfigured, register, Abstract) |
|
45
|
|
|
unregister(Unregistered) |
|
46
|
|
|
|
|
47
|
|
|
def test_tag_custom_activity_stream(self): |
|
48
|
|
|
stream = self.user.actor_actions.testbar('was created') |
|
49
|
|
|
output = render('''{% activity_stream 'testbar' 'was created' %} |
|
50
|
|
|
{% for action in stream %} |
|
51
|
|
|
{{ action }} |
|
52
|
|
|
{% endfor %} |
|
53
|
|
|
''', user=self.user) |
|
54
|
|
|
self.assertAllIn([str(action) for action in stream], output) |
|
55
|
|
|
|
|
56
|
|
|
self.assertEqual( |
|
57
|
|
|
self.capture( |
|
58
|
|
|
'testapp_custom_feed', |
|
59
|
|
|
'was created')['totalItems'], |
|
60
|
|
|
1 |
|
61
|
|
|
) |
|
62
|
|
|
|
|
63
|
|
|
def test_customuser(self): |
|
64
|
|
|
from testapp.models import MyUser |
|
65
|
|
|
|
|
66
|
|
|
self.assertEqual(self.User, MyUser) |
|
67
|
|
|
self.assertEqual(self.user.get_full_name(), 'test') |
|
68
|
|
|
|
|
69
|
|
|
if USE_JSONFIELD: |
|
70
|
|
|
def test_jsonfield(self): |
|
71
|
|
|
action.send( |
|
72
|
|
|
self.user, verb='said', text='foobar', |
|
73
|
|
|
tags=['sayings'], |
|
74
|
|
|
more_data={'pk': self.user.pk} |
|
75
|
|
|
) |
|
76
|
|
|
newaction = Action.objects.filter(verb='said')[0] |
|
77
|
|
|
self.assertEqual(newaction.data['text'], 'foobar') |
|
78
|
|
|
self.assertEqual(newaction.data['tags'], ['sayings']) |
|
79
|
|
|
self.assertEqual(newaction.data['more_data'], {'pk': self.user.pk}) |
|
80
|
|
|
|