class GetCoinValueTest(unittest.TestCase): def setUp(self): self.server = MockServer() self.server.start() def tearDown(self): self.server.stop() def test_perform_request_without_coin(self): with self.assertRaises(TypeError): # noinspection PyArgumentList perform_request() def test_perform_request_with_invalid_coin(self): with self.assertRaises(ValueError): # noinspection PyTypeChecker perform_request(123) def test_perform_request_with_invalid_request(self): with self.assertRaises(ValueError): # noinspection PyTypeChecker perform_request("BTC", request={}) def test_perform_request(self): MockServer.reset() req = EobotRequest() req.set_base_url('http://localhost:{0}/api.test'.format( self.server.port)) value = perform_request("BTC", request=req.clone()) self.assertIsInstance(value, float) self.assertEqual(100.0, value)
class GetExchangeEstimateTest(unittest.TestCase): def setUp(self): self.server = MockServer() self.server.start() def tearDown(self): self.server.stop() def test_perform_request_without_arguments(self): with self.assertRaises(TypeError): # noinspection PyArgumentList perform_request() def test_perform_request_without_from_coin(self): with self.assertRaises(TypeError): # noinspection PyArgumentList perform_request(amount=1.0, to_coin="ETH") def test_perform_request_without_to_coin(self): with self.assertRaises(TypeError): # noinspection PyArgumentList perform_request(from_coin="BTC", amount=1.0) def test_perform_request_without_amount(self): with self.assertRaises(TypeError): # noinspection PyArgumentList perform_request(from_coin="BTC", to_coin="ETH") def test_perform_request_with_invalid_from_coin(self): with self.assertRaises(ValueError): # noinspection PyTypeChecker perform_request(123, "ETH", 1.0) def test_perform_request_with_invalid_to_coin(self): with self.assertRaises(ValueError): # noinspection PyTypeChecker perform_request("BTC", 123, 1.0) def test_perform_request_with_invalid_amount(self): with self.assertRaises(ValueError): # noinspection PyTypeChecker perform_request("BTC", "ETH", "one") def test_perform_request_with_invalid_request(self): with self.assertRaises(ValueError): # noinspection PyTypeChecker perform_request("BTC", "ETH", 1.0, request={}) def test_perform_request(self): MockServer.reset() req = EobotRequest() req.set_base_url('http://localhost:{0}/api.test'.format( self.server.port)) estimate = perform_request("BTC", "ETH", 1.0, request=req.clone()) self.assertIsInstance(estimate, float) self.assertEqual(5.0, estimate)
class GetSupportedCoinsTest(unittest.TestCase): def setUp(self): self.server = MockServer() self.server.start() def tearDown(self): self.server.stop() def test_perform_request_with_invalid_request(self): with self.assertRaises(ValueError): # noinspection PyTypeChecker perform_request(request={}) def test_perform_request(self): MockServer.reset() req = EobotRequest() req.set_base_url('http://localhost:{0}/api.test'.format( self.server.port)) coins = perform_request(request=req.clone()) self.assertIsInstance(coins, dict) self.assertIn("BTC", coins.keys()) self.assertIn("ETH", coins.keys()) self.assertIsInstance(coins["BTC"], dict) self.assertIsInstance(coins["ETH"], dict) self.assertIn("Price", coins["BTC"].keys()) self.assertIn("Image", coins["BTC"].keys()) self.assertIn("BigImage", coins["BTC"].keys()) self.assertIn("Price", coins["ETH"].keys()) self.assertIn("Image", coins["ETH"].keys()) self.assertIn("BigImage", coins["ETH"].keys()) self.assertIsInstance(coins["BTC"]["Price"], float) self.assertIsInstance(coins["BTC"]["Image"], basestring) self.assertIsInstance(coins["BTC"]["BigImage"], basestring) self.assertIsInstance(coins["ETH"]["Price"], float) self.assertIsInstance(coins["ETH"]["Image"], basestring) self.assertIsInstance(coins["ETH"]["BigImage"], basestring) self.assertEqual(100.0, coins["BTC"]["Price"]) self.assertEqual("http://www.eobot.com/btc.png", coins["BTC"]["Image"]) self.assertEqual("http://www.eobot.com/btcbig.png", coins["BTC"]["BigImage"]) self.assertEqual(20.0, coins["ETH"]["Price"]) self.assertEqual("http://www.eobot.com/eth.png", coins["ETH"]["Image"]) self.assertEqual("http://www.eobot.com/ethbig.png", coins["ETH"]["BigImage"])
def test_perform_request_with_error(self): server = MockServer() server.start() req = EobotRequest() req.set_base_url('http://localhost:{0}/api.test'.format(server.port)) req.set_parameter("nosuch", "page") with self.assertRaises(RuntimeError): req.perform_request() server.stop()
def test_perform_request(self): server = MockServer() server.start() req = EobotRequest() req.set_base_url('http://localhost:{0}/api.test'.format(server.port)) req.set_parameter("coin", "BTC") response = req.perform_request() server.stop() self.assertIsInstance(response, dict) self.assertIn("BTC", response) self.assertIsInstance(response["BTC"], float) self.assertEqual(100.0, response["BTC"])
class GetSupportedFiatTest(unittest.TestCase): def setUp(self): self.server = MockServer() self.server.start() def tearDown(self): self.server.stop() def test_perform_request_with_invalid_request(self): with self.assertRaises(ValueError): # noinspection PyTypeChecker perform_request(request={}) def test_perform_request(self): MockServer.reset() req = EobotRequest() req.set_base_url('http://localhost:{0}/api.test'.format( self.server.port)) fiat = perform_request(request=req.clone()) self.assertIsInstance(fiat, dict) self.assertIn("USD", fiat.keys()) self.assertIn("EUR", fiat.keys()) self.assertIsInstance(fiat["USD"], dict) self.assertIsInstance(fiat["EUR"], dict) self.assertIn("Price", fiat["USD"].keys()) self.assertIn("Price", fiat["EUR"].keys()) self.assertIsInstance(fiat["USD"]["Price"], float) self.assertIsInstance(fiat["EUR"]["Price"], float) self.assertEqual(1.0, fiat["USD"]["Price"]) self.assertEqual(0.85, fiat["EUR"]["Price"])
class GetMiningEstimatesTest(unittest.TestCase): def setUp(self): self.server = MockServer() self.server.start() def tearDown(self): self.server.stop() def test_perform_request_with_invalid_config(self): with self.assertRaises(ValueError): # noinspection PyTypeChecker perform_request(config={}) def test_perform_request_with_invalid_request(self): with self.assertRaises(ValueError): # noinspection PyTypeChecker perform_request(request={}) def test_perform_request(self): MockServer.reset() req = EobotRequest() req.set_base_url('http://*****:*****@example.com", password="******", token=None) estimates = perform_request(request=req.clone()) self.assertIsInstance(estimates, dict) self.assertIn("MiningSHA-256", estimates.keys()) self.assertIsInstance(estimates["MiningSHA-256"], float) self.assertEqual((1.0/6.0), estimates["MiningSHA-256"]) def test_perform_request_with_config(self): MockServer.reset() req = EobotRequest() req.set_base_url('http://*****:*****@example.com", password="******", token=None) estimates = perform_request(config="tgme", request=req.clone()) self.assertIsInstance(estimates, dict) self.assertIn("MiningSHA-256", estimates.keys()) self.assertIsInstance(estimates["MiningSHA-256"], float) self.assertEqual((1.0/12.0), estimates["MiningSHA-256"]) def test_perform_request_with_config_without_user_id(self): MockServer.reset() req = EobotRequest() req.set_base_url('http://*****:*****@example.com", password="******", token=None) estimates = perform_request(config=get_config("tgme2"), request=req.clone()) self.assertIsInstance(estimates, dict) self.assertIn("MiningSHA-256", estimates.keys()) self.assertIsInstance(estimates["MiningSHA-256"], float) self.assertEqual((1.0/12.0), estimates["MiningSHA-256"])
class GetBalancesTest(unittest.TestCase): def setUp(self): self.server = MockServer() self.server.start() def tearDown(self): self.server.stop() def test_perform_request_with_invalid_config(self): with self.assertRaises(ValueError): # noinspection PyTypeChecker perform_request(config={}) def test_perform_request_with_invalid_request(self): with self.assertRaises(ValueError): # noinspection PyTypeChecker perform_request(request={}) def test_perform_request(self): MockServer.reset() req = EobotRequest() req.set_base_url('http://*****:*****@example.com", password="******", token=None) balances = perform_request(request=req.clone()) self.assertIsInstance(balances, dict) self.assertEqual(3, len(balances)) self.assertIn("BTC", balances.keys()) self.assertIn("ETH", balances.keys()) self.assertIn("Total", balances.keys()) self.assertEqual(0.2, balances["BTC"]) self.assertEqual(2.5, balances["ETH"]) self.assertEqual(70.0, balances["Total"]) def test_perform_request_with_config(self): MockServer.reset() req = EobotRequest() req.set_base_url('http://*****:*****@example.com", password="******", token=None) balances = perform_request(config="tgb", request=req.clone()) self.assertIsInstance(balances, dict) self.assertEqual(3, len(balances)) self.assertIn("BTC", balances.keys()) self.assertIn("ETH", balances.keys()) self.assertIn("Total", balances.keys()) self.assertEqual(0.1, balances["BTC"]) self.assertEqual(2.0, balances["ETH"]) self.assertEqual(50.0, balances["Total"]) def test_perform_request_with_config_without_user_id(self): MockServer.reset() req = EobotRequest() req.set_base_url('http://*****:*****@example.com", password="******", token=None) balances = perform_request(config=get_config("tgb2"), request=req.clone()) self.assertIsInstance(balances, dict) self.assertEqual(3, len(balances)) self.assertIn("BTC", balances.keys()) self.assertIn("ETH", balances.keys()) self.assertIn("Total", balances.keys()) self.assertEqual(0.1, balances["BTC"]) self.assertEqual(2.0, balances["ETH"]) self.assertEqual(50.0, balances["Total"])
class ExchangeCoinsTest(unittest.TestCase): def setUp(self): self.server = MockServer() self.server.start() def tearDown(self): self.server.stop() def test_perform_request_without_arguments(self): with self.assertRaises(TypeError): # noinspection PyArgumentList perform_request() def test_perform_request_with_invalid_from_coin(self): with self.assertRaises(ValueError): # noinspection PyTypeChecker perform_request(123, 1, "ETH") def test_perform_request_with_invalid_amount(self): with self.assertRaises(ValueError): # noinspection PyTypeChecker perform_request("BTC", "1", "ETH") def test_perform_request_with_invalid_to_coin(self): with self.assertRaises(ValueError): # noinspection PyTypeChecker perform_request("BTC", 1, 456) def test_perform_request_with_invalid_config(self): with self.assertRaises(ValueError): # noinspection PyTypeChecker perform_request("BTC", 1, "ETH", config={}) def test_perform_request_with_invalid_request(self): with self.assertRaises(ValueError): # noinspection PyTypeChecker perform_request("BTC", 1, "ETH", request={}) def test_perform_request(self): MockServer.reset() req = EobotRequest() req.set_base_url('http://*****:*****@example.com", password="******", token=None) self.assertEqual(0.2, get_balances(request=req.clone())["BTC"]) self.assertEqual(2.5, get_balances(request=req.clone())["ETH"]) result = perform_request("BTC", 0.1, "ETH", request=req.clone()) self.assertTrue(result) self.assertEqual(0.1, get_balances(request=req.clone())["BTC"]) self.assertEqual(3.0, get_balances(request=req.clone())["ETH"]) def test_perform_request_with_config(self): MockServer.reset() req = EobotRequest() req.set_base_url('http://*****:*****@example.com", password="******", token=None) self.assertEqual(0.1, get_balances(config="tec", request=req.clone())["BTC"]) self.assertEqual(2.0, get_balances(config="tec", request=req.clone())["ETH"]) result = perform_request("BTC", 0.1, "ETH", config="tec", request=req.clone()) self.assertTrue(result) self.assertEqual(0.0, get_balances(config=get_config("tec"), request=req.clone())["BTC"]) self.assertEqual(2.5, get_balances(config=get_config("tec"), request=req.clone())["ETH"]) def test_perform_request_with_config_without_user_id(self): MockServer.reset() req = EobotRequest() req.set_base_url('http://*****:*****@example.com", password="******", token=None) result = perform_request("ETH", 0.5, "BTC", config="tec2", request=req.clone()) self.assertTrue(result) self.assertEqual(0.2, get_balances(config=get_config("tec2"), request=req.clone())["BTC"]) self.assertEqual(1.5, get_balances(config=get_config("tec2"), request=req.clone())["ETH"])
class GetMiningModeTest(unittest.TestCase): def setUp(self): self.server = MockServer() self.server.start() def tearDown(self): self.server.stop() def test_perform_request_with_invalid_config(self): with self.assertRaises(ValueError): # noinspection PyTypeChecker perform_request(config={}) def test_perform_request_with_invalid_request(self): with self.assertRaises(ValueError): # noinspection PyTypeChecker perform_request(request={}) def test_perform_request(self): MockServer.reset() req = EobotRequest() req.set_base_url('http://*****:*****@example.com", password="******", token=None) mode = perform_request(request=req.clone()) self.assertIsInstance(mode, basestring) self.assertEqual("BTC", mode) def test_perform_request_with_config(self): MockServer.reset() req = EobotRequest() req.set_base_url('http://*****:*****@example.com", password="******", token=None) mode = perform_request(config="tgmm", request=req.clone()) self.assertIsInstance(mode, basestring) self.assertEqual("ETH", mode) def test_perform_request_with_config_without_user_id(self): MockServer.reset() req = EobotRequest() req.set_base_url('http://*****:*****@example.com", password="******", token=None) mode = perform_request(config=get_config("tgmm2"), request=req.clone()) self.assertIsInstance(mode, basestring) self.assertEqual("ETH", mode)
class GetUserIdTest(unittest.TestCase): def setUp(self): self.server = MockServer() self.server.start() def tearDown(self): self.server.stop() def test_perform_request_with_invalid_config(self): with self.assertRaises(ValueError): # noinspection PyTypeChecker perform_request(config={}) def test_perform_request_with_invalid_request(self): with self.assertRaises(ValueError): # noinspection PyTypeChecker perform_request(request={}) def test_perform_request_with_config_without_email(self): get_config("tgui1").configure(user_id=None, email=None, password=None, token=None) with self.assertRaises(NoEmailError): perform_request(config=get_config("tgui1")) def test_perform_request_with_config_without_password_or_token(self): get_config("tgui2").configure(user_id=None, email="*****@*****.**", password=None, token=None) with self.assertRaises(NoPasswordOrTokenError): perform_request(config=get_config("tgui2")) def test_perform_request_with_valid_config(self): MockServer.reset() req = EobotRequest() req.set_base_url('http://*****:*****@example.com", password="******", token=None) user_id = perform_request(request=req.clone()) self.assertIsInstance(user_id, int) self.assertEqual(123, user_id) def test_perform_request_with_config(self): MockServer.reset() req = EobotRequest() req.set_base_url('http://*****:*****@example.com", password="******", token=None) user_id = perform_request(config="tgui3", request=req.clone()) self.assertIsInstance(user_id, int) self.assertEqual(456, user_id)
class GetDepositAddressTest(unittest.TestCase): def setUp(self): self.server = MockServer() self.server.start() def tearDown(self): self.server.stop() def test_perform_request_without_coin(self): with self.assertRaises(TypeError): # noinspection PyArgumentList perform_request() def test_perform_request_with_invalid_coin(self): with self.assertRaises(ValueError): # noinspection PyTypeChecker perform_request(123) def test_perform_request_with_invalid_config(self): with self.assertRaises(ValueError): # noinspection PyTypeChecker perform_request("BTC", config={}) def test_perform_request_with_invalid_request(self): with self.assertRaises(ValueError): # noinspection PyTypeChecker perform_request("BTC", request={}) def test_perform_request(self): MockServer.reset() req = EobotRequest() req.set_base_url('http://*****:*****@example.com", password="******", token=None) wallet = perform_request("BTC", request=req.clone()) self.assertIsInstance(wallet, basestring) self.assertEqual("bitcoin-wallet", wallet) def test_perform_request_with_config(self): MockServer.reset() req = EobotRequest() req.set_base_url('http://*****:*****@example.com", password="******", token=None) wallet = perform_request("ETH", config="tgda", request=req.clone()) self.assertIsInstance(wallet, basestring) self.assertEqual("wallet-ethereum", wallet) def test_perform_request_with_config_without_user_id(self): MockServer.reset() req = EobotRequest() req.set_base_url('http://*****:*****@example.com", password="******", token=None) wallet = perform_request("BTC", config=get_config("tgda2"), request=req.clone()) self.assertIsInstance(wallet, basestring) self.assertEqual("wallet-bitcoin", wallet)
class SetMiningModeTest(unittest.TestCase): def setUp(self): self.server = MockServer() self.server.start() def tearDown(self): self.server.stop() def test_perform_request_without_arguments(self): with self.assertRaises(TypeError): # noinspection PyArgumentList perform_request() def test_perform_request_with_invalid_mode(self): with self.assertRaises(ValueError): # noinspection PyTypeChecker perform_request(123) def test_perform_request_with_invalid_config(self): with self.assertRaises(ValueError): # noinspection PyTypeChecker perform_request("ETH", config={}) def test_perform_request_with_invalid_request(self): with self.assertRaises(ValueError): # noinspection PyTypeChecker perform_request("ETH", request={}) def test_perform_request(self): req = EobotRequest() req.set_base_url('http://*****:*****@example.com", password="******", token=None) mode_before = get_mining_mode(request=req.clone()) self.assertEqual("BTC", mode_before) result = perform_request("ETH", request=req.clone()) self.assertTrue(result) mode_after = get_mining_mode(request=req.clone()) self.assertEqual("ETH", mode_after) def test_perform_request_with_config(self): req = EobotRequest() req.set_base_url('http://*****:*****@example.com", password="******", token=None) mode_before = get_mining_mode(config="tsmm", request=req.clone()) self.assertEqual("ETH", mode_before) result = perform_request("BTC", config="tsmm", request=req.clone()) self.assertTrue(result) mode_after = get_mining_mode(config="tsmm", request=req.clone()) self.assertEqual("BTC", mode_after) def test_perform_request_with_config_without_user_id(self): req = EobotRequest() req.set_base_url('http://*****:*****@example.com", password="******", token=None) result = perform_request("BTC", config=get_config("tsmm2"), request=req.clone()) self.assertTrue(result)
class SetAutomaticWithdrawTest(unittest.TestCase): def setUp(self): self.server = MockServer() self.server.start() def tearDown(self): self.server.stop() def test_perform_request_without_arguments(self): with self.assertRaises(TypeError): # noinspection PyArgumentList perform_request() def test_perform_request_with_invalid_coin(self): with self.assertRaises(ValueError): # noinspection PyTypeChecker perform_request(123, 0.1, "bitcoin-wallet") def test_perform_request_with_invalid_amount(self): with self.assertRaises(ValueError): # noinspection PyTypeChecker perform_request("BTC", "0.1", "bitcoin-wallet") def test_perform_request_with_invalid_wallet(self): with self.assertRaises(ValueError): # noinspection PyTypeChecker perform_request("BTC", 0.1, 456) def test_perform_request_with_invalid_config(self): with self.assertRaises(ValueError): # noinspection PyTypeChecker perform_request("BTC", 0.1, "bitcoin-wallet", config={}) def test_perform_request_with_invalid_request(self): with self.assertRaises(ValueError): # noinspection PyTypeChecker perform_request("BTC", 0.11, "bitcoin-wallet", request={}) def test_perform_request(self): MockServer.reset() req = EobotRequest() req.set_base_url('http://*****:*****@example.com", password="******", token=None) result = perform_request("BTC", 0.1, "bitcoin-wallet", request=req.clone()) self.assertTrue(result) def test_perform_request_with_config(self): MockServer.reset() req = EobotRequest() req.set_base_url('http://*****:*****@example.com", password="******", token=None) result = perform_request("BTC", 0.05, "wallet-bitcoin", config="tsaw", request=req.clone()) self.assertTrue(result) def test_perform_request_with_config_without_user_id(self): MockServer.reset() req = EobotRequest() req.set_base_url('http://*****:*****@example.com", password="******", token=None) result = perform_request("BTC", 0.05, "wallet-bitcoin", config="tsaw2", request=req.clone()) self.assertTrue(result)