def test_constructor(self): # config: default c1_dictionary_file = "tests/assets/csv_file_1.csv" c1 = Config(dictionary_file=c1_dictionary_file) self.assertTrue(c1.dictionary_type == c1.dictionary_type_default) self.assertTrue(c1.dictionary_type in c1.dictionary_type_available) self.assertTrue( c1.dictionary_encoding == c1.dictionary_encoding_default) self.assertTrue( c1.dictionary_encoding in c1.dictionary_encoding_available) self.assertTrue(c1.special_charlist == c1.special_charlist_default) self.assertTrue(c1.random_charlist == c1.random_charlist_default) self.assertTrue(c1.passphrase_compose == c1.passphrase_compose_default) self.assertTrue( c1.lookalikes_charlist == c1.lookalikes_charlist_default) # config: custom c2_dictionary_file = "tests/assets/csv_file_1.csv" c2_dictionary_type = "text" c2_dictionary_encoding = "utf8" c2_special_charlist = Config().ascii_charlist_lower c2_random_charlist = Config().ascii_charlist_lower c2_passphrase_compose = [['d', 3]] c2_lookalikes_charlist = ['a', 'b', 'c'] c2 = Config(c2_dictionary_file, c2_dictionary_type, c2_dictionary_encoding, c2_special_charlist, c2_random_charlist, c2_passphrase_compose, c2_lookalikes_charlist) self.assertTrue(c2.dictionary_type == c2_dictionary_type) self.assertTrue(c2.dictionary_type in c2.dictionary_type_available) self.assertTrue(c2.dictionary_encoding == c2_dictionary_encoding) self.assertTrue( c2.dictionary_encoding in c2.dictionary_encoding_available) self.assertTrue(c2.special_charlist == c2_special_charlist) self.assertTrue(c2.random_charlist == c2_random_charlist) self.assertTrue(c2.passphrase_compose == c2_passphrase_compose) self.assertTrue(c2.lookalikes_charlist == c2_lookalikes_charlist)
def test_getrandom_length(self): # config: special_charlist = default c1 = Config(value_validation=False) l1 = 15 r1 = GenSpecial(c1).get_random(l1) self.assertTrue(len(r1) == l1) self.assertTrue(isinstance(r1, str)) # config: special_charlist = custom c2 = Config(special_charlist=['!', '§', '$', '%', '&', '&'], value_validation=False) l2 = 15 r2 = GenSpecial(c2).get_random(l2) self.assertTrue(len(r2) == l2) self.assertTrue(isinstance(r2, str))
def test_processlist(self): # config: dictionary test c1 = Config(value_validation=False, passphrase_compose=[['d', 5]]) a1 = 3 l1 = 5 r1 = Gen(c1).process_list(a1) self.assertTrue(len(r1) == a1) self.assertTrue(len(r1[0]) == l1) self.assertTrue(isinstance(r1, list)) # config: random test c2 = Config(value_validation=False, passphrase_compose=[['r', 5]]) a2 = 3 l2 = 5 r2 = Gen(c2).process_list(a2) self.assertTrue(len(r2) == a2) self.assertTrue(len(r2[0]) == l2) self.assertTrue(isinstance(r2, list)) # config: special test c3 = Config(value_validation=False, passphrase_compose=[['s', 5]]) a3 = 3 l3 = 5 r3 = Gen(c3).process_list(a3) self.assertTrue(len(r3) == a3) self.assertTrue(len(r3[0]) == l3) self.assertTrue(isinstance(r3, list)) # config: custom complete c4 = Config(value_validation=False, passphrase_compose=[['d', 5], ['r', 5], ['s', 5]]) a4 = 3 l4 = 15 r4 = Gen(c4).process_list(a4) self.assertTrue(len(r4) == a4) self.assertTrue(len(r4[0]) == l4) self.assertTrue(isinstance(r4, list)) # config: custom complete multiple c5 = Config(value_validation=False, passphrase_compose=[['d', 5], ['r', 5], ['s', 5], ['d', 5], ['r', 5], ['s', 5]]) a5 = 3 l5 = 30 r5 = Gen(c5).process_list(a5) self.assertTrue(len(r5) == a5) self.assertTrue(len(r5[0]) == l5) self.assertTrue(isinstance(r5, list))
def test_dictionary_type_text(self): c1 = Config(value_validation=False, dictionary_file=self.assets_text1, dictionary_type='text') a1 = 6 l1 = 3 o1 = GenDictionary(c1) r1 = o1.get_random(l1) self.assertTrue(len(r1) == l1) self.assertTrue(isinstance(r1, str)) self.assertTrue(len(o1.data_memcache) == a1)
def test_process(self): # config: dictionary test c1 = Config(value_validation=False, passphrase_compose=[['d', 5]]) l1 = 5 r1 = Gen(c1).process() self.assertTrue(len(r1) == l1) self.assertTrue(isinstance(r1, str)) # config: random test c2 = Config(value_validation=False, passphrase_compose=[['r', 5]]) l2 = 5 r2 = Gen(c2).process() self.assertTrue(len(r2) == l2) self.assertTrue(isinstance(r2, str)) # config: special test c3 = Config(value_validation=False, passphrase_compose=[['s', 5]]) l3 = 5 r3 = Gen(c3).process() self.assertTrue(len(r3) == l3) self.assertTrue(isinstance(r3, str)) # config: custom complete c4 = Config(value_validation=False, passphrase_compose=[['d', 5], ['r', 5], ['s', 5]]) l4 = 15 r4 = Gen(c4).process() self.assertTrue(len(r4) == l4) self.assertTrue(isinstance(r4, str)) # config: custom complete multiple c5 = Config(value_validation=False, passphrase_compose=[['d', 5], ['r', 5], ['s', 5], ['d', 5], ['r', 5], ['s', 5]]) l5 = 30 r5 = Gen(c5).process() self.assertTrue(len(r5) == l5) self.assertTrue(isinstance(r5, str))
def test_getrandom(self): # config: special_charlist = default c1 = Config(value_validation=False) l1 = 15 r1 = GenRandom(c1).get_random(l1) self.assertTrue(len(r1) == l1) self.assertTrue(isinstance(r1, str)) # config: special_charlist = custom < 4 chars c2 = Config(random_charlist=['a', 'A', '?', '1', 'e', '2'], value_validation=False) l2 = 2 r2 = GenRandom(c2).get_random(l2) self.assertTrue(len(r2) == l2) self.assertTrue(isinstance(r2, str)) # config: special_charlist = custom > 4 chars c3 = Config(random_charlist=['a', 'A', '?', '1', 'e', '2'], value_validation=False) l3 = 15 r3 = GenRandom(c3).get_random(l3) self.assertTrue(len(r3) == l3) self.assertTrue(isinstance(r3, str))
def test_dictionary_type_csv(self): # csv: separated by "," c1 = Config(value_validation=False, dictionary_file=self.assets_csv1, dictionary_type='csv') a1 = 6 l1 = 3 o1 = GenDictionary(c1) r1 = o1.get_random(l1) self.assertTrue(len(r1) == l1) self.assertTrue(isinstance(r1, str)) self.assertTrue(len(o1.data_memcache) == a1) # csv: separated by ";" c2 = Config(value_validation=False, dictionary_file=self.assets_csv2, dictionary_type='csv') a2 = 6 l2 = 3 o2 = GenDictionary(c1) r2 = o2.get_random(l2) self.assertTrue(len(r2) == l2) self.assertTrue(isinstance(r2, str)) self.assertTrue(len(o2.data_memcache) == a2) # csv: separated by " " c3 = Config(value_validation=False, dictionary_file=self.assets_csv3, dictionary_type='csv') a3 = 6 l3 = 3 o3 = GenDictionary(c1) r3 = o3.get_random(l3) self.assertTrue(len(r3) == l3) self.assertTrue(isinstance(r3, str)) self.assertTrue(len(o3.data_memcache) == a3)
def test_exporthr(self): c1 = Config() self.assertTrue(isinstance(c1.exporthr(), str))
def test_export(self): c1 = Config() self.assertTrue(isinstance(c1.export(), dict))