def test_generate_password(self): passp = Passphrase() self.assertRaises(ValueError, passp.generate_password) passp.password_use_lowercase = False passp.password_use_uppercase = False passp.password_use_digits = False passp.password_use_punctuation = False self.assertRaises(ValueError, passp.generate_password) passp.passwordlen = 77 self.assertRaises(ValueError, passp.generate_password)
def test_password_use_digits(self): passp = Passphrase() passp.separator = '' passp.passwordlen = 5 passp.password_use_lowercase = False passp.password_use_uppercase = False passp.password_use_digits = True passp.password_use_punctuation = False passp.generate_password() self.assertRegex(str(passp), r'[\d]+')
def test_password_use_punctuation(self): passp = Passphrase() passp.separator = '' passp.passwordlen = 5 passp.password_use_lowercase = False passp.password_use_uppercase = False passp.password_use_digits = False passp.password_use_punctuation = True passp.generate_password() self.assertRegex( str(passp), r'[\!\"\#\$\%\&\\\'\(\)\*\+\,\-\.\/\:\;\<\=\>\?\@\[\]\^\_' r'\`\{\|\}\~]+')
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)