Esempio n. 1
0
    def test_CreateMessage_CreatesInstance(self):

        # Create Message instance
        chat = Chat.objects.get(pk=1)
        message = Message(chat=chat)
        message.save()
        self.assertIsInstance(message, Message)
Esempio n. 2
0
File: models.py Progetto: somnam/xo
    def test_CreateMessage_CreatesInstance(self):

        # Create Message instance
        chat    = Chat.objects.get(pk=1)
        message = Message(chat=chat)
        message.save()
        self.assertIsInstance(message, Message)
Esempio n. 3
0
def create_message_handler(data):
    message = Message(comment=data['message']['comment'],
                      author=session.user,
                      room_id=data['room']['id'])
    db.session.add(message)
    db.session.commit()
    emit('newMessage', message.serialize(), room=data['room']['name'])
Esempio n. 4
0
    def test_CreateLeaveMessage_PrintsMessage(self):

        # Create Leave Message
        chat = Chat.objects.get(pk=1)
        user = User.objects.get(pk=1)
        message = Message(chat=chat, author=user, type=MESSAGE_TYPES['leave'])
        message.save()
        self.assertEqual(unicode(message), "User 'test1' has left the chat.")
Esempio n. 5
0
File: utils.py Progetto: somnam/xo
def chat_update(request, game_id):
    chat = Chat.objects.get(pk=game_id)

    # Update chat state with users message
    message = Message(
        chat=chat,
        author=request.user,
        message=request.POST['message'],
    )
    message.save()
Esempio n. 6
0
def chat_update(request, game_id):
    chat = Chat.objects.get(pk=game_id)

    # Update chat state with users message
    message = Message(
        chat=chat,
        author=request.user,
        message=request.POST['message'],
    )
    message.save()
Esempio n. 7
0
File: models.py Progetto: somnam/xo
    def test_CreateMessage_PrintsMessage(self):

        # Create Message
        chat    = Chat.objects.get(pk=1)
        user    = User.objects.get(pk=1)
        message = Message(chat=chat, author=user, message=u'This is a message.')
        message.save()
        self.assertEqual(
            (u'[%s]: %s' % (message.author, unicode(message))),
            u'[test1]: This is a message.',
        )
Esempio n. 8
0
File: models.py Progetto: somnam/xo
    def test_CreateLeaveMessage_PrintsMessage(self):

        # Create Leave Message
        chat    = Chat.objects.get(pk=1)
        user    = User.objects.get(pk=1)
        message = Message(chat=chat, author=user, type=MESSAGE_TYPES['leave'])
        message.save()
        self.assertEqual(
            unicode(message),
            "User 'test1' has left the chat."
        )
Esempio n. 9
0
    def test_CreateNotificationMessage_PrintsMessage(self):

        # Create Notification Message
        chat = Chat.objects.get(pk=1)
        message = Message(chat=chat,
                          type=MESSAGE_TYPES['notification'],
                          message=u'This is a notification.')
        message.save()
        self.assertEqual(
            unicode(message),
            u'This is a notification.',
        )
Esempio n. 10
0
 def post(self):
     jsonobj = request.get_json(force=True)
     comment = jsonobj.get('message')
     if not comment:
         abort(400, 'Invalid request.')
     message = Message(comment=comment, author=g.user)
     db.session.add(message)
     db.session.commit()
     result = message.serialize()
     resp = jsonify(result)
     resp.mimetype = 'text/html'
     return resp
Esempio n. 11
0
    def test_CreateMessage_PrintsMessage(self):

        # Create Message
        chat = Chat.objects.get(pk=1)
        user = User.objects.get(pk=1)
        message = Message(chat=chat,
                          author=user,
                          message=u'This is a message.')
        message.save()
        self.assertEqual(
            (u'[%s]: %s' % (message.author, unicode(message))),
            u'[test1]: This is a message.',
        )
Esempio n. 12
0
File: models.py Progetto: somnam/xo
    def test_CreateNotificationMessage_PrintsMessage(self):

        # Create Notification Message
        chat    = Chat.objects.get(pk=1)
        message = Message(
            chat=chat, 
            type=MESSAGE_TYPES['notification'],
            message=u'This is a notification.'
        )
        message.save()
        self.assertEqual(
            unicode(message),
            u'This is a notification.',
        )
Esempio n. 13
0
 def test_xss_messages(self):
     self.login('tim', 'password')
     payload = '<script>alert(42)</script>'
     msg = Message(comment=payload, user=g.user)
     db.session.add(msg)
     db.session.commit()
     rv = self.client.get('/messages', follow_redirects=True)
     self.assertNotIn(payload, rv.data,
                      'XSS payload reflected in the response.')
Esempio n. 14
0
 def post(self):
     jsonobj = request.get_json(force=True)
     message = jsonobj.get('message')
     if message:
         msg = Message(comment=message, user=g.user)
         db.session.add(msg)
         db.session.commit()
     messages = [
         m.serialize()
         for m in Message.query.order_by(Message.created.desc()).all()
     ]
     return {'messages': messages}
Esempio n. 15
0
async def crawl_messages_once(slacker: Slacker, logger: Logger) -> None:
    base_url = f"http://{config.DB_URL}/"

    # get messages and insert them into database
    ch_info = await slacker.get_channels_list() or []
    if ch_info:
        for ch_id, ch_name in ch_info:
            logger.debug(f"Channel: {ch_name}")

            prev_date = datetime.now() - timedelta(
                days=config.MESSAGE_DELTA_DAYS)
            messages = await slacker.get_channel_messages(ch_id, prev_date)
            if messages:
                try_request(logger,
                            r.put,
                            base_url + "message/",
                            data=json.dumps([x.dict() for x in messages],
                                            cls=TimerEncoder))

        logger.info(
            f"Messages from {len(ch_info)} channels parsed and sent to the database."
        )
    channels_point = Point("workspace").field("channels", len(ch_info)).time(
        datetime.utcnow())

    # update messages without permalinks
    answer = try_request(logger, r.get, base_url + "message/linkless")
    if answer.is_err():
        return
    answer = answer.value

    empty_links_messages = [Message(**x) for x in answer.json()]
    if empty_links_messages:
        messages = await slacker.update_permalinks(
            messages=empty_links_messages)
        answer = try_request(logger,
                             r.patch,
                             base_url + "message/links",
                             data=json.dumps([x.dict() for x in messages],
                                             cls=TimerEncoder))
        if answer.is_ok():
            logger.debug(f"Updated permalinks for {len(messages)} messages.")
    linkless_messages_point = Point("workspace").field(
        "linkless_messages", len(empty_links_messages)).time(datetime.utcnow())
    INFLUX_API_WRITE([linkless_messages_point, channels_point])
Esempio n. 16
0
def messages_create():
    message = request.form['message']
    msg = Message(comment=message, user=g.user)
    db.session.add(msg)
    db.session.commit()
    return redirect(url_for('core.messages'))
Esempio n. 17
0
def messages_create():
    message = request.form['message']
    msg = Message(comment=message, author=g.user, room=Room.query.first())
    db.session.add(msg)
    db.session.commit()
    return redirect(url_for('core.messages'))
Esempio n. 18
0
    def _migrate(self):
        # Drop all tables
        print('Dropping tables...')

        auth.models.User.objects.all().delete()
        Administrator.objects.all().delete()
        User.objects.all().delete()
        Folder.objects.all().delete()
        Message.objects.all().delete()
        Announcement.objects.all().delete()
        ApplyAnnouncement.objects.all().delete()
        ApplyRoute.objects.all().delete()
        Comment.objects.all().delete()
        CommentAnnouncement.objects.all().delete()
        CommentRoute.objects.all().delete()
        Day.objects.all().delete()
        Route.objects.all().delete()
        StopAnnouncement.objects.all().delete()
        StopRoute.objects.all().delete()

        print("Dropping tables OK!")

        print('Create administrators accounts...')
        admin1 = auth.models.User.objects.create_superuser(username='******', email='*****@*****.**',
                                                                   password='******')

        print('Create administrators accounts OK!')

        print('Create users accounts...')
        user_account1 = auth.models.User.objects.create_user(username='******', email='*****@*****.**',
                                                                   password='******')

        user_account2 = auth.models.User.objects.create_user(username='******', email='*****@*****.**',
                                                                   password='******')
        print('Create users accounts OK!')

        print('Create administrators...')
        administrator = Administrator(user_account = admin1)
        administrator.save()

        print('Create administrators OK!')

        print('Create users...')
        user1 = User(user_account = user_account1,name = "Nombre", surnames = "Apellido1 Apellido2", city = "Sevilla",
                     birthdate = date(1993, 4, 6), phone = "666999888",searchingCar = True)
        user1.save()
        user2 = User(user_account = user_account2,name = "Nombre2", surnames = "Apellido1 Apellido2", city = "Sevilla",
                     birthdate = date(1993, 4, 6), phone = "666999888",searchingCar = True)
        user2.save()
        print('Create user OK!')

        print('Create folders...')
        folder1 = Folder(name = "1", actor = user1)
        folder1.save()
        folder2 = Folder(name = "2", actor = user1)
        folder2.save()
        folder3 = Folder(name = "3", actor = user1)
        folder3.save()

        folder4 = Folder(name = "1", actor = user2)
        folder4.save()
        folder5 = Folder(name = "2", actor = user2)
        folder5.save()
        folder6 = Folder(name = "3", actor = user2)
        folder6.save()

        folder7 = Folder(name = "1", actor = administrator)
        folder7.save()
        folder8 = Folder(name = "2", actor = administrator)
        folder8.save()
        folder9 = Folder(name = "3", actor = administrator)
        folder9.save()

        print('Create folders OK!')

        print('Create messages...')
        message1 = Message(subject = "Asunto 1", body = "Este es un mensaje de prueba enviado", folder = folder1, sender = user1,
                           recipient = user2)
        message1.save()
        message2 = Message(subject = "Asunto 1", body = "Este es un mensaje de prueba enviado", folder = folder5, sender = user1,
                           recipient = user2)
        message2.save()

        print('Create messages OK!')

        print('Create comments...')
        comment1 = Comment(subject = "Muy bueno", comment = "Muy buen conductor, totalmente recomendable", rating = 9, referrer = user1,
                           evaluated = user2)
        comment1.save()
        comment2 = Comment(subject = "Regular", comment = "Como pasajero deja mucho que desear", rating = 4, referrer = user2,
                           evaluated = user1)
        comment2.save()

        print('Create comments OK!')

        print('Create routes...')
        route1 = Route(origin = "Alcalá de Guadaíra", destination = "Facultad de Informática", description = "Viaje regular durante 3 meses",
                           kind = "1", seating = 4, unitPrice = 2.00, user = user2)
        route1.save()
        route2 = Route(origin = "Arahal", destination = "Isla de la cartuja", description = "Viaje regular durante 6 meses",
                           kind = "1", seating = 4, unitPrice = 2.00, user = user1)
        route2.save()
        print('Create routes OK!')

        print('Create stop routes...')

        stopRoute1 = StopRoute(stop = "Alcalá de Guadaíra", sequence = 1, route = route2)
        stopRoute1.save()

        print('Create stop routes OK!')

        print('Create days...')

        day1 = Day(day = 1, departTime = "7:55", returnTime = "14:00", route = route2, active = True)
        day1.save()
        day2 = Day(day = 2, departTime = "7:55", returnTime = "14:00", route = route2, active = True)
        day2.save()
        day3 = Day(day = 3, departTime = "7:55", returnTime = "14:00", route = route2, active = True)
        day3.save()
        day4 = Day(day = 4, departTime = "7:55", returnTime = "14:00", route = route2, active = True)
        day4.save()
        day5 = Day(day = 5, departTime = "7:55", returnTime = "14:00", route = route2, active = True)
        day5.save()
        day6 = Day(day = 6, route = route2, active = False)
        day6.save()
        day7 = Day(day = 7, route = route2, active = False)
        day7.save()

        day8 = Day(day = 1, departTime = "7:55", returnTime = "14:00", route = route1, active = True)
        day8.save()
        day9 = Day(day = 2, departTime = "7:55", returnTime = "14:00", route = route1, active = True)
        day9.save()
        day10 = Day(day = 3, departTime = "7:55", returnTime = "14:00", route = route1, active = True)
        day10.save()
        day11 = Day(day = 4, departTime = "7:55", returnTime = "14:00", route = route1, active = True)
        day11.save()
        day12 = Day(day = 5, departTime = "7:55", returnTime = "14:00", route = route1, active = True)
        day12.save()
        day13 = Day(day = 6, route = route1, active = False)
        day13.save()
        day14 = Day(day = 7, route = route1, active = False)
        day14.save()

        print('Create days OK!')

        print('Create applys routes...')

        applyRoute1 = ApplyRoute(comment = "Buenas, yo entro a las 9 de la mañana y salgo a las dos, te viene bien en Alcalá de Guadaíra?",
                                 route= route2, user = user1)
        applyRoute1.save()

        print('Create applys routes OK!')

        print('Create comments  routes...')

        commentRoute1 = CommentRoute(subject = "Buena ruta!", comment = "Muy buen trayecto, excelente conductor", rating = 10,
                                     user = user1, route = route2)
        commentRoute1.save()

        print('Create comments routes OK!')

        print('Create announcements ...')
        announcement1 = Announcement(origin = "Alcalá de Guadaíra", destination = "Facultad de informática", description = "Viaje puntual"
                                     , seating = 2, unitPrice = 2, date = datetime(2015, 12, 6, 16, 29, 43, 79043), user = user1)
        announcement1.save()
        print('Create announcements OK!')

        print('Create applys  announcements...')
        applyAnnouncement1 = ApplyAnnouncement(comment = "Buenas, yo entro a las 17:00 de la tarde te viene bien los arcos?",
                                               announcement=announcement1, user=user1)
        applyAnnouncement1.save()
        print('Create applys announcements OK!')

        print('Create stops  announcements...')
        stopAnnouncement1 = StopAnnouncement(stop = "Sevilla", sequence = 1, announcement = announcement1)
        stopAnnouncement1.save()
        print('Create stops announcements OK!')

        print('Create comments  announcements...')
        commentAnnouncement1 = CommentAnnouncement(subject = "Buena ruta!", comment = "Muy buen trayecto, excelente conductor", rating = 10,
                                     user = user1, announcement = announcement1)
        commentAnnouncement1.save()
        print('Create comments announcements OK!')