def test_asctime(self):
        message = Message()
        dt = datetime.datetime(2016, 10, 22, 10, 16, 40)
        message.date = dt
        asctime = message.get_asctime()
        self.assertEqual(asctime, "Sat Oct 22 10:16:40 2016")

        message = Message()
        dt = datetime.datetime(2016, 10, 22, 9, 6, 4)
        message.date = dt
        asctime = message.get_asctime()
        self.assertEqual(asctime, "Sat Oct 22 9:06:04 2016")
    def test_asctime(self):
        from api.models import Message
        message = Message()
        dt = datetime.datetime(2016, 10, 22, 10, 16, 40)
        message.date = dt
        asctime = message.get_asctime()
        self.assertEqual(asctime, "Sat Oct 22 10:16:40 2016")

        message = Message()
        dt = datetime.datetime(2016, 10, 22, 9, 6, 4)
        message.date = dt
        asctime = message.get_asctime()
        self.assertEqual(asctime, "Sat Oct 22 9:06:04 2016")
Beispiel #3
0
 def test_1_day(self):
     from api.models import Message
     message = Message()
     dt = datetime.datetime.fromtimestamp(time.time() - 3600 * 25)
     message.date = dt
     age = message.get_age()
     self.assertEqual(age, "1 day")
Beispiel #4
0
 def test_now(self):
     from api.models import Message
     message = Message()
     dt = datetime.datetime.fromtimestamp(time.time() + 100)
     message.date = dt
     age = message.get_age()
     self.assertEqual(age, "now")
Beispiel #5
0
    def test_0_second(self):
        from api.models import Message

        message = Message()
        message.date = datetime.datetime.utcnow()
        age = message.get_age()
        self.assertEqual(age, "0 second")
 def test_1_day(self):
     from api.models import Message
     message = Message()
     dt = datetime.datetime.fromtimestamp(time.time() - 3600 * 25)
     message.date = dt
     age = message.get_age()
     self.assertEqual(age, "1 day")
 def test_now(self):
     from api.models import Message
     message = Message()
     dt = datetime.datetime.fromtimestamp(time.time() + 100)
     message.date = dt
     age = message.get_age()
     self.assertEqual(age, "now")
Beispiel #8
0
    def create_message(id, user_id, date, text):
        message = Message()
        message.id = id
        message.user_id = user_id
        message.date = date
        message.text = text

        message.save()
        return message
Beispiel #9
0
    def create(self, request, *args, **kwargs):
        """
        parameters: 'recipientID', 'textFirstMessage'
        """
        for parameter in ['recipientID', 'textFirstMessage']:
            if parameter not in request.data:
                print(3333)
                return Response(status=status.HTTP_400_BAD_REQUEST)

        recipientID = request.data['recipientID']
        textFirstMessage = request.data['textFirstMessage']

        querysetDialogsUser = list()
        querysetDialogsRecipient = list()

        #exist dialog?
        for item in DialogOwners.objects.filter(owner=request.user):
            querysetDialogsUser.append(item.dialog)
        for item in DialogOwners.objects.filter(owner=User.objects.get(id=recipientID)):
            querysetDialogsRecipient.append(item.dialog)
        
        #if dialog exist
        for item in querysetDialogsUser:
            if querysetDialogsRecipient.count(item) != 0:
                return Response(status=status.HTTP_400_BAD_REQUEST)

        dialog = Dialog()
        dialog.save()

        message = Message()
        message.owner = request.user
        message.ownerDialog = dialog
        message.text = textFirstMessage
        message.date = timezone.now()
        message.save()

        dialog.textLastMessage = textFirstMessage
        dialog.dateLastMessage = message.date
        dialog.idLastMessage = message.id

        dialog.save()

        dialogOwner1 = DialogOwners()
        dialogOwner2 = DialogOwners()

        dialogOwner1.owner = request.user
        dialogOwner1.dialog = dialog
        dialogOwner2.owner = User.objects.get(id=recipientID)
        dialogOwner2.dialog = dialog

        dialogOwner1.save()
        dialogOwner2.save()

        #data = [{ 'id':dialog.id }]
        return Response(status=status.HTTP_201_CREATED)
Beispiel #10
0
    def create(self, request, *args, **kwargs):
        """
        parameters POST: 'dialogID', 'text'
        """
        for parameter in ['dialogID', 'text']:
            if parameter not in request.data:
                return Response(status=status.HTTP_400_BAD_REQUEST)

        dialog = Dialog.objects.get(pk=request.data['dialogID'])
        message = Message()
        message.owner = request.user
        message.ownerDialog = dialog
        message.text = request.data['text']
        message.date = timezone.now()
        message.save()

        if dialog.dateLastMessage < message.date:
            dialog.dateLastMessage = message.date
            dialog.textLastMessage = message.text
            dialog.idLastMessage = message.id
            dialog.save()

        #data = [{ 'id':message.id }, { 'date':message.date }]
        return Response(status=status.HTTP_201_CREATED)
Beispiel #11
0
 def test_0_second(self):
     from api.models import Message
     message = Message()
     message.date = datetime.datetime.utcnow()
     age = message.get_age()
     self.assertEqual(age, "0 second")