# 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.assertItemsEqual(response.keys(), fields)

        assertFields(self.other_user, self.user_token, self.BASIC_FIELDS)
        assertFields(self.other_user, self.root_token, self.ALL_FIELDS)
        assertFields(self.user, self.user_token, self.ALL_FIELDS)
        assertFields(self.user, self.root_token, self.ALL_FIELDS)

    def test_read_resource(self):
        """Same as test_read_item but with GET to resource."""
        self.create_users()
        self.api.get("/users", status_code=401)

        def assertFields(token, user_fields, other_user_fields):
            response = self.api.get("/users",
                                    token=token, status_code=200).json
            for item in response['_items']:
                if item['_id'] == str(self.user['_id']):
                    self.assertItemsEqual(item.keys(), user_fields)
                elif item['_id'] == str(self.other_user['_id']):
                    self.assertItemsEqual(item.keys(), other_user_fields)

        assertFields(self.user_token, self.ALL_FIELDS, self.BASIC_FIELDS)
        assertFields(self.root_token, self.ALL_FIELDS, self.ALL_FIELDS)

    def test_embedded_read(self):
        """Test that hide hooks are also called when embedding into another
        document."""
        self.app.register_resource('test', {
            'schema': {
                'user': {

# 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.assertItemsEqual(response.keys(), fields)

        assertFields(self.other_user, self.user_token, self.BASIC_FIELDS)
        assertFields(self.other_user, self.root_token, self.ALL_FIELDS)
        assertFields(self.user, self.user_token, self.ALL_FIELDS)
        assertFields(self.user, self.root_token, self.ALL_FIELDS)

    def test_read_resource(self):
        """Same as test_read_item but with GET to resource."""
        self.create_users()
        self.api.get("/users", status_code=401)

        def assertFields(token, user_fields, other_user_fields):
            response = self.api.get("/users",
                                    token=token, status_code=200).json
            for item in response['_items']:
                if item['_id'] == str(self.user['_id']):
                    self.assertItemsEqual(item.keys(), user_fields)
                elif item['_id'] == str(self.other_user['_id']):
                    self.assertItemsEqual(item.keys(), other_user_fields)

        assertFields(self.user_token, self.ALL_FIELDS, self.BASIC_FIELDS)
        assertFields(self.root_token, self.ALL_FIELDS, self.ALL_FIELDS)

    def test_embedded_read(self):
        """Test that hide hooks are also called when embedding into another
        document."""
        self.app.register_resource('test', {
            'schema': {
                'user': {

                    'data_relation': {