# 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)

    def test_hash_hooks(self):
        """Test hash hooks.

        Assert passwort is hashed when user is created or updated through
        the api.
        """
        post_data = {
            'firstname': 'T',
            'lastname': 'Estuser',
            'gender': 'female',
            'membership': 'regular',
            'email': 'test@user.amiv',
            'password': "some_pw"
        }

        user = self.api.post("/users", data=post_data, status_code=201).json

        self.assertVerifyDB(user['_id'], "some_pw")

        patch_data = {'password': "other_pw"}

        headers = {'If-Match': user['_etag']}
        user = self.api.patch("/users/%s" % user['_id'],
                              headers=headers, data=patch_data,
                              status_code=200).json

        self.assertVerifyDB(user['_id'], "other_pw")



# 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)


    def test_hash_hooks(self):
        """Test hash hooks.

        Assert passwort is hashed when user is created or updated through
        the api.
        """
        post_data = {
            'firstname': 'T',
            'lastname': 'Estuser',
            'gender': 'female',
            'membership': 'regular',
            'email': 'test@user.amiv',
            'password': "some_pw"
        }

        user = self.api.post("/users", data=post_data, status_code=201).json

        self.assertVerifyDB(user['_id'], "some_pw")

        patch_data = {'password': "other_pw"}

        headers = {'If-Match': user['_etag']}
        user = self.api.patch("/users/%s" % user['_id'],
                              headers=headers, data=patch_data,
                              status_code=200).json

        self.assertVerifyDB(user['_id'], "other_pw")



class UserFieldsTest(utils.WebTest):