Ejemplo n.º 1
0
    def test_success_get_user_by_username(self):
        username = '******'
        password = '******'
        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)
Ejemplo n.º 2
0
    def test_success_create(self):
        username = '******'
        password = '******'

        user_id = user_db.create_user(username, password)

        fetched_user_id, fetched_username, fetched_password, salt = base_db.fetchone("SELECT * FROM users")

        self.assertIsInstance(fetched_user_id, int)
        self.assertEqual(user_id, fetched_user_id)
        self.assertEqual(username, fetched_username)

        hash_password, _ = utils.get_hash_with_salt(password, salt=salt)
        self.assertEqual(hash_password, fetched_password)
Ejemplo n.º 3
0
    def test_get_user_by_user_id(self):
        username = '******'
        password = '******'
        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)
Ejemplo n.º 4
0
def create_user(username, password):
    password, salt = utils.get_hash_with_salt(password)

    query = "INSERT INTO users(username, password, salt) VALUES (%s, %s, %s) RETURNING id;"
    return base_db.fetchone(query, username, password, salt)[0]