Ejemplo n.º 1
0
def test_main():
    with open("test-data.json") as f:
        sample_tweets = json.load(f)

    # Populate coins
    main.get_coins_bittrex()
    # Telegram bot
    bot = TelegramBot()

    # Twitter stream
    class MockTwitter:
        def tweet_callback(text, user, link):
            to_buy = main.analyze(text)
            assert len(to_buy) > 0
            bot.notify_tweet(text, user, link, to_buy)

    tweets = [sample_tweets["tweet_image"], sample_tweets["tweet_text"]]

    count = 0
    for tweet in tweets:
        Twitter.handle_tweet(MockTwitter, tweet_json=tweet)
        count += 1

    while count < len(tweets):
        time.sleep(1)
Ejemplo n.º 2
0
def test_telegram_buy():
    main.get_coins_bittrex()
    main.bot = TelegramBot()
    query_data = "buy_doge"
    try:
        replies = main.bot.get_query_replies(query_data)
        assert len(replies) > 0
        assert len(replies[0]) == 2
        assert type(replies[0][0]) is str
    except Exception as e:
        raise AssertionError(e)
Ejemplo n.º 3
0
def test_telegram_summary():
    main.get_coins_bittrex()
    main.bot = TelegramBot()
    query_data = "summary_doge"
    try:
        replies = main.bot.get_query_replies(query_data)
        assert len(replies) > 0
        assert len(replies[0]) == 2
        assert type(replies[0][0]) is str
        assert type(replies[0][1]) is telepot.namedtuple.InlineKeyboardMarkup
    except Exception as e:
        raise AssertionError(e)
Ejemplo n.º 4
0
def test_analyze():
    main.get_coins_bittrex()

    # Negative sentiment
    text = "do not buy dogecoin, it is bad"
    to_buy = main.analyze(text)
    assert len(to_buy) == 0

    # Positive sentiment
    text = "please buy dogecoin"
    to_buy = main.analyze(text)
    assert len(to_buy) == 1
Ejemplo n.º 5
0
def test_twitter_tweet_callback(run_forever):
    main.get_coins_bittrex()
    main.bot = TelegramBot()
    text = "please buy doge"
    user = "******"
    link = "https://twitter.com/mcafee2cash/status/944746808466698240"

    try:
        main.twitter_tweet_callback(text, user, link)
    except Exception as e:
        raise AssertionError(e)

    if run_forever:
        while True:
            time.sleep(1)
Ejemplo n.º 6
0
def test_extract_symbols():
    main.get_coins_bittrex()
    texts = [
        'Coin of the day: Digibyte (DGB). Using a Blockchain which is 40 times faster than Bitcoin and having one of the most decentralized mining systems in the world - based on 5 different synergistic algorithms. DGB adherents call the coin "The Sleeping Giant".',
        'Yes, there are 1,500+ coins now. And yes, most  are jokes or outright scams. But among those coins are Ethereum, Monero, Litecoin and other proven winners. By implying Sether is a joke is a huge mistake. Go to sether.io and read it. You will see it is in the mold of a winner.',
        'Coin of the day: BURST -- First truly Green coin and most overlooked coin. Uses 400 times less power than Bitcoin. Super secure and private. Includes smart contracts, encrypted messaging, decentralized wallet, libertine blockchain. Most undervalued coin. https://www.burst-coin.org '
    ]
    symbols = [
        set([('BTC', 'bitcoin'), ('DGB', 'digibyte')]),
        set([('XMR', 'monero'), ('LTC', 'litecoin'), ('ETH', 'ethereum')]),
        set([('BURST', 'burstcoin'), ('BTC', 'bitcoin')])
    ]

    for i, text in enumerate(texts):
        extracted = main.extract_symbols(text)
        try:
            assert extracted == symbols[i]
        except AssertionError as e:
            print(extracted, symbols[i])
            raise e
Ejemplo n.º 7
0
def test_get_coins_bittrex():
    main.get_coins_bittrex()
    assert len(main.symbol_name) > 0
    assert len(main.name_symbol) > 0
    assert main.symbol_name["BTC"] == "bitcoin"
    assert main.name_symbol["bitcoin"] == "BTC"