Example #1
0
    def test_get_non_existent_user_id_returns_none(self):
        username = 'johndoe'
        password = '123123'
        user_db.create_user(username, password)
        fetched_data = user_db.get_user(user_id=12324)

        self.assertEqual(fetched_data, None)
Example #2
0
    def test_get_user_by_user_id(self):
        username = 'johndoe'
        password = '123123'
        user_db.create_user(username, password)

        user = user_db.get_user(username=username)
        print user.id
        fetched_user = user_db.get_user(user_id=user.id)
        print fetched_user.id

        self.assertIsInstance(fetched_user.id, int)
        self.assertEqual(user.id, fetched_user.id)
        self.assertEqual(fetched_user.username, username)

        hash_password, _ = utils.get_hash_with_salt(password, salt=fetched_user.salt)
        self.assertEqual(hash_password, fetched_user.password)
Example #3
0
    def test_false_user_check_password_wrong_password(self):
        username = 'johndoe'
        password = '123123'

        user_db.create_user(username, password)
        user = user_db.get_user(username=username)

        self.assertEqual(user.check_password("False"), False)
Example #4
0
    def test_user_check_password(self):
        username = 'johndoe'
        password = '123123'

        user_db.create_user(username, password)
        user = user_db.get_user(username=username)

        self.assertEqual(user.check_password(password), True)
Example #5
0
def user_chat(request, recipient_id, user_id):

    user_id = int(user_id)
    recipient_id = int(recipient_id)
    message_history = db.get_messages(user_id, recipient_id)
    db.mark_messages_as_read(user_id, recipient_id)
    user = user_db.get_user(user_id=user_id)
    recipient = user_db.get_user(user_id=recipient_id)

    if request.method == 'POST':
        text_message = request.POST['message']
        db.create_message(user_id, recipient_id, text_message)
        return redirect('/chat/user/{}/'.format(recipient_id))

    return render_to_response('chat/user_chat.html', {
        'recipient_id': recipient.id,
        'user_id': user.id,
        'message_history': message_history,
        'user_name': user.username,
        'recipient_name': recipient.username
    })
Example #6
0
    def test_success_get_user_by_username(self):
        username = 'johndoe'
        password = '123123'
        user_db.create_user(username, password)

        user = user_db.get_user(username=username)

        self.assertIsInstance(user.id, int)
        self.assertEqual(user.username, username)

        hash_password, _ = utils.get_hash_with_salt(password, salt=user.salt)
        self.assertEqual(hash_password, user.password)
Example #7
0
def index(request):
    error = False

    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']
        user = user_db.get_user(username=username)

        if user and user.check_password(password):
            response = redirect('/chat/')
            auth.authorize_user(response, user.id)
            return response
        else:
            error = True

    return render_to_response('users/index.html', {'error' : error})
Example #8
0
def validate_username(username):
    errors = []

    if not username:
        errors.append("Enter username")

    if not errors and len(username) < 3:
        errors.append("Username is too short")

    if not errors and len(username) > 64:
        errors.append("Username is too long")

    if not errors and user_db.get_user(username=username):
        errors.append("User already exists")

    return errors
Example #9
0
def confirmation(request, user_id):
    user = user_db.get_user(user_id=user_id)
    return render_to_response('users/confirmation.html', {
        'user_name' : user.username
    })