import unittest

import password_hashing


class TestPasswordHash(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.hash_of_b_password = password_hashing.create_hash(b'b_password')
        cls.hash_of_u_password = password_hashing.create_hash(u'u_password')

    def test_create_hash_b(self):
        password_hashing.create_hash(b'test_password')

    def test_create_hash_u(self):
        password_hashing.create_hash(u'test_password')

    def test_successful_validation_b2b(self):
        self.assertTrue(
            password_hashing.validate_password(
                b'b_password',
                TestPasswordHash.hash_of_b_password))

    def test_successful_validation_u2u(self):
        self.assertTrue(
            password_hashing.validate_password(
                u'u_password',
                TestPasswordHash.hash_of_u_password))

    def test_successful_validation_b2u(self):
        self.assertTrue(
            password_hashing.validate_password(
                b'u_password',
                TestPasswordHash.hash_of_u_password))

    def test_successful_validation_u2b(self):
        self.assertTrue(
            password_hashing.validate_password(
                u'b_password',
                TestPasswordHash.hash_of_b_password))

    def test_unsuccessful_validation_b2b(self):
        self.assertFalse(
            password_hashing.validate_password(
                b'wrong_password',
                TestPasswordHash.hash_of_b_password))

    def test_unsuccessful_validation_u2u(self):
        self.assertFalse(
            password_hashing.validate_password(
                u'wrong_password',
                TestPasswordHash.hash_of_u_password))

    def test_unsuccessful_validation_b2u(self):
        self.assertFalse(
            password_hashing.validate_password(
                b'wrong_password',
                TestPasswordHash.hash_of_u_password))

    def test_unsuccessful_validation_u2b(self):
        self.assertFalse(
            password_hashing.validate_password(
                u'wrong_password',
                TestPasswordHash.hash_of_b_password))


if __name__ == '__main__':
    unittest.main()

@@ -8,16 +8,44 @@
 unittest
+%0Aimport random%0Aimport string
 %0A%0Aimport
@@ -116,44 +116,638 @@
    @
-classmethod%0A    def setUpClass(cls):
+staticmethod%0A    def generate_b_str(size=12):%0A        available_chars = string.printable.encode('utf-8')%0A        return b''.join(random.choice(available_chars) for _ in range(size))%0A%0A    @staticmethod%0A    def generate_u_str(size=12):%0A        available_chars = string.printable%0A        return u''.join(random.choice(available_chars) for _ in range(size))%0A%0A    @classmethod%0A    def setUpClass(cls):%0A        cls.b_password = TestPasswordHash.generate_b_str()%0A        cls.u_password = TestPasswordHash.generate_u_str()%0A        cls.u_b_password = cls.b_password.decode('utf-8')%0A        cls.b_u_password = cls.u_password.encode('utf-8')
 %0A   
@@ -805,18 +805,20 @@
 te_hash(
-b'
+cls.
 b_passwo
@@ -819,17 +819,16 @@
 password
-'
 )%0A      
@@ -883,18 +883,20 @@
 te_hash(
-u'
+cls.
 u_passwo
@@ -889,33 +889,32 @@
 h(cls.u_password
-'
 )%0A%0A    def test_
@@ -975,24 +975,41 @@
 ash(
-b'test_p
+TestP
 assword
-'
+Hash.generate_b_str()
 )%0A%0A 
@@ -1082,24 +1082,41 @@
 ash(
-u'test_p
+TestP
 assword
-'
+Hash.generate_u_str()
 )%0A%0A 
@@ -1249,18 +1249,33 @@
         
-b'
+TestPasswordHash.
 b_passwo
@@ -1268,33 +1268,32 @@
 dHash.b_password
-'
 ,%0A              
@@ -1468,18 +1468,33 @@
         
-u'
+TestPasswordHash.
 u_passwo
@@ -1487,33 +1487,32 @@
 dHash.u_password
-'
 ,%0A              
@@ -1687,18 +1687,35 @@
         
-b'
+TestPasswordHash.b_
 u_passwo
@@ -1708,33 +1708,32 @@
 ash.b_u_password
-'
 ,%0A              
@@ -1908,18 +1908,35 @@
         
-u'
+TestPasswordHash.u_
 b_passwo
@@ -1929,33 +1929,32 @@
 ash.u_b_password
-'
 ,%0A              
@@ -2132,33 +2132,49 @@
         
-b'wrong_password'
+TestPasswordHash.generate_b_str()
 ,%0A      
@@ -2360,33 +2360,49 @@
         
-u'wrong_password'
+TestPasswordHash.generate_u_str()
 ,%0A      
@@ -2592,25 +2592,41 @@
     
-b'wrong_password'
+TestPasswordHash.generate_b_str()
 ,%0A  
@@ -2820,25 +2820,41 @@
     
-u'wrong_password'
+TestPasswordHash.generate_u_str()
 ,%0A  

Add element of randomness to test cases, to ensure it works 'in general'