def test_autowatch_reply(self, get_current): """Replying to a thread creates a watch.""" get_current.return_value.domain = "testserver" u = UserFactory() t1 = ThreadFactory() t2 = ThreadFactory() assert not NewPostEvent.is_notifying(u, t1) assert not NewPostEvent.is_notifying(u, t2) self.client.login(username=u.username, password="******") # If the poster has the forums_watch_after_reply setting set to True, # they will start watching threads they reply to. s = Setting.objects.create(user=u, name="forums_watch_after_reply", value="True") data = {"content": "some content"} post(self.client, "forums.reply", data, args=[t1.forum.slug, t1.pk]) assert NewPostEvent.is_notifying(u, t1) # Setting forums_watch_after_reply back to False, now they shouldn't # start watching threads they reply to. s.value = "False" s.save() post(self.client, "forums.reply", data, args=[t2.forum.slug, t2.pk]) assert not NewPostEvent.is_notifying(u, t2)
def test_autowatch_reply(self, get_current): """Replying to a thread creates a watch.""" get_current.return_value.domain = 'testserver' u = user(save=True) t1 = thread(save=True) t2 = thread(save=True) assert not NewPostEvent.is_notifying(u, t1) assert not NewPostEvent.is_notifying(u, t2) self.client.login(username=u.username, password='******') # If the poster has the forums_watch_after_reply setting set to True, # they will start watching threads they reply to. s = Setting.objects.create(user=u, name='forums_watch_after_reply', value='True') data = {'content': 'some content'} post(self.client, 'forums.reply', data, args=[t1.forum.slug, t1.pk]) assert NewPostEvent.is_notifying(u, t1) # Setting forums_watch_after_reply back to False, now they shouldn't # start watching threads they reply to. s.value = 'False' s.save() post(self.client, 'forums.reply', data, args=[t2.forum.slug, t2.pk]) assert not NewPostEvent.is_notifying(u, t2)
def test_autowatch_reply(self, get_current): """Replying to a thread creates a watch.""" get_current.return_value.domain = 'testserver' u = user(save=True) t1 = thread(save=True) t2 = thread(save=True) assert not NewPostEvent.is_notifying(u, t1) assert not NewPostEvent.is_notifying(u, t2) self.client.login(username=u.username, password='******') # If the poster has the forums_watch_after_reply setting set to True, # they will start watching threads they reply to. s = Setting.objects.create(user=u, name='forums_watch_after_reply', value='True') data = {'content': 'some content'} post(self.client, 'forums.reply', data, args=[t1.forum.slug, t1.pk]) assert NewPostEvent.is_notifying(u, t1) # Setting forums_watch_after_reply back to False, now they shouldn't # start watching threads they reply to. s.value = 'False' s.save() post(self.client, 'forums.reply', data, args=[t2.forum.slug, t2.pk]) assert not NewPostEvent.is_notifying(u, t2)
def _toggle_watch_thread_as(self, thread, user, turn_on=True): """Watch a thread and return it.""" self.client.login(username=user.username, password="******") watch = "yes" if turn_on else "no" post(self.client, "forums.watch_thread", {"watch": watch}, args=[thread.forum.slug, thread.id]) # Watch exists or not, depending on watch. if turn_on: assert NewPostEvent.is_notifying(user, thread), "NewPostEvent should be notifying." else: assert not NewPostEvent.is_notifying(user, thread), "NewPostEvent should not be notifying."
def _toggle_watch_thread_as(self, thread, user, turn_on=True): """Watch a thread and return it.""" self.client.login(username=user.username, password='******') watch = 'yes' if turn_on else 'no' post(self.client, 'forums.watch_thread', {'watch': watch}, args=[thread.forum.slug, thread.id]) # Watch exists or not, depending on watch. if turn_on: assert NewPostEvent.is_notifying(user, thread), ( 'NewPostEvent should be notifying.') else: assert not NewPostEvent.is_notifying(user, thread), ( 'NewPostEvent should not be notifying.')
def _toggle_watch_thread_as(self, thread, user, turn_on=True): """Watch a thread and return it.""" self.client.login(username=user.username, password='******') watch = 'yes' if turn_on else 'no' post(self.client, 'forums.watch_thread', {'watch': watch}, args=[thread.forum.slug, thread.id]) # Watch exists or not, depending on watch. if turn_on: assert NewPostEvent.is_notifying(user, thread), ( 'NewPostEvent should be notifying.') else: assert not NewPostEvent.is_notifying(user, thread), ( 'NewPostEvent should not be notifying.')
def test_watch_thread(self): """Watch then unwatch a thread.""" t = ThreadFactory() u = UserFactory() self.client.login(username=u.username, password='******') post(self.client, 'forums.watch_thread', {'watch': 'yes'}, args=[t.forum.slug, t.id]) assert NewPostEvent.is_notifying(u, t) # NewThreadEvent is not notifying. assert not NewThreadEvent.is_notifying(u, t.forum) post(self.client, 'forums.watch_thread', {'watch': 'no'}, args=[t.forum.slug, t.id]) assert not NewPostEvent.is_notifying(u, t)
def test_watch_thread(self): """Watch then unwatch a thread.""" t = ThreadFactory() u = UserFactory() self.client.login(username=u.username, password='******') post(self.client, 'forums.watch_thread', {'watch': 'yes'}, args=[t.forum.slug, t.id]) assert NewPostEvent.is_notifying(u, t) # NewThreadEvent is not notifying. assert not NewThreadEvent.is_notifying(u, t.forum) post(self.client, 'forums.watch_thread', {'watch': 'no'}, args=[t.forum.slug, t.id]) assert not NewPostEvent.is_notifying(u, t)
def posts(request, forum_slug, thread_id, form=None, post_preview=None, is_reply=False): """View all the posts in a thread.""" thread = get_object_or_404(Thread, pk=thread_id) forum = thread.forum if forum.slug != forum_slug and not is_reply: new_forum = get_object_or_404(Forum, slug=forum_slug) if new_forum.allows_viewing_by(request.user): return HttpResponseRedirect(thread.get_absolute_url()) raise Http404 # User has no right to view destination forum. elif forum.slug != forum_slug: raise Http404 if not forum.allows_viewing_by(request.user): raise Http404 posts_ = thread.post_set.all() count = posts_.count() if count: last_post = posts_[count - 1] else: last_post = None posts_ = posts_.select_related('author', 'updated_by') posts_ = posts_.extra( select={ 'author_post_count': 'SELECT COUNT(*) FROM forums_post WHERE ' 'forums_post.author_id = auth_user.id' }) posts_ = paginate(request, posts_, constants.POSTS_PER_PAGE, count=count) if not form: form = ReplyForm() feed_urls = ((reverse('forums.posts.feed', kwargs={ 'forum_slug': forum_slug, 'thread_id': thread_id }), PostsFeed().title(thread)), ) is_watching_thread = (request.user.is_authenticated() and NewPostEvent.is_notifying(request.user, thread)) return render( request, 'forums/posts.html', { 'forum': forum, 'thread': thread, 'posts': posts_, 'form': form, 'count': count, 'last_post': last_post, 'post_preview': post_preview, 'is_watching_thread': is_watching_thread, 'feeds': feed_urls, 'forums': Forum.objects.all() })
def _toggle_watch_thread_as(self, thread, user, turn_on=True): """Watch a thread and return it.""" self.client.login(username=user.username, password="******") watch = "yes" if turn_on else "no" post( self.client, "forums.watch_thread", {"watch": watch}, args=[thread.forum.slug, thread.id], ) # Watch exists or not, depending on watch. if turn_on: assert NewPostEvent.is_notifying( user, thread), "NewPostEvent should be notifying." else: assert not NewPostEvent.is_notifying( user, thread), "NewPostEvent should not be notifying."
def test_watch_thread(self): """Watch then unwatch a thread.""" t = ThreadFactory() u = UserFactory() self.client.login(username=u.username, password="******") post(self.client, "forums.watch_thread", {"watch": "yes"}, args=[t.forum.slug, t.id]) assert NewPostEvent.is_notifying(u, t) # NewThreadEvent is not notifying. assert not NewThreadEvent.is_notifying(u, t.forum) post(self.client, "forums.watch_thread", {"watch": "no"}, args=[t.forum.slug, t.id]) assert not NewPostEvent.is_notifying(u, t)
def test_autowatch_new_thread(self, get_current): """Creating a new thread should email responses""" get_current.return_value.domain = "testserver" f = forum(save=True) u = user(save=True) self.client.login(username=u.username, password="******") s = Setting.objects.create(user=u, name="forums_watch_new_thread", value="False") data = {"title": "a title", "content": "a post"} post(self.client, "forums.new_thread", data, args=[f.slug]) t1 = Thread.objects.all().order_by("-id")[0] assert not NewPostEvent.is_notifying(u, t1), "NewPostEvent should not be notifying." s.value = "True" s.save() post(self.client, "forums.new_thread", data, args=[f.slug]) t2 = Thread.uncached.all().order_by("-id")[0] assert NewPostEvent.is_notifying(u, t2), "NewPostEvent should be notifying."
def test_autowatch_new_thread(self, get_current): """Creating a new thread should email responses""" get_current.return_value.domain = 'testserver' f = forum(save=True) u = user(save=True) self.client.login(username=u.username, password='******') s = Setting.objects.create(user=u, name='forums_watch_new_thread', value='False') data = {'title': 'a title', 'content': 'a post'} post(self.client, 'forums.new_thread', data, args=[f.slug]) t1 = Thread.objects.all().order_by('-id')[0] assert not NewPostEvent.is_notifying(u, t1), ( 'NewPostEvent should not be notifying.') s.value = 'True' s.save() post(self.client, 'forums.new_thread', data, args=[f.slug]) t2 = Thread.objects.all().order_by('-id')[0] assert NewPostEvent.is_notifying(u, t2), ( 'NewPostEvent should be notifying.')
def test_autowatch_new_thread(self, get_current): """Creating a new thread should email responses""" get_current.return_value.domain = 'testserver' f = forum(save=True) u = user(save=True) self.client.login(username=u.username, password='******') s = Setting.objects.create(user=u, name='forums_watch_new_thread', value='False') data = {'title': 'a title', 'content': 'a post'} post(self.client, 'forums.new_thread', data, args=[f.slug]) t1 = Thread.objects.all().order_by('-id')[0] assert not NewPostEvent.is_notifying(u, t1), ( 'NewPostEvent should not be notifying.') s.value = 'True' s.save() post(self.client, 'forums.new_thread', data, args=[f.slug]) t2 = Thread.uncached.all().order_by('-id')[0] assert NewPostEvent.is_notifying(u, t2), ( 'NewPostEvent should be notifying.')
def test_autowatch_new_thread(self, get_current): """Creating a new thread should email responses""" get_current.return_value.domain = "testserver" f = ForumFactory() u = UserFactory() self.client.login(username=u.username, password="******") s = Setting.objects.create(user=u, name="forums_watch_new_thread", value="False") data = {"title": "a title", "content": "a post"} post(self.client, "forums.new_thread", data, args=[f.slug]) t1 = Thread.objects.all().order_by("-id")[0] assert not NewPostEvent.is_notifying( u, t1), "NewPostEvent should not be notifying." s.value = "True" s.save() post(self.client, "forums.new_thread", data, args=[f.slug]) t2 = Thread.objects.all().order_by("-id")[0] assert NewPostEvent.is_notifying( u, t2), "NewPostEvent should be notifying."
def posts(request, forum_slug, thread_id, form=None, post_preview=None, is_reply=False): """View all the posts in a thread.""" thread = get_object_or_404(Thread, pk=thread_id) forum = thread.forum if forum.slug != forum_slug and not is_reply: new_forum = get_object_or_404(Forum, slug=forum_slug) if new_forum.allows_viewing_by(request.user): return HttpResponseRedirect(thread.get_absolute_url()) raise Http404 # User has no right to view destination forum. elif forum.slug != forum_slug: raise Http404 if not forum.allows_viewing_by(request.user): raise Http404 posts_ = thread.post_set.all() count = posts_.count() if count: last_post = posts_[count - 1] else: last_post = None posts_ = posts_.select_related('author', 'updated_by') posts_ = posts_.extra( select={'author_post_count': 'SELECT COUNT(*) FROM forums_post WHERE ' 'forums_post.author_id = auth_user.id'}) posts_ = paginate(request, posts_, constants.POSTS_PER_PAGE, count=count) if not form: form = ReplyForm() feed_urls = ((reverse('forums.posts.feed', kwargs={'forum_slug': forum_slug, 'thread_id': thread_id}), PostsFeed().title(thread)),) is_watching_thread = (request.user.is_authenticated() and NewPostEvent.is_notifying(request.user, thread)) return render(request, 'forums/posts.html', { 'forum': forum, 'thread': thread, 'posts': posts_, 'form': form, 'count': count, 'last_post': last_post, 'post_preview': post_preview, 'is_watching_thread': is_watching_thread, 'feeds': feed_urls, 'forums': Forum.objects.all()})
def test_watch_forum(self): """Watch then unwatch a forum.""" f = ForumFactory() PostFactory(thread__forum=f) u = UserFactory() self.client.login(username=u.username, password="******") post(self.client, "forums.watch_forum", {"watch": "yes"}, args=[f.slug]) assert NewThreadEvent.is_notifying(u, f) # NewPostEvent is not notifying. assert not NewPostEvent.is_notifying(u, f.last_post) post(self.client, "forums.watch_forum", {"watch": "no"}, args=[f.slug]) assert not NewThreadEvent.is_notifying(u, f)
def test_watch_forum(self): """Watch then unwatch a forum.""" f = ForumFactory() PostFactory(thread__forum=f) u = UserFactory() self.client.login(username=u.username, password='******') post(self.client, 'forums.watch_forum', {'watch': 'yes'}, args=[f.slug]) assert NewThreadEvent.is_notifying(u, f) # NewPostEvent is not notifying. assert not NewPostEvent.is_notifying(u, f.last_post) post(self.client, 'forums.watch_forum', {'watch': 'no'}, args=[f.slug]) assert not NewThreadEvent.is_notifying(u, f)
def test_watch_forum(self): """Watch then unwatch a forum.""" f = forum(save=True) forum_post(thread=thread(forum=f, save=True), save=True) u = user(save=True) self.client.login(username=u.username, password='******') post(self.client, 'forums.watch_forum', {'watch': 'yes'}, args=[f.slug]) assert NewThreadEvent.is_notifying(u, f) # NewPostEvent is not notifying. assert not NewPostEvent.is_notifying(u, f.last_post) post(self.client, 'forums.watch_forum', {'watch': 'no'}, args=[f.slug]) assert not NewThreadEvent.is_notifying(u, f)
def test_watch_forum(self): """Watch then unwatch a forum.""" f = ForumFactory() PostFactory(thread__forum=f) u = UserFactory() self.client.login(username=u.username, password='******') post(self.client, 'forums.watch_forum', {'watch': 'yes'}, args=[f.slug]) assert NewThreadEvent.is_notifying(u, f) # NewPostEvent is not notifying. assert not NewPostEvent.is_notifying(u, f.last_post) post(self.client, 'forums.watch_forum', {'watch': 'no'}, args=[f.slug]) assert not NewThreadEvent.is_notifying(u, f)
def test_watch_forum(self): """Watch then unwatch a forum.""" f = forum(save=True) forum_post(thread=thread(forum=f, save=True), save=True) u = user(save=True) self.client.login(username=u.username, password='******') post(self.client, 'forums.watch_forum', {'watch': 'yes'}, args=[f.slug]) assert NewThreadEvent.is_notifying(u, f) # NewPostEvent is not notifying. assert not NewPostEvent.is_notifying(u, f.last_post) post(self.client, 'forums.watch_forum', {'watch': 'no'}, args=[f.slug]) assert not NewThreadEvent.is_notifying(u, f)
def posts(request, forum_slug, thread_id, form=None, post_preview=None, is_reply=False): """View all the posts in a thread.""" thread = get_object_or_404(Thread, pk=thread_id) forum = thread.forum if forum.slug != forum_slug and not is_reply: new_forum = get_object_or_404(Forum, slug=forum_slug) if new_forum.allows_viewing_by(request.user): return HttpResponseRedirect(thread.get_absolute_url()) raise Http404 # User has no right to view destination forum. elif forum.slug != forum_slug: raise Http404 if not forum.allows_viewing_by(request.user): raise Http404 posts_ = thread.post_set.all() count = posts_.count() if count: last_post = posts_[count - 1] else: last_post = None posts_ = posts_.select_related("author", "updated_by") posts_ = posts_.extra( select={ "author_post_count": "SELECT COUNT(*) FROM forums_post WHERE " "forums_post.author_id = auth_user.id" }) posts_ = paginate(request, posts_, constants.POSTS_PER_PAGE, count=count) if not form: form = ReplyForm() feed_urls = (( reverse("forums.posts.feed", kwargs={ "forum_slug": forum_slug, "thread_id": thread_id }), PostsFeed().title(thread), ), ) is_watching_thread = request.user.is_authenticated and NewPostEvent.is_notifying( request.user, thread) return render( request, "forums/posts.html", { "forum": forum, "thread": thread, "posts": posts_, "form": form, "count": count, "last_post": last_post, "post_preview": post_preview, "is_watching_thread": is_watching_thread, "feeds": feed_urls, "forums": Forum.objects.all(), }, )
def test_delete_removes_watches(self): t = thread(save=True) NewPostEvent.notify('*****@*****.**', t) assert NewPostEvent.is_notifying('*****@*****.**', t) t.delete() assert not NewPostEvent.is_notifying('*****@*****.**', t)
def test_delete_removes_watches(self): t = ThreadFactory() NewPostEvent.notify('*****@*****.**', t) assert NewPostEvent.is_notifying('*****@*****.**', t) t.delete() assert not NewPostEvent.is_notifying('*****@*****.**', t)
def test_delete_removes_watches(self): t = ThreadFactory() NewPostEvent.notify('*****@*****.**', t) assert NewPostEvent.is_notifying('*****@*****.**', t) t.delete() assert not NewPostEvent.is_notifying('*****@*****.**', t)
def test_delete_removes_watches(self): t = thread(save=True) NewPostEvent.notify('*****@*****.**', t) assert NewPostEvent.is_notifying('*****@*****.**', t) t.delete() assert not NewPostEvent.is_notifying('*****@*****.**', t)