Ejemplo n.º 1
0
def test_success_fetch_confirmations_blocks(requests_mock):

    blocks = [
        {
            "id": "e7c5c2e0-8ed1-4eb3-abd8-97fa2e5ca8db",
            "created_date": "2020-10-08T02:18:07.908635Z",
            "modified_date": "2020-10-08T02:18:07.908702Z",
            "block_identifier":
            "824614aa97edb391784b17ce6956b70aed31edf741c1858d43ae4d566b2a13ed",
            "block": "c6fc11cf-8948-4d32-96c9-d56caa6d5b24",
            "validator": "e2a138b0-ebe9-47d2-a146-fb4d9d9ca378",
        },
        {
            "id": "78babf4b-74ed-442e-b5ab-7b23345c18f8",
            "created_date": "2020-10-08T02:18:07.998146Z",
            "modified_date": "2020-10-08T02:18:07.998206Z",
            "block_identifier":
            "824614aa97edb391784b17ce6956b70aed31edf741c1858d43ae4d566b2a13ed",
            "block": "c6fc11cf-8948-4d32-96c9-d56caa6d5b24",
            "validator": "97a878ac-328a-47b6-ac93-be6deee75d94",
        },
    ]

    result_page1 = {
        "count": 2,
        "next": "http://10.2.3.4:80/confirmation_blocks?limit=50&offset=1",
        "previous": None,
        "results": [
            blocks[0],
        ],
    }

    result_page2 = {
        "count": 2,
        "next": None,
        "previous": "http://10.2.3.4:80/confirmation_blocks",
        "results": [
            blocks[1],
        ],
    }
    requests_mock.get(
        "http://10.2.3.4:80/confirmation_blocks",
        json=result_page1,
    )
    requests_mock.get(
        "http://10.2.3.4:80/confirmation_blocks?limit=50&offset=1",
        json=result_page2,
    )

    bank = Bank(address="10.2.3.4")
    response = bank.fetch_confirmation_blocks()
    assert response == blocks
Ejemplo n.º 2
0
def test_success_fetch_confirmations_blocks_on_page_2(requests_mock):
    results = [
        {
            "id": "e7c5c2e0-8ed1-4eb3-abd8-97fa2e5ca8db",
            "created_date": "2020-10-08T02:18:07.908635Z",
            "modified_date": "2020-10-08T02:18:07.908702Z",
            "block_identifier":
            "824614aa97edb391784b17ce6956b70aed31edf741c1858d43ae4d566b2a13ed",
            "block": "c6fc11cf-8948-4d32-96c9-d56caa6d5b24",
            "validator": "e2a138b0-ebe9-47d2-a146-fb4d9d9ca378",
        },
        {
            "id": "78babf4b-74ed-442e-b5ab-7b23345c18f8",
            "created_date": "2020-10-08T02:18:07.998146Z",
            "modified_date": "2020-10-08T02:18:07.998206Z",
            "block_identifier":
            "824614aa97edb391784b17ce6956b70aed31edf741c1858d43ae4d566b2a13ed",
            "block": "c6fc11cf-8948-4d32-96c9-d56caa6d5b24",
            "validator": "97a878ac-328a-47b6-ac93-be6deee75d94",
        },
    ]

    address = "10.2.3.4"
    url = f"http://{address}:80/confirmation_blocks"

    payload = {
        "count": 6,
        "next": f"{url}?limit=2&offset=4",
        "previous": f"{url}?limit=2",
        "results": results,
    }

    requests_mock.get(url, json=payload)
    bank = Bank(address=address)
    response = bank.fetch_confirmation_blocks(offset=2, limit=2)
    assert response == payload