def test_file(self): file_m = dict(name="hello", data=b"SGVsbG8gV29ybGQ=") file = appier.File(file_m) self.assertEqual(type(file.file_name), str) self.assertEqual(type(file.data_b64), str) self.assertEqual(type(file.data), appier.legacy.BYTES) self.assertEqual(file.file_name, "hello") self.assertEqual(file.data, b"Hello World") self.assertEqual(file.data_b64, "SGVsbG8gV29ybGQ=") file_d = b"Hello World" file = appier.File(file_d) self.assertEqual(type(file.file_name), str) self.assertEqual(type(file.data_b64), str) self.assertEqual(type(file.data), appier.legacy.BYTES) self.assertEqual(file.file_name, "default") self.assertEqual(file.data, b"Hello World") self.assertEqual(file.data_b64, "SGVsbG8gV29ybGQ=")
def _set_avatar_d(self, image="avatar.png", mime="image/png"): if not hasattr(self.owner, "admin_part"): return if not self.owner.admin_part: return if not self.owner.admin_avatar_default: return admin_part = self.owner.admin_part file = open(admin_part.static_path + "/images/" + image, "rb") try: data = file.read() finally: file.close() file_t = (image, mime, data) self.avatar = appier.File(file_t)