|
1 | 1 | from django import template |
2 | | -from django.contrib.auth.models import User |
| 2 | +from django.conf import settings |
| 3 | +from django.contrib.auth.models import User, Group |
3 | 4 | from django.test import TestCase |
4 | 5 | from stream import signals |
5 | 6 | from stream.models import Action |
6 | 7 | from stream import utils |
7 | 8 |
|
| 9 | + |
| 10 | +utils.register_actor([User, Group]) |
| 11 | +utils.register_target([User, Group]) |
| 12 | +utils.register_action_object([User, Group]) |
| 13 | + |
| 14 | + |
8 | 15 | class TestStream(TestCase): |
9 | 16 | def setUp(self): |
10 | 17 | self.lennon = User.objects.create(username='lennon') |
@@ -64,7 +71,7 @@ def test_getters_setters(self): |
64 | 71 | action.action_object = self.lennon |
65 | 72 | action.save() |
66 | 73 |
|
67 | | - action = Action.objects.get(id=1) |
| 74 | + action = Action.objects.get(id=action.id) |
68 | 75 |
|
69 | 76 | self.assertEqual(self.morrison, action.actor) |
70 | 77 | self.assertEqual(self.hendrix, action.target) |
@@ -96,3 +103,36 @@ def test_template_tag(self): |
96 | 103 | ctx = template.Context({'action': action}) |
97 | 104 |
|
98 | 105 | self.assertEqual("lennon did Stream Item hendrix.", tpl.render(ctx)) |
| 106 | + |
| 107 | + def test_multi_lookups(self): |
| 108 | + def target_result(): |
| 109 | + return len(Action.objects.get_for_targets([self.lennon, self.hendrix, self.morrison])) |
| 110 | + def actor_result(): |
| 111 | + return len(Action.objects.get_for_actors([self.lennon, self.hendrix, self.morrison])) |
| 112 | + |
| 113 | + self.assertEqual(0, target_result()) |
| 114 | + self.assertEqual(0, actor_result()) |
| 115 | + |
| 116 | + utils.action.send(self.lennon, 'follow', self.hendrix) |
| 117 | + self.assertEqual(1, target_result()) |
| 118 | + self.assertEqual(1, actor_result()) |
| 119 | + |
| 120 | + utils.action.send(self.lennon, 'follow', self.morrison) |
| 121 | + self.assertEqual(2, target_result()) |
| 122 | + self.assertEqual(2, actor_result()) |
| 123 | + |
| 124 | + utils.action.send(self.hendrix, 'follow', self.morrison) |
| 125 | + self.assertEqual(3, target_result()) |
| 126 | + self.assertEqual(3, actor_result()) |
| 127 | + |
| 128 | + utils.action.send(self.hendrix, 'follow', self.lennon) |
| 129 | + self.assertEqual(4, target_result()) |
| 130 | + self.assertEqual(4, actor_result()) |
| 131 | + |
| 132 | + self.assertEqual(2, Action.objects.get_for_actors([self.lennon]).count()) |
| 133 | + self.assertEqual(2, Action.objects.get_for_actors([self.hendrix]).count()) |
| 134 | + self.assertEqual(0, Action.objects.get_for_actors([self.morrison]).count()) |
| 135 | + |
| 136 | + self.assertEqual(1, Action.objects.get_for_targets([self.hendrix]).count()) |
| 137 | + self.assertEqual(1, Action.objects.get_for_targets([self.lennon]).count()) |
| 138 | + self.assertEqual(2, Action.objects.get_for_targets([self.morrison]).count()) |
0 commit comments