# Path: amivapi/tests/utils.py
# class TestClient(FlaskClient):
# class TestResponse(Response):
# class WebTest(unittest.TestCase, FixtureMixin):
# class WebTestNoAuth(WebTest):
#     def open(self, *args, **kwargs):
#     def json(self):
#     def setUp(self, **extra_config):
#     def tearDown(self):
#     def get_user_token(self, user_id, created=None):
#     def get_root_token(self):
#     def setUp(self, **extra_config):
#         def authenticate_root(resource):
# def skip_if_false(condition, reason):
#     def _skip(func):
# 
# Path: amivapi/users/security.py
# def hash_on_insert(items):
#     """Hook for user insert.
# 
#     Hash the password if it is not None.
#     (When logging in via LDAP the password should not be stored and therefore
#     it can be none.)
# 
#     Args:
#         items (list): List of new items as passed by the on_insert event.
#     """
#     for user in items:
#         _hash_password(user)
# 
# def hash_on_update(updates, original):
#     """Hook for user update or replace.
# 
#     Hash the password if it is not None.
#     (When logging in via LDAP the password should not be stored and therefore
#     it can be none.)
# 
#     Args:
#         updates (dict): dict of changed user data
#         original (dict): dict of user data before the update
#     """
#     _hash_password(updates)


import json
from bson import ObjectId
from passlib.hash import pbkdf2_sha256
from amivapi.tests import utils
from amivapi.users.security import (
    hash_on_insert, hash_on_update)
        self.assertTrue(pbkdf2_sha256.verify(plaintext, hashed_password))

    def test_hash_on_insert(self):
        """Test Hash insert function.

        Because of how Eve handles hooks, they all modify the input arguments.

        Need app context to find config.
        """
        with self.app.app_context():
            # First test hash on insert
            items = [
                {'password': "some_pw"},
                {'password': "other_pw"}
            ]

            # Hash passwords in list items
            hash_on_insert(items)

            # Check hashed
            self.assertVerify("some_pw", items[0]['password'])
            self.assertVerify("other_pw", items[1]['password'])

    def test_hash_on_update(self):
        """Test hash on update. Works like test for hash on insert."""
        with self.app.app_context():
            data = {'password': "some_pw"}

            # Second param is original data, but the hash function ignores
            # it so we can just set it to None

# Path: amivapi/tests/utils.py
# class TestClient(FlaskClient):
# class TestResponse(Response):
# class WebTest(unittest.TestCase, FixtureMixin):
# class WebTestNoAuth(WebTest):
#     def open(self, *args, **kwargs):
#     def json(self):
#     def setUp(self, **extra_config):
#     def tearDown(self):
#     def get_user_token(self, user_id, created=None):
#     def get_root_token(self):
#     def setUp(self, **extra_config):
#         def authenticate_root(resource):
# def skip_if_false(condition, reason):
#     def _skip(func):
# 
# Path: amivapi/users/security.py
# def hash_on_insert(items):
#     """Hook for user insert.
# 
#     Hash the password if it is not None.
#     (When logging in via LDAP the password should not be stored and therefore
#     it can be none.)
# 
#     Args:
#         items (list): List of new items as passed by the on_insert event.
#     """
#     for user in items:
#         _hash_password(user)
# 
# def hash_on_update(updates, original):
#     """Hook for user update or replace.
# 
#     Hash the password if it is not None.
#     (When logging in via LDAP the password should not be stored and therefore
#     it can be none.)
# 
#     Args:
#         updates (dict): dict of changed user data
#         original (dict): dict of user data before the update
#     """
#     _hash_password(updates)


# Path: amivapi/tests/users/test_security.py
import json
from bson import ObjectId
from passlib.hash import pbkdf2_sha256
from amivapi.tests import utils
from amivapi.users.security import (
    hash_on_insert, hash_on_update)

        self.assertTrue(pbkdf2_sha256.verify(plaintext, hashed_password))

    def test_hash_on_insert(self):
        """Test Hash insert function.

        Because of how Eve handles hooks, they all modify the input arguments.

        Need app context to find config.
        """
        with self.app.app_context():
            # First test hash on insert
            items = [
                {'password': "some_pw"},
                {'password': "other_pw"}
            ]

            # Hash passwords in list items
            hash_on_insert(items)

            # Check hashed
            self.assertVerify("some_pw", items[0]['password'])
            self.assertVerify("other_pw", items[1]['password'])

    def test_hash_on_update(self):
        """Test hash on update. Works like test for hash on insert."""
        with self.app.app_context():
            data = {'password': "some_pw"}

            # Second param is original data, but the hash function ignores
            # it so we can just set it to None

            hash_on_update(data, None)