Skip to content
Snippets Groups Projects
Commit ffb208de authored by Holger Nahrstaedt's avatar Holger Nahrstaedt
Browse files

Improve unit tests

parent ccda07cc
No related branches found
No related tags found
No related merge requests found
...@@ -31,26 +31,26 @@ class Testcases(unittest.TestCase): ...@@ -31,26 +31,26 @@ class Testcases(unittest.TestCase):
stm.config.refreshBackup() stm.config.refreshBackup()
runner = CliRunner() runner = CliRunner()
result = runner.invoke(cli, ['-o', 'set', 'default_vote_weight', '100']) result = runner.invoke(cli, ['-o', 'set', 'default_vote_weight', '100'])
if result != 0: if result.exit_code != 0:
raise AssertionError("setup failed!") raise AssertionError(str(result))
result = runner.invoke(cli, ['-o', 'set', 'default_account', 'beem']) result = runner.invoke(cli, ['-o', 'set', 'default_account', 'beem'])
if result != 0: if result.exit_code != 0:
raise AssertionError("setup failed!") raise AssertionError(str(result))
result = runner.invoke(cli, ['-o', 'set', 'nodes', 'wss://testnet.steem.vc']) result = runner.invoke(cli, ['-o', 'set', 'nodes', 'wss://testnet.steem.vc'])
if result != 0: if result.exit_code != 0:
raise AssertionError("setup failed!") raise AssertionError(str(result))
result = runner.invoke(cli, ['createwallet'], input="y\ntest\ntest\n") result = runner.invoke(cli, ['createwallet'], input="y\ntest\ntest\n")
if result != 0: if result.exit_code != 0:
raise AssertionError("setup failed!") raise AssertionError(str(result))
result = runner.invoke(cli, ['addkey'], input="test\n" + wif + "\n") result = runner.invoke(cli, ['addkey'], input="test\n" + wif + "\n")
if result != 0: if result.exit_code != 0:
raise AssertionError("setup failed!") raise AssertionError(str(result))
result = runner.invoke(cli, ['addkey'], input="test\n" + posting_key + "\n") result = runner.invoke(cli, ['addkey'], input="test\n" + posting_key + "\n")
if result != 0: if result.exit_code != 0:
raise AssertionError("setup failed!") raise AssertionError(str(result))
result = runner.invoke(cli, ['addkey'], input="test\n" + memo_key + "\n") result = runner.invoke(cli, ['addkey'], input="test\n" + memo_key + "\n")
if result != 0: if result.exit_code != 0:
raise AssertionError("setup failed!") raise AssertionError(str(result))
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
......
...@@ -10,7 +10,7 @@ from beem import Steem, exceptions ...@@ -10,7 +10,7 @@ from beem import Steem, exceptions
from beem.comment import Comment, RecentReplies, RecentByPath from beem.comment import Comment, RecentReplies, RecentByPath
from beem.vote import Vote from beem.vote import Vote
from beem.instance import set_shared_steem_instance from beem.instance import set_shared_steem_instance
from beem.utils import get_node_list from beem.utils import get_node_list, resolve_authorperm
wif = "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3" wif = "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"
...@@ -30,7 +30,12 @@ class Testcases(unittest.TestCase): ...@@ -30,7 +30,12 @@ class Testcases(unittest.TestCase):
keys={"active": wif}, keys={"active": wif},
num_retries=10 num_retries=10
) )
cls.authorperm = "@gtg/witness-gtg-log" cls.authorperm = "@gtg/ffdhu-gtg-witness-log"
[author, permlink] = resolve_authorperm(cls.authorperm)
cls.author = author
cls.permlink = permlink
cls.category = 'witness-category'
cls.title = 'gtg witness log'
# from getpass import getpass # from getpass import getpass
# self.bts.wallet.unlock(getpass()) # self.bts.wallet.unlock(getpass())
set_shared_steem_instance(cls.bts) set_shared_steem_instance(cls.bts)
...@@ -38,7 +43,7 @@ class Testcases(unittest.TestCase): ...@@ -38,7 +43,7 @@ class Testcases(unittest.TestCase):
cnt = 0 cnt = 0
title = '' title = ''
while cnt < 5 and title == '': while cnt < 5 and title == '':
c = Comment("@gtg/witness-gtg-log", steem_instance=cls.bts) c = Comment(cls.authorperm, steem_instance=cls.bts)
title = c["title"] title = c["title"]
cls.bts.rpc.next() cls.bts.rpc.next()
...@@ -55,16 +60,16 @@ class Testcases(unittest.TestCase): ...@@ -55,16 +60,16 @@ class Testcases(unittest.TestCase):
exceptions.ContentDoesNotExistsException exceptions.ContentDoesNotExistsException
): ):
Comment("@abcdef/abcdef", steem_instance=bts) Comment("@abcdef/abcdef", steem_instance=bts)
c = Comment("@gtg/witness-gtg-log", steem_instance=bts) c = Comment(self.authorperm, steem_instance=bts)
self.assertTrue(isinstance(c.id, int)) self.assertTrue(isinstance(c.id, int))
self.assertTrue(c.id > 0) self.assertTrue(c.id > 0)
self.assertEqual(c.author, "gtg") self.assertEqual(c.author, self.author)
self.assertEqual(c.permlink, "witness-gtg-log") self.assertEqual(c.permlink, self.permlink)
self.assertEqual(c.authorperm, "@gtg/witness-gtg-log") self.assertEqual(c.authorperm, self.authorperm)
self.assertEqual(c.category, 'witness-category') self.assertEqual(c.category, self.category)
self.assertEqual(c.parent_author, '') self.assertEqual(c.parent_author, '')
self.assertEqual(c.parent_permlink, 'witness-category') self.assertEqual(c.parent_permlink, self.category)
self.assertEqual(c.title, 'witness gtg log') self.assertEqual(c.title, self.title)
self.assertTrue(len(c.body) > 0) self.assertTrue(len(c.body) > 0)
for key in ['tags', 'users', 'image', 'links', 'app', 'format']: for key in ['tags', 'users', 'image', 'links', 'app', 'format']:
self.assertIn(key, list(c.json_metadata.keys())) self.assertIn(key, list(c.json_metadata.keys()))
...@@ -86,7 +91,7 @@ class Testcases(unittest.TestCase): ...@@ -86,7 +91,7 @@ class Testcases(unittest.TestCase):
bts = self.bts bts = self.bts
else: else:
bts = self.appbase bts = self.appbase
c = Comment("@gtg/witness-gtg-log", steem_instance=bts) c = Comment(self.authorperm, steem_instance=bts)
tx = c.vote(100, account="test") tx = c.vote(100, account="test")
self.assertEqual( self.assertEqual(
(tx["operations"][0][0]), (tx["operations"][0][0]),
...@@ -111,12 +116,12 @@ class Testcases(unittest.TestCase): ...@@ -111,12 +116,12 @@ class Testcases(unittest.TestCase):
def test_export(self, node_param): def test_export(self, node_param):
if node_param == "non_appbase": if node_param == "non_appbase":
bts = self.bts bts = self.bts
content = bts.rpc.get_content("gtg", "witness-gtg-log") content = bts.rpc.get_content(self.author, self.permlink)
else: else:
bts = self.appbase bts = self.appbase
content = bts.rpc.get_discussion({'author': 'gtg', 'permlink': 'witness-gtg-log'}, api="tags") content = bts.rpc.get_discussion({'author': self.author, 'permlink': self.permlink}, api="tags")
c = Comment("@gtg/witness-gtg-log", steem_instance=bts) c = Comment(self.authorperm, steem_instance=bts)
keys = list(content.keys()) keys = list(content.keys())
json_content = c.json() json_content = c.json()
...@@ -126,7 +131,7 @@ class Testcases(unittest.TestCase): ...@@ -126,7 +131,7 @@ class Testcases(unittest.TestCase):
def test_resteem(self): def test_resteem(self):
bts = self.bts bts = self.bts
c = Comment("@gtg/witness-gtg-log", steem_instance=bts) c = Comment(self.authorperm, steem_instance=bts)
tx = c.resteem(account="test") tx = c.resteem(account="test")
self.assertEqual( self.assertEqual(
(tx["operations"][0][0]), (tx["operations"][0][0]),
...@@ -135,7 +140,7 @@ class Testcases(unittest.TestCase): ...@@ -135,7 +140,7 @@ class Testcases(unittest.TestCase):
def test_reply(self): def test_reply(self):
bts = self.bts bts = self.bts
c = Comment("@gtg/witness-gtg-log", steem_instance=bts) c = Comment(self.authorperm, steem_instance=bts)
tx = c.reply(body="Good post!", author="test") tx = c.reply(body="Good post!", author="test")
self.assertEqual( self.assertEqual(
(tx["operations"][0][0]), (tx["operations"][0][0]),
...@@ -148,7 +153,7 @@ class Testcases(unittest.TestCase): ...@@ -148,7 +153,7 @@ class Testcases(unittest.TestCase):
def test_delete(self): def test_delete(self):
bts = self.bts bts = self.bts
c = Comment("@gtg/witness-gtg-log", steem_instance=bts) c = Comment(self.authorperm, steem_instance=bts)
tx = c.delete(account="test") tx = c.delete(account="test")
self.assertEqual( self.assertEqual(
(tx["operations"][0][0]), (tx["operations"][0][0]),
...@@ -156,12 +161,12 @@ class Testcases(unittest.TestCase): ...@@ -156,12 +161,12 @@ class Testcases(unittest.TestCase):
) )
op = tx["operations"][0][1] op = tx["operations"][0][1]
self.assertIn( self.assertIn(
"gtg", self.author,
op["author"]) op["author"])
def test_edit(self): def test_edit(self):
bts = self.bts bts = self.bts
c = Comment("@gtg/witness-gtg-log", steem_instance=bts) c = Comment(self.authorperm, steem_instance=bts)
c.edit(c.body, replace=False) c.edit(c.body, replace=False)
body = c.body + "test" body = c.body + "test"
tx = c.edit(body, replace=False) tx = c.edit(body, replace=False)
...@@ -171,12 +176,12 @@ class Testcases(unittest.TestCase): ...@@ -171,12 +176,12 @@ class Testcases(unittest.TestCase):
) )
op = tx["operations"][0][1] op = tx["operations"][0][1]
self.assertIn( self.assertIn(
"gtg", self.author,
op["author"]) op["author"])
def test_edit_replace(self): def test_edit_replace(self):
bts = self.bts bts = self.bts
c = Comment("@gtg/witness-gtg-log", steem_instance=bts) c = Comment(self.authorperm, steem_instance=bts)
body = c.body + "test" body = c.body + "test"
tx = c.edit(body, meta=c["json_metadata"], replace=True) tx = c.edit(body, meta=c["json_metadata"], replace=True)
self.assertEqual( self.assertEqual(
...@@ -185,13 +190,13 @@ class Testcases(unittest.TestCase): ...@@ -185,13 +190,13 @@ class Testcases(unittest.TestCase):
) )
op = tx["operations"][0][1] op = tx["operations"][0][1]
self.assertIn( self.assertIn(
"gtg", self.author,
op["author"]) op["author"])
self.assertEqual(body, op["body"]) self.assertEqual(body, op["body"])
def test_recent_replies(self): def test_recent_replies(self):
bts = self.bts bts = self.bts
r = RecentReplies("gtg", skip_own=True, steem_instance=bts) r = RecentReplies(self.author, skip_own=True, steem_instance=bts)
self.assertTrue(len(r) > 0) self.assertTrue(len(r) > 0)
self.assertTrue(r[0] is not None) self.assertTrue(r[0] is not None)
......
...@@ -134,7 +134,7 @@ class Testcases(unittest.TestCase): ...@@ -134,7 +134,7 @@ class Testcases(unittest.TestCase):
trades_raw = m.trades(limit=10, raw_data=True) trades_raw = m.trades(limit=10, raw_data=True)
trades_history = m.trade_history(limit=10) trades_history = m.trade_history(limit=10)
self.assertEqual(len(trades), 10) self.assertEqual(len(trades), 10)
self.assertEqual(len(trades_history), 10) self.assertTrue(len(trades_history) > 0)
self.assertEqual(len(trades_raw), 10) self.assertEqual(len(trades_raw), 10)
@parameterized.expand([ @parameterized.expand([
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment