Example #1
0
    def test_password_length_needed(self):
        passp = Passphrase()
        for wrongtype in constants.WRONGTYPES_INT_FLOAT:
            passp._entropy_bits_req = wrongtype
            with self.assertRaises(TypeError) as context:
                passp.password_length_needed()
            self.assertIn('entropybits can only be int or float',
                          str(context.exception))

        passp._entropy_bits_req = -1
        with self.assertRaises(ValueError) as context:
            passp.password_length_needed()
        self.assertIn('entropybits should be greater than 0',
                      str(context.exception))
        passp = Passphrase()
        self.assertRaises(ValueError, passp.password_length_needed)
        passp.password_use_lowercase = False
        passp.password_use_uppercase = False
        passp.password_use_digits = False
        passp.password_use_punctuation = False
        self.assertRaises(ValueError, passp.password_length_needed)
        passp.entropy_bits_req = 77
        self.assertRaises(ValueError, passp.password_length_needed)
Example #2
0
 def test_password_length_needed(self):
     passp = Passphrase()
     passp.entropy_bits_req = 128
     p_len = passp.password_length_needed()
     self.assertEqual(p_len, 20)