def test_topic_update_signal(self): """ POST, topic moved to category """ def topic_post_moderate_handler(sender, user, topic, action, **kwargs): self._moderate = [repr(user._wrapped), repr(topic), action] topic_post_moderate.connect(topic_post_moderate_handler) utils.login(self) self.user.is_moderator = True self.user.save() category = utils.create_category() topic = utils.create_topic(category=category, user=self.user) category2 = utils.create_category() form_data = {'title': 'foobar', 'category': category2.pk} response = self.client.post( reverse('spirit:topic-update', kwargs={ 'pk': topic.pk, }), form_data) self.assertSequenceEqual( self._moderate, [repr(self.user), repr(Topic.objects.get(pk=topic.pk)), MOVED])
def test_profile_likes_dont_show_removed_or_private(self): """ dont show private topics or removed """ category = utils.create_category() category_removed = utils.create_category(is_removed=True) subcategory = utils.create_category(parent=category_removed) subcategory_removed = utils.create_category(parent=category, is_removed=True) topic_a = utils.create_private_topic(user=self.user2) topic_b = utils.create_topic(category=category, is_removed=True) topic_c = utils.create_topic(category=category_removed) topic_d = utils.create_topic(category=subcategory) topic_e = utils.create_topic(category=subcategory_removed) comment_a = utils.create_comment(user=self.user2, topic=topic_a.topic) comment_b = utils.create_comment(user=self.user, topic=topic_b) comment_c = utils.create_comment(user=self.user, topic=topic_c) comment_d = utils.create_comment(user=self.user, topic=topic_d) comment_e = utils.create_comment(user=self.user, topic=topic_e) like_a = CommentLike.objects.create(user=self.user2, comment=comment_a) like_b = CommentLike.objects.create(user=self.user2, comment=comment_b) like_c = CommentLike.objects.create(user=self.user2, comment=comment_c) like_d = CommentLike.objects.create(user=self.user2, comment=comment_d) like_e = CommentLike.objects.create(user=self.user2, comment=comment_e) utils.login(self) response = self.client.get( reverse("spirit:profile-likes", kwargs={ 'pk': self.user2.pk, 'slug': self.user2.slug })) self.assertQuerysetEqual(response.context['comments'], [])
def test_category_invalid_parent(self): """ invalid parent """ # parent can not be a subcategory, only one level subcat is allowed subcategory = utils.create_category(parent=self.category) form_data = {"parent": subcategory.pk, } form = CategoryForm(data=form_data) self.assertEqual(form.is_valid(), False) self.assertNotIn('parent', form.cleaned_data) # parent can not be set to a category with childrens category_ = utils.create_category() form_data = {"parent": category_.pk, } form = CategoryForm(data=form_data, instance=self.category) self.assertEqual(form.is_valid(), False) self.assertNotIn('parent', form.cleaned_data) # parent can not be removed category_ = utils.create_category(is_removed=True) form_data = {"parent": category_.pk, } form = CategoryForm(data=form_data) self.assertEqual(form.is_valid(), False) self.assertNotIn('parent', form.cleaned_data) # parent can not be private category_ = utils.create_category(is_private=True) form_data = {"parent": category_.pk, } form = CategoryForm(data=form_data) self.assertEqual(form.is_valid(), False) self.assertNotIn('parent', form.cleaned_data)
def setUp(self): cache.clear() self.category_1 = utils.create_category(title="cat1") self.subcategory_1 = utils.create_subcategory(self.category_1) self.category_2 = utils.create_category(title="cat2") self.category_removed = utils.create_category(title="cat3", is_removed=True)
def test_profile_likes_dont_show_removed_or_private(self): """ dont show private topics or removed """ category = utils.create_category() category_removed = utils.create_category(is_removed=True) subcategory = utils.create_category(parent=category_removed) subcategory_removed = utils.create_category(parent=category, is_removed=True) topic_a = utils.create_private_topic(user=self.user2) topic_b = utils.create_topic(category=category, is_removed=True) topic_c = utils.create_topic(category=category_removed) topic_d = utils.create_topic(category=subcategory) topic_e = utils.create_topic(category=subcategory_removed) comment_a = utils.create_comment(user=self.user2, topic=topic_a.topic) comment_b = utils.create_comment(user=self.user, topic=topic_b) comment_c = utils.create_comment(user=self.user, topic=topic_c) comment_d = utils.create_comment(user=self.user, topic=topic_d) comment_e = utils.create_comment(user=self.user, topic=topic_e) like_a = CommentLike.objects.create(user=self.user2, comment=comment_a) like_b = CommentLike.objects.create(user=self.user2, comment=comment_b) like_c = CommentLike.objects.create(user=self.user2, comment=comment_c) like_d = CommentLike.objects.create(user=self.user2, comment=comment_d) like_e = CommentLike.objects.create(user=self.user2, comment=comment_e) utils.login(self) response = self.client.get(reverse("spirit:profile-likes", kwargs={'pk': self.user2.pk, 'slug': self.user2.slug})) self.assertQuerysetEqual(response.context['comments'], [])
def test_topic_notification_has_notifications_dont_count_topic_removed_or_no_access(self): """ dont show private topics if user has no access or is removed """ TopicNotification.objects.all().delete() category = utils.create_category() category_removed = utils.create_category(is_removed=True) subcategory = utils.create_category(parent=category_removed) subcategory_removed = utils.create_category(parent=category, is_removed=True) topic_a = utils.create_private_topic() topic_b = utils.create_topic(category=category, is_removed=True) topic_c = utils.create_topic(category=category_removed) topic_d = utils.create_topic(category=subcategory) topic_e = utils.create_topic(category=subcategory_removed) unread_a = TopicNotification.objects.create(user=self.user, topic=topic_a.topic, comment=self.comment, is_active=True, action=COMMENT) unread_b = TopicNotification.objects.create(user=self.user, topic=topic_b, comment=self.comment, is_active=True, action=COMMENT) unread_c = TopicNotification.objects.create(user=self.user, topic=topic_c, comment=self.comment, is_active=True, action=COMMENT) unread_d = TopicNotification.objects.create(user=self.user, topic=topic_d, comment=self.comment, is_active=True, action=COMMENT) unread_e = TopicNotification.objects.create(user=self.user, topic=topic_e, comment=self.comment, is_active=True, action=COMMENT) self.assertEqual(len(TopicNotification.objects.filter(user=self.user, is_active=True, is_read=False)), 5) self.assertFalse(has_topic_notifications(self.user))
def test_profile_topics_dont_show_removed_or_private(self): """ dont show private topics or removed """ Topic.objects.all().delete() category = utils.create_category() category_removed = utils.create_category(is_removed=True) subcategory = utils.create_category(parent=category_removed) subcategory_removed = utils.create_category(parent=category, is_removed=True) topic_a = utils.create_private_topic(user=self.user2) topic_b = utils.create_topic(category=category, user=self.user2, is_removed=True) topic_c = utils.create_topic(category=category_removed, user=self.user2) topic_d = utils.create_topic(category=subcategory, user=self.user2) topic_e = utils.create_topic(category=subcategory_removed, user=self.user2) utils.login(self) response = self.client.get( reverse("spirit:profile-topics", kwargs={ 'pk': self.user2.pk, 'slug': self.user2.slug })) self.assertQuerysetEqual(response.context['topics'], [])
def test_form(self): """ NestedModelChoiceField """ category = test_utils.create_category() category2 = test_utils.create_category() subcategory = test_utils.create_subcategory(category) field = NestedModelChoiceField(queryset=Category.objects.all(), related_name='category_set', parent_field='parent_id', label_field='title') self.assertSequenceEqual(list(field.choices), [(1, u'%s' % category.title), (3, u'--- %s' % subcategory.title), (2, u'%s' % category2.title)])
def test_topic_notification_has_notifications_dont_count_topic_removed_or_no_access( self): """ dont show private topics if user has no access or is removed """ TopicNotification.objects.all().delete() category = utils.create_category() category_removed = utils.create_category(is_removed=True) subcategory = utils.create_category(parent=category_removed) subcategory_removed = utils.create_category(parent=category, is_removed=True) topic_a = utils.create_private_topic() topic_b = utils.create_topic(category=category, is_removed=True) topic_c = utils.create_topic(category=category_removed) topic_d = utils.create_topic(category=subcategory) topic_e = utils.create_topic(category=subcategory_removed) unread_a = TopicNotification.objects.create(user=self.user, topic=topic_a.topic, comment=self.comment, is_active=True, action=COMMENT) unread_b = TopicNotification.objects.create(user=self.user, topic=topic_b, comment=self.comment, is_active=True, action=COMMENT) unread_c = TopicNotification.objects.create(user=self.user, topic=topic_c, comment=self.comment, is_active=True, action=COMMENT) unread_d = TopicNotification.objects.create(user=self.user, topic=topic_d, comment=self.comment, is_active=True, action=COMMENT) unread_e = TopicNotification.objects.create(user=self.user, topic=topic_e, comment=self.comment, is_active=True, action=COMMENT) self.assertEqual( len( TopicNotification.objects.filter(user=self.user, is_active=True, is_read=False)), 5) self.assertFalse(has_topic_notifications(self.user))
def test_nested_model_choise_form(self): """ NestedModelChoiceField """ category = test_utils.create_category() category2 = test_utils.create_category() subcategory = test_utils.create_subcategory(category) field = NestedModelChoiceField(queryset=Category.objects.all(), related_name='category_set', parent_field='parent_id', label_field='title') self.assertSequenceEqual(list(field.choices), [('', u'---------'), (1, u'%s' % category.title), (3, u'--- %s' % subcategory.title), (2, u'%s' % category2.title)])
def test_profile_topics_order(self): """ topics ordered by date """ Topic.objects.all().delete() category = utils.create_category() topic_a = utils.create_topic(category=category, user=self.user2) topic_b = utils.create_topic(category=category, user=self.user2) topic_c = utils.create_topic(category=category, user=self.user2) Topic.objects.filter(pk=topic_a.pk).update(date=timezone.now() - datetime.timedelta(days=10)) Topic.objects.filter(pk=topic_c.pk).update(date=timezone.now() - datetime.timedelta(days=5)) utils.login(self) response = self.client.get( reverse("spirit:profile-topics", kwargs={ 'pk': self.user2.pk, 'slug': self.user2.slug })) self.assertQuerysetEqual(response.context['topics'], map(repr, [topic_b, topic_c, topic_a]))
def setUp(self): cache.clear() self.user = utils.create_user() self.user2 = utils.create_user() self.category = utils.create_category() self.topic = utils.create_topic(self.category, user=self.user2) self.topic2 = utils.create_topic(self.category)
def test_topic_active_view_dont_show_private_or_removed(self): """ dont show private topics or removed """ category = utils.create_category() category_removed = utils.create_category(is_removed=True) subcategory = utils.create_category(parent=category_removed) subcategory_removed = utils.create_category(parent=category, is_removed=True) topic_a = utils.create_private_topic() topic_b = utils.create_topic(category=category, is_removed=True) topic_c = utils.create_topic(category=category_removed) topic_d = utils.create_topic(category=subcategory) topic_e = utils.create_topic(category=subcategory_removed) response = self.client.get(reverse('spirit:topic-active')) self.assertQuerysetEqual(response.context['topics'], [])
def test_topic_moderate_unpin(self): """ topic unpin """ def topic_post_moderate_handler(sender, user, topic, action, **kwargs): self._moderate = [repr(user._wrapped), repr(topic), action] topic_post_moderate.connect(topic_post_moderate_handler) utils.login(self) self.user.is_moderator = True self.user.save() category = utils.create_category() topic = utils.create_topic(category, is_pinned=True) form_data = {} response = self.client.post( reverse('spirit:topic-unpin', kwargs={ 'pk': topic.pk, }), form_data) expected_url = topic.get_absolute_url() self.assertRedirects(response, expected_url, status_code=302) self.assertFalse(Topic.objects.get(pk=topic.pk).is_pinned) self.assertEqual( self._moderate, [repr(self.user), repr(topic), UNPINNED])
def test_comment_publish_on_removed_topic_or_category(self): """ should not be able to create a comment """ # removed category Category.objects.all().update(is_removed=True) utils.login(self) form_data = {'comment': 'foobar', } response = self.client.post(reverse('spirit:comment-publish', kwargs={'topic_id': self.topic.pk, }), form_data) self.assertEqual(response.status_code, 404) # removed subcategory Category.objects.all().update(is_removed=False) subcategory = utils.create_category(parent=self.category, is_removed=True) topic2 = utils.create_topic(subcategory) utils.login(self) form_data = {'comment': 'foobar', } response = self.client.post(reverse('spirit:comment-publish', kwargs={'topic_id': topic2.pk, }), form_data) self.assertEqual(response.status_code, 404) # removed topic Category.objects.all().update(is_removed=False) Topic.objects.all().update(is_removed=True) utils.login(self) form_data = {'comment': 'foobar', } response = self.client.post(reverse('spirit:comment-publish', kwargs={'topic_id': self.topic.pk, }), form_data) self.assertEqual(response.status_code, 404)
def test_topic_publish_in_category(self): """ POST, create topic in category """ utils.login(self) category = utils.create_category() form_data = { 'comment': 'foo', 'title': 'foobar', 'category': category.pk } response = self.client.post( reverse('spirit:topic-publish', kwargs={ 'category_id': category.pk, }), form_data) topic = Topic.objects.last() expected_url = topic.get_absolute_url() self.assertRedirects(response, expected_url, status_code=302) # ratelimit response = self.client.post( reverse('spirit:topic-publish', kwargs={ 'category_id': category.pk, }), form_data) self.assertEqual(response.status_code, 200)
def test_topic_active_view_pinned(self): """ pinned topics. Only show pinned topics from uncategorized category, even if the category is removed """ category = utils.create_category() # show topic from regular category topic_a = utils.create_topic(category=category) # dont show pinned from regular category topic_b = utils.create_topic(category=category, is_pinned=True) uncat_category = Category.objects.get(pk=settings.ST_UNCATEGORIZED_CATEGORY_PK) # dont show pinned and removed topic_c = utils.create_topic(category=uncat_category, is_pinned=True, is_removed=True) # show topic from uncategorized category topic_d = utils.create_topic(category=uncat_category, is_pinned=True) # show pinned first Topic.objects.filter(pk=topic_d.pk).update(last_active=timezone.now() - datetime.timedelta(days=10)) response = self.client.get(reverse('spirit:topic-active')) self.assertQuerysetEqual(response.context['topics'], map(repr, [topic_d, topic_a, ])) # show topic from uncategorized category even if it is removed Category.objects.filter(pk=uncat_category.pk).update(is_removed=True) response = self.client.get(reverse('spirit:topic-active')) self.assertQuerysetEqual(response.context['topics'], map(repr, [topic_d, topic_a, ]))
def setUp(self): cache.clear() self.user = utils.create_user() self.user2 = utils.create_user() self.category = utils.create_category() self.topic = utils.create_topic(self.category) self.comment = utils.create_comment(topic=self.topic) # comment notification self.topic_notification = TopicNotification.objects.create( user=self.user, topic=self.topic, comment=self.comment, is_active=True, action=COMMENT) self.topic_notification2 = TopicNotification.objects.create( user=self.user2, topic=self.topic, comment=self.comment, is_active=True, action=COMMENT) # subscription to topic self.topic2 = utils.create_topic(self.category) self.topic_subscrption = TopicNotification.objects.create( user=self.user, topic=self.topic2, is_active=True)
def test_topic_detail_view_signals(self): """ send topic view signal """ def topic_viewed_handler(sender, request, topic, **kwargs): self._viewed = [ request, repr(topic), ] topic_viewed.connect(topic_viewed_handler) utils.login(self) category = utils.create_category() topic = utils.create_topic(category=category, user=self.user) response = self.client.get( reverse('spirit:topic-detail', kwargs={ 'pk': topic.pk, 'slug': topic.slug })) self.assertEqual(response.status_code, 200) self.assertSequenceEqual(self._viewed, [response.context['request'], repr(topic)])
def setUp(self): cache.clear() self.user = utils.create_user() self.category = utils.create_category() self.topic = utils.create_topic(category=self.category, user=self.user) for _ in xrange(settings.ST_COMMENTS_PER_PAGE * 4): # 4 pages utils.create_comment(user=self.user, topic=self.topic)
def setUp(self): cache.clear() self.user = utils.create_user() self.category = utils.create_category() self.topic = utils.create_topic(category=self.category, user=self.user) utils.create_comment(topic=self.topic) utils.create_comment(topic=self.topic) utils.create_comment(topic=self.topic)
def test_category_list(self): """ Categories, excludes Topic Private and subcats """ subcat = utils.create_category(parent=self.category) categories = Category.objects.filter(is_private=False, parent=None) utils.login(self) response = self.client.get(reverse('spirit:admin-category-list')) self.assertQuerysetEqual(response.context['categories'], map(repr, categories))
def test_topic_update(self): """ create update """ category = utils.create_category() topic = utils.create_topic(category) form_data = {'title': 'foobar', } form = TopicForm(self.user, data=form_data, instance=topic) self.assertEqual(form.is_valid(), True)
def setUp(self): cache.clear() self.user = utils.create_user() self.topic = utils.create_topic(utils.create_category()) for _ in xrange(300): utils.create_comment(user=self.user, topic=self.topic) self.queryset = Comment.objects.all().order_by("-pk")
def setUp(self): cache.clear() self.user = utils.create_user() self.topic = utils.create_topic(utils.create_category()) for _ in xrange(300): utils.create_comment(user=self.user, topic=self.topic) self.queryset = Comment.objects.all()
def test_topic_detail_view(self): """ should display topic """ utils.login(self) category = utils.create_category() topic = utils.create_topic(category=category) response = self.client.get(reverse('spirit:topic-detail', kwargs={'pk': topic.pk, })) self.assertEqual(response.context['topic'], topic)
def test_index_queryset_excludes_private_topics(self): """ index_queryset should exclude private topics """ private = utils.create_private_topic() self.assertEqual(len(TopicIndex().index_queryset()), 0) category = utils.create_category() topic = utils.create_topic(category) self.assertEqual(len(TopicIndex().index_queryset()), 1)
def test_topic_detail_view_invalid_slug(self): """ invalid slug """ utils.login(self) category = utils.create_category() topic = utils.create_topic(category=category) response = self.client.get(reverse('spirit:topic-detail', kwargs={'pk': topic.pk, 'slug': 'bar'})) self.assertRedirects(response, topic.get_absolute_url(), status_code=301)
def test_topic_update_signal(self): """ POST, topic moved to category """ def topic_post_moderate_handler(sender, user, topic, action, **kwargs): self._moderate = [repr(user._wrapped), repr(topic), action] topic_post_moderate.connect(topic_post_moderate_handler) utils.login(self) self.user.is_moderator = True self.user.save() category = utils.create_category() topic = utils.create_topic(category=category, user=self.user) category2 = utils.create_category() form_data = {'title': 'foobar', 'category': category2.pk} response = self.client.post(reverse('spirit:topic-update', kwargs={'pk': topic.pk, }), form_data) self.assertSequenceEqual(self._moderate, [repr(self.user), repr(Topic.objects.get(pk=topic.pk)), MOVED])
def test_topic_publish(self): """ create topic """ category = utils.create_category() subcategory = utils.create_subcategory(category) form_data = {'comment': 'foo', 'title': 'foobar', 'category': subcategory.pk} form = TopicForm(self.user, data=form_data) self.assertEqual(form.is_valid(), True)
def setUp(self): cache.clear() self.user = utils.create_user() self.category = utils.create_category() self.topic = utils.create_topic(self.category) self.comment = utils.create_comment(topic=self.topic) self.topic_notification = TopicNotification.objects.create(user=self.user, topic=self.topic, comment=self.comment, is_active=True, action=COMMENT)
def test_topic_update(self): """ POST, update topic """ utils.login(self) category = utils.create_category() topic = utils.create_topic(category=category, user=self.user) form_data = {'title': 'foobar', } response = self.client.post(reverse('spirit:topic-update', kwargs={'pk': topic.pk, }), form_data) self.assertRedirects(response, topic.get_absolute_url(), status_code=302)
def setUp(self): cache.clear() self.user = utils.create_user() self.user2 = utils.create_user() self.category = utils.create_category() self.topic = utils.create_topic(self.category) self.topic2 = utils.create_topic(self.category, user=self.user) self.topic_unread = TopicUnread.objects.create(user=self.user, topic=self.topic) self.topic_unread2 = TopicUnread.objects.create(user=self.user, topic=self.topic2) self.topic_unread3 = TopicUnread.objects.create(user=self.user2, topic=self.topic)
def test_profile_topics_dont_show_removed_or_private(self): """ dont show private topics or removed """ Topic.objects.all().delete() category = utils.create_category() category_removed = utils.create_category(is_removed=True) subcategory = utils.create_category(parent=category_removed) subcategory_removed = utils.create_category(parent=category, is_removed=True) topic_a = utils.create_private_topic(user=self.user2) topic_b = utils.create_topic(category=category, user=self.user2, is_removed=True) topic_c = utils.create_topic(category=category_removed, user=self.user2) topic_d = utils.create_topic(category=subcategory, user=self.user2) topic_e = utils.create_topic(category=subcategory_removed, user=self.user2) utils.login(self) response = self.client.get(reverse("spirit:profile-topics", kwargs={'pk': self.user2.pk, 'slug': self.user2.slug})) self.assertQuerysetEqual(response.context['topics'], [])
def test_topic_update_invalid_user(self): """ POST, update topic """ utils.login(self) category = utils.create_category() topic = utils.create_topic(category=category) form_data = {'title': 'foobar', } response = self.client.post(reverse('spirit:topic-update', kwargs={'pk': topic.pk, }), form_data) self.assertEqual(response.status_code, 404)
def test_private_join_invalid_regular_topic(self): """ Only topics from the category private can be rejoined """ category = utils.create_category() topic = utils.create_topic(category, user=self.user) utils.login(self) form_data = {} response = self.client.post(reverse("spirit:private-join", kwargs={"topic_id": topic.pk}), form_data) self.assertEqual(response.status_code, 404)
def test_indexing_excludes_private_topics(self): """ rebuild_index command should exclude private topics """ private = utils.create_private_topic() category = utils.create_category() topic = utils.create_topic(category) call_command("rebuild_index", interactive=False) sqs = SearchQuerySet().models(Topic) self.assertQuerysetEqual([s.object for s in sqs], map(repr, [topic, ]))
def test_topic_publish_invalid_subcategory(self): """ invalid subcategory """ category = utils.create_category() subcategory = utils.create_subcategory(category, is_closed=True) form_data = {'comment': 'foo', 'title': 'foobar', 'category': subcategory.pk} form = TopicForm(self.user, data=form_data) self.assertEqual(form.is_valid(), False) self.assertNotIn('category', form.cleaned_data)
def test_notification(self): """ update notification """ category = utils.create_category() topic = utils.create_topic(category) notification = TopicNotification.objects.create(user=self.user, topic=topic, is_active=True, action=COMMENT) form_data = {'is_active': True, } form = NotificationForm(data=form_data, instance=notification) self.assertEqual(form.is_valid(), True)
def test_topic_publish_long_title(self): """ POST, create topic with long title """ utils.login(self) category = utils.create_category() title = "a" * 75 form_data = {'comment': 'foo', 'title': title, 'category': category.pk} response = self.client.post(reverse('spirit:topic-publish'), form_data) self.assertEqual(response.status_code, 302) self.assertEqual(len(Topic.objects.all()), 1) self.assertEqual(Topic.objects.last().slug, title[:50])
def test_private_join_invalid_regular_topic(self): """ Only topics from the category private can be rejoined """ category = utils.create_category() topic = utils.create_topic(category, user=self.user) utils.login(self) form_data = {} response = self.client.post(reverse('spirit:private-join', kwargs={'topic_id': topic.pk, }), form_data) self.assertEqual(response.status_code, 404)
def setUp(self): # TODO: simple backend wont work on django +1.6 coz of a bug on haystack 2.1 #self.connections = haystack.connections #haystack.connections = haystack.loading.ConnectionHandler(HAYSTACK_TEST) cache.clear() self.user = utils.create_user() self.category = utils.create_category() self.topic = utils.create_topic(category=self.category, user=self.user, title="spirit search test") self.topic2 = utils.create_topic(category=self.category, user=self.user, title="foo") call_command("rebuild_index", interactive=False)
def test_topic_notification_list_dont_show_topic_removed_or_no_access(self): """ dont show private topics if user has no access or is removed """ TopicNotification.objects.all().delete() category = utils.create_category() category_removed = utils.create_category(is_removed=True) subcategory = utils.create_category(parent=category_removed) subcategory_removed = utils.create_category(parent=category, is_removed=True) topic_a = utils.create_private_topic() topic_b = utils.create_topic(category=category, is_removed=True) topic_c = utils.create_topic(category=category_removed) topic_d = utils.create_topic(category=subcategory) topic_e = utils.create_topic(category=subcategory_removed) unread_a = TopicNotification.objects.create(user=self.user, topic=topic_a.topic, comment=self.comment, is_active=True, action=COMMENT) unread_b = TopicNotification.objects.create(user=self.user, topic=topic_b, comment=self.comment, is_active=True, action=COMMENT) unread_c = TopicNotification.objects.create(user=self.user, topic=topic_c, comment=self.comment, is_active=True, action=COMMENT) unread_d = TopicNotification.objects.create(user=self.user, topic=topic_d, comment=self.comment, is_active=True, action=COMMENT) unread_e = TopicNotification.objects.create(user=self.user, topic=topic_e, comment=self.comment, is_active=True, action=COMMENT) self.assertEqual(len(TopicNotification.objects.filter(user=self.user, is_active=True, is_read=False)), 5) utils.login(self) response = self.client.get(reverse('spirit:topic-notification-list')) self.assertQuerysetEqual(response.context['notifications'], []) # list unread should behave the same response = self.client.get(reverse('spirit:topic-notification-list-unread')) self.assertQuerysetEqual(response.context['page'], []) # ajax list should behave the same response = self.client.get(reverse('spirit:topic-notification-ajax'), HTTP_X_REQUESTED_WITH='XMLHttpRequest') res = json.loads(response.content) self.assertEqual(len(res['n']), 0)
def test_topic_publish_in_subcategory(self): """ POST, create topic in subcategory """ utils.login(self) category = utils.create_category() subcategory = utils.create_subcategory(category) form_data = {'comment': 'foo', 'title': 'foobar', 'category': subcategory.pk} response = self.client.post(reverse('spirit:topic-publish', kwargs={'category_id': subcategory.pk, }), form_data) topic = Topic.objects.last() expected_url = topic.get_absolute_url() self.assertRedirects(response, expected_url, status_code=302)