Skip to content

Commit

Permalink
Update tests to match current code.
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeReclaimers committed Apr 11, 2017
1 parent 162747f commit 0f6c145
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 26 deletions.
21 changes: 14 additions & 7 deletions test/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@


class TestCommon(unittest.TestCase):
def setUp(self):
self.connection = BTCEConnection()

def tearDown(self):
self.connection.close()
self.connection = None

def test_formatCurrency(self):
self.assertEqual(formatCurrencyDigits(1.123456789, 1), "1.1")
self.assertEqual(formatCurrencyDigits(1.123456789, 2), "1.12")
Expand All @@ -21,7 +28,7 @@ def test_formatCurrency(self):
self.assertEqual(formatCurrencyDigits(44.0, i), "44.0")

def test_formatCurrencyByPair(self):
info = APIInfo()
info = APIInfo(self.connection)
for i in info.pairs.values():
d = i.decimal_places
self.assertEqual(i.format_currency(1.12),
Expand All @@ -34,7 +41,7 @@ def test_formatCurrencyByPair(self):
truncateAmountDigits(44.0, d))

def test_truncateAmount(self):
info = APIInfo()
info = APIInfo(self.connection)
for i in info.pairs.values():
d = i.decimal_places
self.assertEqual(i.truncate_amount(1.12),
Expand All @@ -43,19 +50,19 @@ def test_truncateAmount(self):
truncateAmountDigits(44.0, d))

def test_validatePair(self):
info = APIInfo()
info = APIInfo(self.connection)
for pair in info.pair_names:
info.validate_pair(pair)
self.assertRaises(InvalidTradePairException,
info.validate_pair, "not_a_real_pair")

def test_validate_pair_suggest(self):
info = APIInfo()
info = APIInfo(self.connection)
self.assertRaises(InvalidTradePairException,
info.validate_pair, "usd_btc")

def test_validateOrder(self):
info = APIInfo()
info = APIInfo(self.connection)
for pair in info.pair_names:
t = random.choice(("buy", "sell"))
a = random.random()
Expand Down Expand Up @@ -100,13 +107,13 @@ def test_parseJSONResponse(self):
decimal.Decimal("27.5")])

def test_pair_identity(self):
info = APIInfo()
info = APIInfo(self.connection)
self.assertEqual(len(info.pair_names), len(set(info.pair_names)))
self.assertEqual(set(info.pairs.keys()), set(info.pair_names))

def test_currency_sets(self):
currencies_from_pairs = set()
info = APIInfo()
info = APIInfo(self.connection)
for pair in info.pair_names:
c1, c2 = pair.split("_")
currencies_from_pairs.add(c1)
Expand Down
32 changes: 18 additions & 14 deletions test/test_scraping.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,25 @@


class TestScraping(unittest.TestCase):

def test_scrape_main_page(self):
mainPage = btceapi.scrapeMainPage()
for message in mainPage.messages:
msgId, user, time, text = message
assert type(time) is datetime
if sys.version_info[0] == 2:
# python2.x
assert type(msgId) in (str, unicode)
assert type(user) in (str, unicode)
assert type(text) in (str, unicode)
else:
# python3.x
self.assertIs(type(msgId), str)
self.assertIs(type(user), str)
self.assertIs(type(text), str)
with btceapi.BTCEConnection() as connection:
info = btceapi.APIInfo(connection)
mainPage = info.scrapeMainPage()

for message in mainPage.messages:
msgId, user, time, text = message
assert type(time) is datetime
if sys.version_info[0] == 2:
# python2.x
assert type(msgId) in (str, unicode)
assert type(user) in (str, unicode)
assert type(text) in (str, unicode)
else:
# python3.x
self.assertIs(type(msgId), str)
self.assertIs(type(user), str)
self.assertIs(type(text), str)


if __name__ == '__main__':
Expand Down
12 changes: 7 additions & 5 deletions test/test_trade.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,22 @@ def setUp(self):
if not os.path.isfile(TEST_KEY_FILE):
self.skipTest("No test keys found")

self.key_handler = btceapi.KeyHandler(TEST_KEY_FILE, resaveOnDeletion=True)
self.key_handler = btceapi.KeyHandler(TEST_KEY_FILE)
self.connection = btceapi.BTCEConnection()

def tearDown(self):
self.connection.close()
self.connection = None
self.key_handler.close()

def test_construction(self):
keys = list(self.key_handler.keys)
t = btceapi.TradeAPI(keys[0], self.key_handler)
t = btceapi.TradeAPI(keys[0], self.key_handler, self.connection)

def test_key_info(self):
for key in self.key_handler.keys:
conn = btceapi.BTCEConnection()
t = btceapi.TradeAPI(key, self.key_handler)
r = t.getInfo(connection=conn)
t = btceapi.TradeAPI(key, self.key_handler, self.connection)
r = t.getInfo()


if __name__ == '__main__':
Expand Down

0 comments on commit 0f6c145

Please sign in to comment.