def test_is_following(self): """Test the is-following query""" p = self.jacob.get_profile() loggedin = self.client.login(username='******', password='******') self.assertTrue(loggedin) follow(self.jacob, self.bill_1) response = self.client.post(reverse('user-is-following'), { 'id': self.bill_1.id, 'what': 'bill' }) self.assertEquals(response.status_code, 200) res_obj = json.loads(response.content) self.assertTrue(res_obj['watched']) unfollow(self.jacob, self.bill_1) response = self.client.post(reverse('user-is-following'), { 'id': self.bill_1.id, 'what': 'bill' }) self.assertEquals(response.status_code, 200) res_obj = json.loads(response.content) self.assertFalse(res_obj['watched']) self.client.logout()
def downvote_question(request, q_id): if request.method == "POST": q = get_object_or_404(Question, id=q_id) user = request.user if q.author == user: return HttpResponseForbidden(_("Cannot downvote your own question")) elif not user.upvotes.filter(question=q): return HttpResponseForbidden(_("You already downvoted this question")) else: QuestionUpvote.objects.filter(question=q, user=user).delete() new_count = change_rating(q, -1) unfollow(request.user, q) # TODO: publish_downvote_to_facebook.delay(upvote) return HttpResponse(new_count) else: return HttpResponseForbidden(_("Use POST to upvote a question"))
def downvote_question(request, q_id): if request.method == "POST": q = get_object_or_404(Question, id=q_id) user = request.user if q.author == user: return HttpResponseForbidden( _("Cannot downvote your own question")) elif not user.upvotes.filter(question=q): return HttpResponseForbidden( _("You already downvoted this question")) else: QuestionUpvote.objects.filter(question=q, user=user).delete() new_count = change_rating(q, -1) unfollow(request.user, q) # TODO: publish_downvote_to_facebook.delay(upvote) return HttpResponse(new_count) else: return HttpResponseForbidden(_("Use POST to upvote a question"))
def follow_agendas(request): if not request.user.is_authenticated(): return HttpResponseForbidden(reverse('login')) if request.method == 'POST': unwatch_id = request.POST.get('unwatch', None) if unwatch_id: agenda = get_object_or_404(Agenda, pk=unwatch_id) unfollow(request.user, agenda, send_action=True) else: watch_id = request.POST.get('watch', None) if not watch_id: return HttpResponseServerError('neither "watch" nor "unwatch" arguments specified') try: agenda = get_object_or_404(Agenda, pk=watch_id) follow(request.user, agenda) except Agenda.DoesNotExist: return HttpResponseBadRequest('bad agenda id') return HttpResponse('OK') else: return HttpResponseNotAllowed(['POST'])
def follow_members(request): if not request.user.is_authenticated(): return HttpResponseForbidden(reverse("login")) if request.method == "POST": unwatch_id = request.POST.get("unwatch", None) if unwatch_id: member = get_object_or_404(Member, pk=unwatch_id) unfollow(request.user, member, send_action=True) else: watch_id = request.POST.get("watch", None) if not watch_id: return HttpResponseServerError('neither "watch" nor "unwatch" arguments specified') try: member = get_object_or_404(Member, pk=watch_id) follow(request.user, member) except Member.DoesNotExist: return HttpResponseBadRequest("bad member id") return HttpResponse("OK") else: return HttpResponseNotAllowed(["POST"])
def follow_members(request): if not request.user.is_authenticated(): return HttpResponseForbidden(reverse('login')) p = request.user.get_profile() if request.method == 'POST': unwatch_id = request.POST.get('unwatch', None) if unwatch_id: member = get_object_or_404(Member, pk=unwatch_id) unfollow(request.user, member) else: watch_id = request.POST.get('watch', None) if not watch_id: return HttpResponseServerError('neither "watch" nor "unwatch" arguments specified') try: member = get_object_or_404(Member, pk=watch_id) follow(request.user, member) except Member.DoesNotExist: return HttpResponseBadRequest('bad member id') return HttpResponse('OK') else: return HttpResponseNotAllowed(['POST'])
def follow_agendas(request): if not request.user.is_authenticated(): return HttpResponseForbidden(reverse('login')) if request.method == 'POST': unwatch_id = request.POST.get('unwatch', None) if unwatch_id: agenda = get_object_or_404(Agenda, pk=unwatch_id) unfollow(request.user, agenda, send_action=True) else: watch_id = request.POST.get('watch', None) if not watch_id: return HttpResponseServerError( 'neither "watch" nor "unwatch" arguments specified') try: agenda = get_object_or_404(Agenda, pk=watch_id) follow(request.user, agenda) except Agenda.DoesNotExist: return HttpResponseBadRequest('bad agenda id') return HttpResponse('OK') else: return HttpResponseNotAllowed(['POST'])
def test_is_following(self): """Test the is-following query""" p = self.jacob.get_profile() loggedin = self.client.login(username='******', password='******') self.assertTrue(loggedin) follow(self.jacob, self.bill_1) response = self.client.post(reverse('user-is-following'), {'id': self.bill_1.id, 'what': 'bill'}) self.assertEquals(response.status_code, 200) self.assertEquals(response.content, 'true') unfollow(self.jacob, self.bill_1) response = self.client.post(reverse('user-is-following'), {'id': self.bill_1.id, 'what': 'bill'}) self.assertEquals(response.status_code, 200) self.assertEquals(response.content, 'false') self.client.logout()
def test_is_following(self): """Test the is-following query""" p = self.jacob.profiles.get() loggedin = self.client.login(username='******', password='******') self.assertTrue(loggedin) follow(self.jacob, self.bill_1) response = self.client.get(reverse('user-is-following'), {'id': self.bill_1.id, 'what': 'bill'}) self.assertEquals(response.status_code, 200) res_obj = json.loads(response.content) self.assertTrue(res_obj['watched']) unfollow(self.jacob, self.bill_1) response = self.client.get(reverse('user-is-following'), {'id': self.bill_1.id, 'what': 'bill'}) self.assertEquals(response.status_code, 200) res_obj = json.loads(response.content) self.assertFalse(res_obj['watched']) self.client.logout()