Esempio n. 1
0
def chat(request, user_id):
    new_messages_number = db.get_number_new_messages(user_id)
    users_data = user_db.get_id_and_username_all_users()
    data = []
    for id, name in users_data:
        number = new_messages_number.get(id)
        data.append((id, name, number))
    return render_to_response("chat/chat.html", {
        'data': data,
    })
Esempio n. 2
0
    def test_get_number_new_messages(self):
        user_id = factories.create_user()
        user_id2 = factories.create_user()
        user_id3 = factories.create_user()
        text_message = 'Hello world'
        chat_db.create_message(user_id, user_id2, text_message)
        chat_db.create_message(user_id, user_id2, text_message)

        chat_db.create_message(user_id2, user_id, text_message)

        fetched_number_new_messages = chat_db.get_number_new_messages(user_id2)
        fetched_number = fetched_number_new_messages[user_id]

        self.assertEqual(2, fetched_number)
Esempio n. 3
0
    def test_mark_messages_as_read(self):
        user1 = factories.create_user()
        user2 = factories.create_user()
        user3 = factories.create_user()

        chat_db.create_message(user2, user1, 'Hello world')
        chat_db.create_message(user3, user1, 'Hello world')

        chat_db.mark_messages_as_read(user1, user2)

        fetched_data = chat_db.get_number_new_messages(user1)
        fetched_number = fetched_data.get(user2)
        fetched_number2 = fetched_data.get(user3)

        self.assertEqual(None, fetched_number)
        self.assertEqual(1, fetched_number2)