def test_clean(): ok = (' !#%$&)(+*-1032547698;:=?@acbedgfihkjmlonqpsrutwvyxzABCDEFGHIJ' 'KLMNOPQRSTUVWXYZ') invalids = ['foo bar`', 'bar baz~'] assert crypto_util.clean(ok) == ok for invalid in invalids: with pytest.raises(CryptoException) as err: crypto_util.clean(invalid) assert 'invalid input: {}'.format(invalid) in str(err)
def test_clean(self): ok = (' !#%$&)(+*-1032547698;:=?@acbedgfihkjmlonqpsrutwvyxzABCDEFGHIJ' 'KLMNOPQRSTUVWXYZ') invalid_1 = 'foo bar`' invalid_2 = 'bar baz~' self.assertEqual(ok, crypto_util.clean(ok)) with self.assertRaisesRegexp(crypto_util.CryptoException, 'invalid input: {}'.format(invalid_1)): crypto_util.clean(invalid_1) with self.assertRaisesRegexp(crypto_util.CryptoException, 'invalid input: {}'.format(invalid_2)): crypto_util.clean(invalid_2)
def test_genrandomid(self): id = crypto_util.genrandomid() id_words = id.split() self.assertEqual(id, crypto_util.clean(id)) self.assertEqual(len(id_words), crypto_util.DEFAULT_WORDS_IN_RANDOM_ID) for word in id_words: self.assertIn(word, crypto_util.words)
def verify_genrandomid(self, locale): id = crypto_util.genrandomid(locale=locale) id_words = id.split() self.assertEqual(id, crypto_util.clean(id)) self.assertEqual(len(id_words), crypto_util.DEFAULT_WORDS_IN_RANDOM_ID) for word in id_words: self.assertIn(word, crypto_util._get_wordlist(locale))
def verify_genrandomid(app, locale): id = app.crypto_util.genrandomid(locale=locale) id_words = id.split() assert crypto_util.clean(id) == id assert len(id_words) == CryptoUtil.DEFAULT_WORDS_IN_RANDOM_ID for word in id_words: assert word in app.crypto_util.get_wordlist(locale)
def test_clean(self): with self.assertRaises(crypto_util.CryptoException): crypto_util.clean('foo bar`') # backtick is not currently allowed with self.assertRaises(crypto_util.CryptoException): crypto_util.clean('bar baz~') # tilde is not currently allowed