Пример #1
0
def test_convert():
    website_slug = random_cryptocurrency(pym)["website_slug"]
    print('(<currency>["website_slug"] == "%s")' % website_slug, end=" ")
    res = pym.currency(website_slug, convert="BTC")

    assert_types(res)
    assert_consistence(res)
Пример #2
0
def test_consistence():
    print("")
    for size in tqdm([16, 32, 64, 128, 200],
                     desc="Testing currency logo downloads for all sizes"):
        attempts = 20
        while attempts > 0:
            _assert = True
            website_slug = random_cryptocurrency(pym)["website_slug"]
            tqdm.write(('<currency>["website_slug"] == "%s" | Size: %d)' \
                % (website_slug, size))
            )
            try:
                res = pym.download_logo(website_slug, size=size)
            except ValueError as e:
                print(e)
                attempts -= 1
                _assert = False
                if attempts == 0:
                    break
            else:
                break
        if _assert:
            assert res == "%s_%dx%d.png" % (website_slug, size, size)
            sleep(.5)

            assert os.path.exists(res)
            os.remove(res)
            assert os.path.exists(res) == False
        if attempts == 0:
            raise AssertionError("0 currency logos downloaded. Check it!")
Пример #3
0
def test_without_convert():
    website_slug = random_cryptocurrency(pym)["website_slug"]
    print('(<currency>["website_slug"] == "%s")' % website_slug, end=" ")
    res = pym.markets(website_slug)
    assert_types(res)
    assert_consistence(res)
    assert_number_of_markets(res)
Пример #4
0
def test_start_end():
    days_ago = timedelta(days=randint(1, 15))
    start = datetime.now() - days_ago
    end = datetime.now()
    curr = random_cryptocurrency(pym)["website_slug"]
    print('(<currency>["website_slug"] == %s | Start: %r | End: %r)' %
          (curr, start, end),
          end=" ")
    for startend in [True, False]:
        params = {"start": start, "end": end}
        if not startend:
            params["start"], params["end"] = (None, None)
        res = pym.graphs.currency(curr, **params)

        # Test types
        assert isinstance(res, dict)

        for key, _list in res.items():
            assert isinstance(_list, list)
            for elem, value in _list:
                assert isinstance(elem, datetime)
                assert type(value) in [int, float]

        # Test consistence
        if end.day > 2:
            assert end.day >= res["price_btc"][-1][0].day
        if startend:
            first_day = res["price_usd"][0][0]
            next_day = res["price_usd"][0][0] + timedelta(days=1)
            assert start <= next_day
Пример #5
0
def test_name():
    name = random_cryptocurrency(pym)["name"]
    print('(<currency>["name"] == "%s")' % name, end=" ")
    res = pym.ticker(name)

    if res:
        assert_types(res["data"])
        assert_consistence(res["data"])
Пример #6
0
def test_symbol():
    symbol = random_cryptocurrency(pym)["symbol"]
    print('(<currency>["symbol"] == "%s")' % symbol, end=" ")
    res = pym.ticker(symbol)

    if res:
        assert_types(res["data"])
        assert_consistence(res["data"])
Пример #7
0
def test_convert():
    for currency in [True, False]:  # With and without currency
        symbol = None
        badge = choice(pym.ticker_badges)
        if currency:
            symbol = random_cryptocurrency(pym)["symbol"]
            print('(<currency>["name"] == "%s") - Badge: %s)' \
                      % (symbol, badge), end=" | ")
        else:
            print("(Badge: %s)" % badge, end=" ")

        res = pym.ticker(currency=symbol, convert=badge)
        if currency and res:
            assert_types(res["data"])
            assert_consistence(res["data"])
Пример #8
0
def test_consistence():
    curr = random_cryptocurrency(pym)["website_slug"]
    res = pym.graphs.currency(curr)
    print('(<currency>["website_slug"] == "%s")' % curr, end=" ")

    assert len(res) in [4, 5]

    fields = [
        "market_cap_by_available_supply",
        "price_btc",
        "price_usd",
        "volume_usd",
        "price_platform",
    ]

    for field, values in res.items():
        assert field in fields
Пример #9
0
from time import sleep
from urllib.request import urlopen

import pytest
from tqdm import tqdm

from pymarketcap import Pymarketcap
from pymarketcap.tests.utils import (
    random_cryptocurrency,
    random_exchange,
)

pym = Pymarketcap()

cryptocurrency = random_cryptocurrency(pym)
exchange = random_exchange(pym)["website_slug"]

base_public_api_url = "https://api.coinmarketcap.com/v2/"
base_web_url = "https://coinmarketcap.com/"
base_internal_api_url = "https://s2.coinmarketcap.com/"
base_graphs_api_url = "https://graphs2.coinmarketcap.com/"

endpoints = [
    ("_quick_search",
     "%sgenerated/search/quick_search.json" % base_internal_api_url),
    ("_quick_search_exchanges",
     "%sgenerated/search/quick_search_exchanges.json" % base_internal_api_url),
    ("download_logo",
     "%sstatic/img/coins/64x64/1.png" % base_internal_api_url),
    ("download_exchange_logo",
Пример #10
0
def test_types():
    website_slug = random_cryptocurrency(pym)["website_slug"]
    print('(<currency>["website_slug"] == "%s")' % website_slug, end=" ")
    res = pym.currency(website_slug)
    assert_types(res)
Пример #11
0
def test_consistence():
    curr = random_cryptocurrency(pym)["website_slug"]
    print('(<currency>["website_slug"] == "%s")' % curr, end=" ")
    res = pym.historical(curr)
    assert_consistence(res)
Пример #12
0
def test_types():
    curr = random_cryptocurrency(pym)["website_slug"]
    res = pym.graphs.currency(curr)
    print('(<currency>["website_slug"] == "%s")' % curr, end=" ")

    assert_types(res)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from tqdm import tqdm

from pymarketcap import Pymarketcap
from pymarketcap.tests.utils import (
    random_cryptocurrency,
    random_exchange,
)

pym = Pymarketcap()

METHODS = [["exchanges"], ["exchange",
                           random_exchange(pym)["website_slug"]],
           ["currency", random_cryptocurrency(pym)["website_slug"]],
           ["markets", random_cryptocurrency(pym)["website_slug"]], ["ranks"],
           ["recently"], ["tokens"],
           ["graphs.currency",
            random_cryptocurrency(pym)["website_slug"]], ["graphs.global_cap"],
           ["graphs.dominance"]]


def test_fields():
    keys = []
    keys_method_map = {}
    for method in tqdm(METHODS, desc="Testing all response names consistency"):
        _exec = "pym.%s(%s)" % (method[0],
                                '"%s"' % method[1] if len(method) == 2 else "")
        tqdm.write(_exec)
        try: