class User: def __init__(self, username, password, steem): self._username = username self._passwd = password self._steem = steem self._ipfsapi = get_ipfsapi() self._cur_post = None @staticmethod def get_videos_list(query): return get_chain_master().get_videos_list(query) @staticmethod def get_video_unauthorized(name, path): video_metadata = get_chain_master().get_video_metadata(name) multihash = video_metadata['multihash'] get_ipfsapi().get_video(multihash, path) return video_metadata def get_video(self, name, path): video_metadata = User.get_video_unauthorized(name, path) self._cur_post = Post( { 'author': video_metadata['author'], 'permlink': video_metadata['name'], }, self._steem) return self._cur_post def add_video(self, name, path, description=None, miniature_url=None): description = description or 'No description' miniature_url = miniature_url or self.get_miniature_url(path) result = self._ipfsapi.add_video(path) get_chain_master().add_video(name, self._username, description, result['Hash']) self._steem.commit.post(title=name, body=description + '\n' + miniature_url, author=self._username, permlink=name, default_parent_permlink='video') def vote_video(self, type): if not self._cur_post: raise RuntimeError('There is no post to vote') if type == VoteType.UP_VOTE: return self._cur_post.upvote(self._username) return self._cur_post.downvote(self._username) def get_miniature_url(self, path): return 'https://static.tumblr.com/5cc5658c2c9cd06cfc68747c9059bd6f/i9ytv5i/szXn6nvfq/tumblr_static_tumblr_static__640.jpg'
class Testcases(unittest.TestCase): def __init__(self, *args, **kwargs): super(Testcases, self).__init__(*args, **kwargs) self.post = Post(identifier, steem_instance=steem) def test_getOpeningPost(self): self.post._getOpeningPost() def test_reply(self): try: self.post.reply(body="foobar", title="", author=testaccount, meta=None) except InsufficientAuthorityError: pass except MissingKeyError: pass def test_upvote(self): try: self.post.upvote(voter=testaccount) except VotingInvalidOnArchivedPost: pass except InsufficientAuthorityError: pass except MissingKeyError: pass def test_downvote(self, weight=-100, voter=testaccount): try: self.post.downvote(voter=testaccount) except VotingInvalidOnArchivedPost: pass except InsufficientAuthorityError: pass except MissingKeyError: pass def test_edit(self): try: steem.edit(identifier, "Foobar") except InsufficientAuthorityError: pass except MissingKeyError: pass def test_post(self): try: steem.post("title", "body", meta={"foo": "bar"}, author=testaccount) except InsufficientAuthorityError: pass except MissingKeyError: pass def test_create_account(self): try: steem.create_account("xeroc-create", creator=testaccount, password="******", storekeys=False) except InsufficientAuthorityError: pass except MissingKeyError: pass def test_transfer(self): try: steem.transfer("fabian", 10, "STEEM", account=testaccount) except InsufficientAuthorityError: pass except MissingKeyError: pass def test_withdraw_vesting(self): try: steem.withdraw_vesting(10, account=testaccount) except InsufficientAuthorityError: pass except MissingKeyError: pass def test_transfer_to_vesting(self): try: steem.transfer_to_vesting(10, to=testaccount, account=testaccount) except InsufficientAuthorityError: pass except MissingKeyError: pass def test_get_replies(self): steem.get_replies(author=testaccount) def test_get_posts(self): steem.get_posts() def test_get_categories(self): steem.get_categories(sort="trending") def test_get_balances(self): steem.get_balances(testaccount) def test_getPost(self): self.assertEqual( Post("@xeroc/piston", steem_instance=steem).url, "/piston/@xeroc/piston") self.assertEqual( Post({ "author": "@xeroc", "permlink": "piston" }, steem_instance=steem).url, "/piston/@xeroc/piston")