# Path: provy/more/debian/users/passwd_utils.py
# def random_salt_function(salt_len=12):
#     """
#     Creates random salt for password.
# 
#     :param salt_len: Length of salt. Default :data:`12`
#     :type param: :class:`int`
# 
#     :return: Computed salt
#     :rtype: str
#     """
#     charset = "abcdefghijklmnopqrstuxyz"
#     charset = charset + charset.upper() + '1234567890'
#     chars = []
#     rand = SystemRandom()
#     for _ in range(salt_len):
#         chars.append(rand.choice(charset))
#     return "".join(chars)
# 
# def hash_password_function(password, salt=None, magic="6"):
#     """
#     Hashes password using `crypt` function on local machine (which is not harmfull,
#     since these hashes are well-specified.
# 
#     :param password: Plaintext password to be hashed.
#     :type password: :class:`str`
#     :param salt: Salt to be used with this password, if None will
#         use random password.
#     :type salt: :class:`str`
#     :param magic: Specifies salt type. Default :data:`6` which means
#         use `sha-512`. For all appropriate values refer
#         to http://man7.org/linux/man-pages/man3/crypt.3.html#NOTES, or
#         (even better) consult `man 3 crypt` on your system.
#     :type salt: :class:`str` or :class:`int`
# 
#     :return: remote password
#     """
# 
#     magic = str(magic)
# 
#     if salt is None:
#         salt = random_salt_function()
# 
#     salt = "${magic}${salt}".format(magic=magic, salt=salt)
# 
#     return crypt.crypt(password, salt)


import unittest
from nose.tools import istest
from mock import patch
from provy.more.debian.users.passwd_utils import random_salt_function, hash_password_function
# -*- coding: utf-8 -*-



class PasswdUtilsTest(unittest.TestCase):

    @istest
    def check_if_two_generated_salts_are_different(self):
        """
        Instead of checking if output is truly random, we'll just check if
        in two conseutive calls different functions will be returned
        """
        self.assertNotEqual(random_salt_function(), random_salt_function())

    @istest
    def check_random_add_function_output_is_as_specified(self):

# Path: provy/more/debian/users/passwd_utils.py
# def random_salt_function(salt_len=12):
#     """
#     Creates random salt for password.
# 
#     :param salt_len: Length of salt. Default :data:`12`
#     :type param: :class:`int`
# 
#     :return: Computed salt
#     :rtype: str
#     """
#     charset = "abcdefghijklmnopqrstuxyz"
#     charset = charset + charset.upper() + '1234567890'
#     chars = []
#     rand = SystemRandom()
#     for _ in range(salt_len):
#         chars.append(rand.choice(charset))
#     return "".join(chars)
# 
# def hash_password_function(password, salt=None, magic="6"):
#     """
#     Hashes password using `crypt` function on local machine (which is not harmfull,
#     since these hashes are well-specified.
# 
#     :param password: Plaintext password to be hashed.
#     :type password: :class:`str`
#     :param salt: Salt to be used with this password, if None will
#         use random password.
#     :type salt: :class:`str`
#     :param magic: Specifies salt type. Default :data:`6` which means
#         use `sha-512`. For all appropriate values refer
#         to http://man7.org/linux/man-pages/man3/crypt.3.html#NOTES, or
#         (even better) consult `man 3 crypt` on your system.
#     :type salt: :class:`str` or :class:`int`
# 
#     :return: remote password
#     """
# 
#     magic = str(magic)
# 
#     if salt is None:
#         salt = random_salt_function()
# 
#     salt = "${magic}${salt}".format(magic=magic, salt=salt)
# 
#     return crypt.crypt(password, salt)


# Path: tests/unit/more/debian/users/test_passwd_utils.py
import unittest
from nose.tools import istest
from mock import patch
from provy.more.debian.users.passwd_utils import random_salt_function, hash_password_function

# -*- coding: utf-8 -*-



class PasswdUtilsTest(unittest.TestCase):

    @istest
    def check_if_two_generated_salts_are_different(self):
        """
        Instead of checking if output is truly random, we'll just check if
        in two conseutive calls different functions will be returned
        """
        self.assertNotEqual(random_salt_function(), random_salt_function())

    @istest
    def check_random_add_function_output_is_as_specified(self):

        self.assertEqual(len(random_salt_function(salt_len=125)), 125)