def feed_messages(request, recipient_username=None, author_username=None): if not request.user.is_authenticated(): return HttpResponseForbidden() else: timestamp = TalkMessage.getLargestMessageId() if recipient_username is not None: recipient = get_object_or_404(User, username=recipient_username) else: recipient = None if author_username is not None: author = get_object_or_404(User, username=author_username) else: author = None since = request.GET.get("since", None) if since is not None: since_dt = since messages = TalkMessage.getMessages(recipient, author).filter(pk__gt=since_dt) message_count = TalkMessage.getMessages(request.user).filter(pk__gt=since_dt).count() else: messages = TalkMessage.getMessages(recipient, author) message_count = TalkMessage.getMessages(request.user).count() return HttpResponse( json.dumps({"ts": timestamp, "msgCnt": message_count, "ms": [msg.getJson() for msg in messages]}) )
def feed_messages(request, recipient_username=None, author_username=None): if not request.user.is_authenticated(): return HttpResponseForbidden() else: timestamp = TalkMessage.getLargestMessageId() if recipient_username is not None: recipient = get_object_or_404(User, username=recipient_username) else: recipient = None if author_username is not None: author = get_object_or_404(User, username=author_username) else: author = None since = request.GET.get('since', None) if since is not None: since_dt = since messages = TalkMessage.getMessages(recipient, author).filter(pk__gt=since_dt) message_count = TalkMessage.getMessages( request.user).filter(pk__gt=since_dt).count() else: messages = TalkMessage.getMessages(recipient, author) message_count = TalkMessage.getMessages(request.user).count() return HttpResponse( json.dumps({ 'ts': timestamp, 'msgCnt': message_count, 'ms': [msg.getJson() for msg in messages] }))
def test_MyMessageList(self): # arrange ''' This test is attempting to verify that we see messages for specified user or broadcast ''' recipient = User.objects.get(username="******") author = User.objects.all()[1] msg = TalkMessage.objects.create(content='yo dude', content_timestamp=self.now, author=author) msg.recipients.add(recipient) msg.recipients.add(User.objects.all()[2]) time_stamp = TalkMessage.objects.all().order_by('-pk')[0].pk - 2 profile = recipient.profile profile.last_viewed_mymessages = time_stamp profile.save() #self.client.login(username=recipient.username, password='******') #response = self.client.get('/talk/messages/'+recipient_path) # act response = self._get_messages_response(recipient=recipient) expectedMessages = TalkMessage.getMessages(recipient,author=None) # don't pass in author gotMessages = response.context["gc_msg"] # assert self.assertTrue(time_stamp < recipient.profile.last_viewed_mymessages) self.assertEqual(recipient, response.context["recipient"]) self.assertEqual(len(gotMessages), expectedMessages.count(), "My messages response % is not the same size as expected %s" % (len(gotMessages), expectedMessages.count())) for i in range(len(expectedMessages)): self.assertEqual(expectedMessages[i],gotMessages[i], "My messages doesn't contain an expected message: %s" % expectedMessages[i])
def test_MyMessageList(self): # arrange ''' This test is attempting to verify that we see messages for specified user or broadcast ''' recipient = User.objects.get(username="******") author = User.objects.all()[1] msg = TalkMessage.objects.create(content='yo dude', content_timestamp=self.now, author=author) msg.recipients.add(recipient) msg.recipients.add(User.objects.all()[2]) time_stamp = TalkMessage.objects.all().order_by('-pk')[0].pk - 2 profile = recipient.profile profile.last_viewed_mymessages = time_stamp profile.save() #self.client.login(username=recipient.username, password='******') #response = self.client.get('/talk/messages/'+recipient_path) # act response = self._get_messages_response(recipient=recipient) expectedMessages = TalkMessage.getMessages(recipient, author=None) # don't pass in author gotMessages = response.context["gc_msg"] # assert self.assertTrue(time_stamp < recipient.profile.last_viewed_mymessages) self.assertEqual(recipient, response.context["recipient"]) self.assertEqual(len(gotMessages), expectedMessages.count(), "My messages response % is not the same size as expected %s" % (len(gotMessages), expectedMessages.count())) for i in range(len(expectedMessages)): self.assertEqual(expectedMessages[i], gotMessages[i], "My messages doesn't contain an expected message: %s" % expectedMessages[i])
def message_map(request): messages = TalkMessage.getMessages() return render_to_response( "geocamTalk/map.html", dict(gc_msg=messages, first_geolocation=get_first_geolocation(messages)), context_instance=RequestContext(request), )
def message_map(request): messages = TalkMessage.getMessages() return render_to_response( 'geocamTalk/map.html', dict(gc_msg=messages, first_geolocation=get_first_geolocation(messages)), context_instance=RequestContext(request))
def get_messages(request, recipient_username=None, author_username=None): timestamp = TalkMessage.getLargestMessageId() if recipient_username is not None: recipient = get_object_or_404(User, username=recipient_username) else: recipient = None if author_username is not None: author = get_object_or_404(User, username=author_username) else: author = None since = request.GET.get('since', None) if since is not None: since_dt = since messages = TalkMessage.getMessages(recipient, author).filter(pk__gt=since_dt) message_count = TalkMessage.getMessages(recipient).filter(pk__gt=since_dt).count() else: messages = TalkMessage.getMessages(recipient, author) message_count = TalkMessage.getMessages(recipient).count() return timestamp, messages, message_count
def testMessageListAudioPresent(self): # arrange _author = User.objects.all()[2] recipient = User.objects.all()[1] response = self.get_recipient_messages_response(recipient) recipient_messages = TalkMessage.getMessages(recipient) # act geocount = 0 for m in recipient_messages.all(): if m.audio_file: geocount += 1 # assert self.assertContains(response, 'class="media"', geocount)
def testEnsureMyMessageListAuthorLinksPresent(self): author = User.objects.all()[2] recipient = User.objects.all()[1] #arrange recipient_messages = TalkMessage.getMessages(recipient, author) #act response = self.get_recipient_messages_response(recipient) #assert for _ in recipient_messages: link_to_recipient_msgs_from_author = 'href="FIXME/messages/%s/%s"' % (recipient.username, author.username) #print 'didnt find %s in %s' % (link_to_recipient_msgs_from_author, response) self.assertContains(response, link_to_recipient_msgs_from_author)
def testEnsureMyMessagesAreFilteredByAuthor(self): # arrange author = User.objects.all()[0] recipient = User.objects.all()[2] recipient_messages_from_author_or_broadcast = TalkMessage.getMessages(recipient, author) # act response = self.get_recipient_messages_response_filtered_by_author(recipient, author) # assert self.assertEqual(200, response.status_code) for m in recipient_messages_from_author_or_broadcast: self.assertContains(response, m.content)
def testMessageListAudioPresent(self): # arrange _author = User.objects.all()[2] recipient = User.objects.all()[1] response = self.get_recipient_messages_response(recipient) recipient_messages = TalkMessage.getMessages(recipient) # act geocount = 0 for m in recipient_messages.all(): if m.audio_file: geocount += 1 # assert self.assertContains(response, 'class="media"', geocount)
def test_MyMessageJsonFeed(self): ''' This test is attempting to verify that we see messages for specified user or broadcast ''' author = User.objects.get(username="******") self.client.login(username=author.username, password='******') ordered_messages = TalkMessage.getMessages(recipient=author).order_by("-pk") messageid = ordered_messages[0].pk - 1 response = self.client.get(reverse("talk_message_list_author_json", args=[author.username])+ '?since=%s' % messageid) self.assertContains(response, '"messageId": %s' % ordered_messages[0].pk) for msg in ordered_messages[1:]: self.assertNotContains(response, '"messageId": %s' % msg.pk)
def testEnsureMyMessageListAuthorLinksPresent(self): author = User.objects.all()[2] recipient = User.objects.all()[1] #arrange recipient_messages = TalkMessage.getMessages(recipient, author) #act response = self.get_recipient_messages_response(recipient) #assert for _ in recipient_messages: link_to_recipient_msgs_from_author = 'href="FIXME/messages/%s/%s"' % ( recipient.username, author.username) #print 'didnt find %s in %s' % (link_to_recipient_msgs_from_author, response) self.assertContains(response, link_to_recipient_msgs_from_author)
def test_MyMessageJsonFeed(self): ''' This test is attempting to verify that we see messages for specified user or broadcast ''' author = User.objects.get(username="******") self.client.login(username=author.username, password='******') ordered_messages = TalkMessage.getMessages(recipient=author).order_by("-pk") messageid = ordered_messages[0].pk - 1 response = self.client.get(reverse("geocamTalk_message_list_author_json", args=[author.username]) + '?since=%s' % messageid) self.assertContains(response, '"messageId": %s' % ordered_messages[0].pk) for msg in ordered_messages[1:]: self.assertNotContains(response, '"messageId": %s' % msg.pk)
def testEnsureMyMessagesAreFilteredByAuthor(self): # arrange author = User.objects.all()[0] recipient = User.objects.all()[2] recipient_messages_from_author_or_broadcast = TalkMessage.getMessages( recipient, author) # act response = self.get_recipient_messages_response_filtered_by_author( recipient, author) # assert self.assertEqual(200, response.status_code) for m in recipient_messages_from_author_or_broadcast: self.assertContains(response, m.content)
def message_list(request, recipient_username=None, author_username=None): timestamp = TalkMessage.getLargestMessageId() if recipient_username is not None: recipient = get_object_or_404(User, username=recipient_username) else: recipient = None if author_username is not None: author = get_object_or_404(User, username=author_username) else: author = None if recipient is not None and recipient.pk == request.user.pk and author is None: profile = recipient.profile profile.last_viewed_mymessages = timestamp profile.save() return render_to_response('geocamTalk/message_list.html', dict(gc_msg=TalkMessage.getMessages(recipient, author), recipient=recipient, author=author, timestamp=timestamp), context_instance=RequestContext(request))
def test_submitFormToCreateMessageWithRecipients(self): """ submit the Talk Message through the form """ msgCnt = TalkMessage.objects.all().count() content = "Whoa man, that burning building almost collapsed on me!" author = User.objects.get(username="******") self.client.login(username=author.username, password='******') recipienta = User.objects.all()[1] recipientb = User.objects.all()[2] response = self.client.post(reverse("geocamTalk_create_message"), data={"content": content, "latitude": GeocamTalkMessageSaveTest.cmusv_lat, "longitude": GeocamTalkMessageSaveTest.cmusv_lon, "author": author.pk, "recipients": [recipienta.pk, recipientb.pk]}) # should be redirected when form post is successful: self.assertEqual(response.status_code, 302, "submitFormToCreateMessage Failed") newMsgCnt = TalkMessage.objects.all().count() self.assertEqual(msgCnt + 1, newMsgCnt, "Creating a Talk Message through view Failed.") newMsg = TalkMessage.getMessages()[0] self.assertEqual(newMsg.recipients.all().count(), 2, "Different number of recipients than expected")
def test_submitFormToCreateMessageWithRecipients(self): """ submit the Talk Message through the form """ msgCnt = TalkMessage.latest.all().count() content = "Whoa man, that burning building almost collapsed on me!" author = User.objects.get(username="******") self.client.login(username=author.username, password='******') recipienta = User.objects.all()[1] recipientb = User.objects.all()[2] response = self.client.post(reverse("talk_create_message"), data={"content":content, "latitude":GeocamTalkMessageSaveTest.cmusv_lat, "longitude":GeocamTalkMessageSaveTest.cmusv_lon, "author":author.pk, "recipients":[recipienta.pk, recipientb.pk]}) # should be redirected when form post is successful: self.assertEqual(response.status_code, 302, "submitFormToCreateMessage Failed") newMsgCnt = TalkMessage.latest.all().count() self.assertEqual(msgCnt + 1, newMsgCnt, "Creating a Talk Message through view Failed.") newMsg = TalkMessage.getMessages()[0] self.assertEqual(newMsg.recipients.all().count(), 2, "Different number of recipients than expected")