Skip to content

Commit

Permalink
Add more unit tests and fix hive replacement for beempy post
Browse files Browse the repository at this point in the history
  • Loading branch information
holgern committed Jun 29, 2020
1 parent cd7ea6f commit 64a1061
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Changelog
* Use Hive() on beempy when setting default_chain to "hive"
* Simplify chain identification
* Fix more Token symbols in beempy
* Fix unittest
* Fix unittest and add more unit tests

0.24.3
------
Expand Down
50 changes: 42 additions & 8 deletions beem/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2430,7 +2430,10 @@ def download(permlink, account, save, export):
yaml_prefix += 'app: %s\n' % comment.json_metadata["app"]
yaml_prefix += 'last_update: %s\n' % comment.json()["last_update"]
yaml_prefix += 'max_accepted_payout: %s\n' % str(comment["max_accepted_payout"])
yaml_prefix += 'percent_steem_dollars: %s\n' % str(comment["percent_steem_dollars"])
if "percent_steem_dollars" in comment:
yaml_prefix += 'percent_steem_dollars: %s\n' % str(comment["percent_steem_dollars"])
else:
yaml_prefix += 'percent_hive_dollars: %s\n' % str(comment["percent_hive_dollars"])
if "tags" in comment.json_metadata:
if len(comment.json_metadata["tags"]) > 0 and comment["category"] != comment.json_metadata["tags"][0] and len(comment["category"]) > 0:
yaml_prefix += 'community: %s\n' % comment["category"]
Expand Down Expand Up @@ -2464,9 +2467,10 @@ def download(permlink, account, save, export):
@click.option('--community', '-c', help=' Name of the community (optional)')
@click.option('--beneficiaries', '-b', help='Post beneficiaries (komma separated, e.g. a:10%,b:20%)')
@click.option('--percent-steem-dollars', '-d', help='50% SBD /50% SP is 10000 (default), 100% SP is 0')
@click.option('--percent-hive-dollars', '-d', help='50% SBD /50% SP is 10000 (default), 100% SP is 0')
@click.option('--max-accepted-payout', '-m', help='Default is 1000000.000 [SBD]')
@click.option('--no-parse-body', '-n', help='Disable parsing of links, tags and images', is_flag=True, default=False)
def createpost(markdown_file, account, title, tags, community, beneficiaries, percent_steem_dollars, max_accepted_payout, no_parse_body):
def createpost(markdown_file, account, title, tags, community, beneficiaries, percent_steem_dollars, percent_hive_dollars, max_accepted_payout, no_parse_body):
"""Creates a new markdown file with YAML header"""
stm = shared_blockchain_instance()
if stm.rpc is not None:
Expand All @@ -2482,23 +2486,35 @@ def createpost(markdown_file, account, title, tags, community, beneficiaries, pe
community = input("community account:")
if beneficiaries is None:
beneficiaries = input("beneficiaries (komma separated, e.g. a:10%,b:20%):")
if percent_steem_dollars is None:
if percent_steem_dollars is None and percent_hive_dollars is None:
ret = None
while ret is None:
ret = input("Reward: 50% or 100% Hive Power [50 or 100]?")
ret = input("50% or 100% Steem/Hive Power as post reward [50 or 100]? ")
if ret not in ["50", "100"]:
ret = None
if ret == "50":
percent_steem_dollars = 10000
percent_hive_dollars = 10000
else:
percent_steem_dollars = 0
percent_hive_dollars = 0
elif percent_steem_dollars is not None and percent_hive_dollars is not None:
raise ValueError("percent_hive_dollars and percent_steem_dollars cannot be both set.")
elif percent_steem_dollars is None:
percent_steem_dollars = percent_hive_dollars
elif percent_hive_dollars is None:
percent_hive_dollars = percent_steem_dollars

if max_accepted_payout is None:
max_accepted_payout = input("max accepted payout [return to skip]: ")

yaml_prefix += 'title: "%s"\n' % title
yaml_prefix += 'author: %s\n' % account
yaml_prefix += 'tags: %s\n' % tags
yaml_prefix += 'percent_steem_dollars: %d\n' % percent_steem_dollars
if stm.is_hive and not stm.get_replace_hive_by_steem():
yaml_prefix += 'percent_hive_dollars: %d\n' % percent_hive_dollars
else:
yaml_prefix += 'percent_steem_dollars: %d\n' % percent_steem_dollars
if community is not None and community != "":
yaml_prefix += 'community: %s\n' % community
if beneficiaries is not None and beneficiaries != "":
Expand All @@ -2521,11 +2537,12 @@ def createpost(markdown_file, account, title, tags, community, beneficiaries, pe
@click.option('--canonical-url', '-u', help='Canonical url, can also set to https://hive.blog or https://peakd.com (optional)')
@click.option('--beneficiaries', '-b', help='Post beneficiaries (komma separated, e.g. a:10%,b:20%)')
@click.option('--percent-steem-dollars', '-d', help='50% SBD /50% SP is 10000 (default), 100% SP is 0')
@click.option('--percent-hive-dollars', '-d', help='50% SBD /50% SP is 10000 (default), 100% SP is 0')
@click.option('--max-accepted-payout', '-m', help='Default is 1000000.000 [SBD]')
@click.option('--no-parse-body', '-n', help='Disable parsing of links, tags and images', is_flag=True, default=False)
@click.option('--no-patch-on-edit', '-e', help='Disable patch posting on edits (when the permlink already exists)', is_flag=True, default=False)
@click.option('--export', help='When set, transaction is stored in a file')
def post(markdown_file, account, title, permlink, tags, reply_identifier, community, canonical_url, beneficiaries, percent_steem_dollars, max_accepted_payout, no_parse_body, no_patch_on_edit, export):
def post(markdown_file, account, title, permlink, tags, reply_identifier, community, canonical_url, beneficiaries, percent_steem_dollars, percent_hive_dollars, max_accepted_payout, no_parse_body, no_patch_on_edit, export):
"""broadcasts a post/comment. All image links which links to a file will be uploaded.
The yaml header can contain:
Expand Down Expand Up @@ -2562,6 +2579,10 @@ def post(markdown_file, account, title, permlink, tags, reply_identifier, commun
parameter["percent_steem_dollars"] = percent_steem_dollars
elif "percent-steem-dollars" in parameter:
parameter["percent_steem_dollars"] = parameter["percent-steem-dollars"]
if percent_hive_dollars is not None:
parameter["percent_hive_dollars"] = percent_hive_dollars
elif "percent-hive-dollars" in parameter:
parameter["percent_hive_dollars"] = parameter["percent-hive-dollars"]
if max_accepted_payout is not None:
parameter["max_accepted_payout"] = max_accepted_payout
elif "max-accepted-payout" in parameter:
Expand Down Expand Up @@ -2600,6 +2621,9 @@ def post(markdown_file, account, title, permlink, tags, reply_identifier, commun
percent_steem_dollars = None
if "percent_steem_dollars" in parameter:
percent_steem_dollars = parameter["percent_steem_dollars"]
percent_hive_dollars = None
if "percent_hive_dollars" in parameter:
percent_hive_dollars = parameter["percent_hive_dollars"]
max_accepted_payout = None
if "max_accepted_payout" in parameter:
max_accepted_payout = parameter["max_accepted_payout"]
Expand All @@ -2610,8 +2634,15 @@ def post(markdown_file, account, title, permlink, tags, reply_identifier, commun
if stm.backed_token_symbol not in max_accepted_payout:
max_accepted_payout = str(Amount(float(max_accepted_payout), stm.backed_token_symbol, blockchain_instance=stm))
comment_options["max_accepted_payout"] = max_accepted_payout
if percent_steem_dollars is not None:
if percent_hive_dollars is not None and stm.is_hive and not stm.get_replace_hive_by_steem():
comment_options["percent_hive_dollars"] = percent_hive_dollars
elif percent_steem_dollars is not None and stm.is_hive and not stm.get_replace_hive_by_steem():
comment_options["percent_hive_dollars"] = percent_steem_dollars
elif percent_steem_dollars is not None:
comment_options["percent_steem_dollars"] = percent_steem_dollars
elif percent_hive_dollars is not None:
comment_options["percent_steem_dollars"] = percent_hive_dollars

beneficiaries = None
if "beneficiaries" in parameter:
beneficiaries = derive_beneficiaries(parameter["beneficiaries"])
Expand Down Expand Up @@ -3338,10 +3369,11 @@ def unfollow(unfollow, account, export):
@click.option('--maximum_block_size', help='Max block size')
@click.option('--account_creation_fee', help='Account creation fee')
@click.option('--sbd_interest_rate', help='SBD interest rate in percent')
@click.option('--hbd_interest_rate', help='HBD interest rate in percent')
@click.option('--url', help='Witness URL')
@click.option('--signing_key', help='Signing Key')
@click.option('--export', '-e', help='When set, transaction is stored in a file')
def witnessupdate(witness, maximum_block_size, account_creation_fee, sbd_interest_rate, url, signing_key, export):
def witnessupdate(witness, maximum_block_size, account_creation_fee, sbd_interest_rate, hbd_interest_rate, url, signing_key, export):
"""Change witness properties"""
stm = shared_blockchain_instance()
if stm.rpc is not None:
Expand All @@ -3359,6 +3391,8 @@ def witnessupdate(witness, maximum_block_size, account_creation_fee, sbd_interes
props["maximum_block_size"] = int(maximum_block_size)
if sbd_interest_rate is not None:
props["sbd_interest_rate"] = int(float(sbd_interest_rate) * 100)
if hbd_interest_rate is not None:
props["hbd_interest_rate"] = int(float(hbd_interest_rate) * 100)
tx = witness.update(signing_key or witness["signing_key"], url or witness["url"], props)
if stm.unsigned and stm.nobroadcast and stm.steemconnect is not None:
tx = stm.steemconnect.url_from_tx(tx)
Expand Down
31 changes: 31 additions & 0 deletions tests/beem/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,11 +399,37 @@ def test_claimreward(self):
result = runner.invoke(cli, ['-dx', 'claimreward', '--claim_all_vests'], input="test\n")
self.assertEqual(result.exit_code, 0)

def test_claimaccount(self):
runner = CliRunner()
result = runner.invoke(cli, ['-dx', 'claimaccount', 'holger80'], input="test\n")
result = runner.invoke(cli, ['-dx', 'claimaccount', '-n', '2', 'holger80'], input="test\n")
self.assertEqual(result.exit_code, 0)

def test_power(self):
runner = CliRunner()
result = runner.invoke(cli, ['power', 'holger80'])
self.assertEqual(result.exit_code, 0)

def test_history(self):
runner = CliRunner()
result = runner.invoke(cli, ['history', 'holger80'])
self.assertEqual(result.exit_code, 0)

def test_draw(self):
runner = CliRunner()
result = runner.invoke(cli, ['draw'])
self.assertEqual(result.exit_code, 0)

def test_witnessenable(self):
runner = CliRunner()
result = runner.invoke(cli, ['-dx', 'witnessenable', 'holger80', 'STM1111111111111111111111111111111114T1A'])
self.assertEqual(result.exit_code, 0)

def test_witnessdisable(self):
runner = CliRunner()
result = runner.invoke(cli, ['-dx', 'witnessdisable', 'holger80'])
self.assertEqual(result.exit_code, 0)

def test_nextnode(self):
runner = CliRunner()
runner.invoke(cli, ['-o', 'set', 'nodes', self.node_list])
Expand Down Expand Up @@ -454,6 +480,11 @@ def test_pricehistory(self):
result = runner.invoke(cli, ['pricehistory'])
self.assertEqual(result.exit_code, 0)

def test_notifications(self):
runner = CliRunner()
result = runner.invoke(cli, ['notifications', 'fullnodeupdate'])
self.assertEqual(result.exit_code, 0)

def test_pending(self):
runner = CliRunner()
account_name = "fullnodeupdate"
Expand Down

0 comments on commit 64a1061

Please sign in to comment.