def base64_decode(obj): """ Decode using base64 :param obj: :return: """ return mark_safe(Str.base64_decode(obj))
class StrTest(SimpleTestCase): def test_str(self): self.assertEqual(Str.casefold('ViỆt Nam'), Str.casefold('việt nam')) self.assertTrue(Str.eq('a', 'A')) self.assertFalse(Str.eq('a', 'A', case=True)) self.assertTrue(Str.contains("Hello", "hell")) self.assertFalse(Str.contains("Hello", "hell", case=True)) # base64 plain_str = 'hello world!' b64 = 'aGVsbG8gd29ybGQh' self.assertEqual(Str.base64_encode(plain_str), b64) self.assertEqual(Str.base64_decode(b64), plain_str) plain_str = 'this is a test' b64 = 'dGhpcyBpcyBhIHRlc3Q=' self.assertEqual(Str.base64_encode(plain_str), b64) self.assertEqual(Str.base64_decode(b64), plain_str) # is_int() self.assertTrue(Str.is_int('0')) self.assertTrue(Str.is_int('1')) self.assertTrue(Str.is_int('-1')) self.assertFalse(Str.is_int('1.0')) self.assertFalse(Str.is_int('-1.0')) self.assertFalse(Str.is_int('-0')) self.assertFalse(Str.is_int('- 70'))