def test_generate(self): for _ in range(0, 1000): amount_w = randint(0, 10) amount_n = randint(0, 10) uppercase = randint(1, 5) passp = Passphrase() passp.load_internal_wordlist() passp.amount_w = amount_w passp.amount_n = amount_n passphrase = passp.generate(uppercase) self.assertIsInstance(passphrase, list) self.assertEqual(len(passphrase), amount_w + amount_n) if amount_w > 0: # Perhaps it was requested just 1 word, and many uppercase # chars, but the word happens to be just 3 chars long... chars = Aux.chars_count(passphrase) if chars < uppercase: self.assertTrue(str(passphrase).isupper()) else: self.assertEqual(Aux.uppercase_count(passphrase), uppercase) passp.generate(0) self.assertTrue(str(passp).isupper()) lowercase = randint(-5, -1) passphrase = passp.generate(lowercase) chars = Aux.chars_count(passphrase) if chars < (lowercase * -1): self.assertTrue(str(passphrase).islower()) else: self.assertEqual(Aux.lowercase_count(passphrase), lowercase * -1)
def test_separator(self): passp = Passphrase('internal') passp.amount_w = 1 passp.amount_n = 1 passp.separator = '-.-' passp.generate() self.assertIn('-.-', str(passp))
def test_to_string(self): passp = Passphrase() passp.load_internal_wordlist() passphrase = str(passp) self.assertEqual(len(passphrase), 0) passp.amount_n = 1 passp.amount_w = 1 passp.generate() passphrase = str(passp) self.assertIsInstance(passphrase, str) self.assertTrue(len(passphrase) > 0)
def test_generate(self): passp = Passphrase() self.assertRaises(ValueError, passp.generate) passp.amount_n = 0 self.assertRaises(ValueError, passp.generate) passp.amount_w = 0 self.assertRaises(ValueError, passp.generate) passp.load_internal_wordlist() self.assertEqual(passp.generate(), []) for wrongtype in constants.WRONGTYPES_INT: self.assertRaises(TypeError, passp.generate, wrongtype)