Skip to content
Snippets Groups Projects
Select Git revision
  • 591f3313af06dc47b93fbd009e778764aefc3255
  • dev default protected
  • release/1.9.1 protected
  • pini-1.8-docker
  • pini-sync-onlypeers
  • duniter-v2s-issue-123-industrialize-releases
  • feature/build-aarch64-nodejs16
  • release/1.8 protected
  • pini-docker
  • ci_tags
  • fix/1448/1.8/txs_not_stored
  • feature/node-20
  • fix/1441/node_summary_with_storage
  • fix/1442/improve_bma_tx_history
  • feature/wotwizard-1.8
  • release/1.9 protected
  • 1.7 protected
  • feature/docker-set-latest protected
  • feature/fast-docker-build-1.8.4
  • fast-docker-build protected
  • feature/dump-distance
  • v1.8.7 protected
  • v1.8.7-rc4 protected
  • v1.8.7-rc3 protected
  • v1.8.7-rc2 protected
  • v1.8.7-rc1 protected
  • v1.8.6 protected
  • v1.7.23 protected
  • v1.8.5 protected
  • v1.8.4 protected
  • v1.8.3 protected
  • v1.8.2 protected
  • v1.8.1 protected
  • v1.8.0 protected
  • v1.8.0-rc1 protected
  • v1.8.0-beta5 protected
  • v1.8.0-beta4 protected
  • v1.8.0-beta3 protected
  • v1.8.0-beta2 protected
  • v1.8.0-beta protected
  • v1.7.21 protected
41 results

install.sh

Blame
  • test_network_tools.py 2.96 KiB
    # Copyright  2016-2021 Maël Azimi <m.a@moul.re>
    #
    # Silkaj is free software: you can redistribute it and/or modify
    # it under the terms of the GNU Affero General Public License as published by
    # the Free Software Foundation, either version 3 of the License, or
    # (at your option) any later version.
    #
    # Silkaj is distributed in the hope that it will be useful,
    # but WITHOUT ANY WARRANTY; without even the implied warranty of
    # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    # GNU Affero General Public License for more details.
    #
    # You should have received a copy of the GNU Affero General Public License
    # along with Silkaj. If not, see <https://www.gnu.org/licenses/>.
    
    import urllib
    from unittest.mock import patch
    
    import pytest
    from duniterpy.api import bma
    from duniterpy.api import endpoint as du_ep
    
    from silkaj import constants, network_tools
    from silkaj.membership import generate_membership_document
    from tests import helpers
    
    ipv6 = "2001:0db8:85a3:0000:0000:8a2e:0370:7334"
    
    
    @pytest.mark.parametrize(
        "endpoint, host, ipv4, ipv6, port, path",
        [
            ("127.0.0.1", "", "127.0.0.1", None, 443, None),
            ("127.0.0.1:80", "", "127.0.0.1", None, 80, None),
            ("127.0.0.1:443", "", "127.0.0.1", None, 443, None),
            ("127.0.0.1/path", "", "127.0.0.1", None, 443, "path"),
            ("127.0.0.1:80/path", "", "127.0.0.1", None, 80, "path"),
            ("domain.tld:80/path", "domain.tld", None, None, 80, "path"),
            ("localhost:80/path", "localhost", None, None, 80, "path"),
            (f"[{ipv6}]", None, None, ipv6, 443, None),
            (f"[{ipv6}]/path", None, None, ipv6, 443, "path"),
            (f"[{ipv6}]:80/path", None, None, ipv6, 80, "path"),
        ],
    )
    def test_determine_endpoint_custom(endpoint, host, ipv4, ipv6, port, path):
        helpers.define_click_context(endpoint)
        ep = network_tools.determine_endpoint()
        assert ep.host == host
        assert ep.ipv4 == ipv4
        assert ep.ipv6 == ipv6
        assert ep.port == port
        if isinstance(ep, du_ep.SecuredBMAEndpoint):
            assert ep.path == path
    
    
    @pytest.mark.parametrize(
        "gtest, endpoint",
        [
            (True, constants.G1_TEST_DEFAULT_ENDPOINT),
            (False, constants.G1_DEFAULT_ENDPOINT),
        ],
    )
    def test_determine_endpoint(gtest, endpoint):
        helpers.define_click_context(gtest=gtest)
        ep = network_tools.determine_endpoint()
        assert ep == du_ep.endpoint(endpoint)
    
    
    # def test_send_document_success(capsys):
    #    display = capsys.readouterr().out
    #    network_tools.send_document()
    
    
    # def test_send_document_error(capsys):
    #    membership_doc = generate_membership_document(
    #        "g1", "A" * 43, "0-ahv", "test", "1-aut"
    #    )
    #
    #    #with patch("urllib.request.urlopen", side_effect=urllib.error.HTTPError):
    #    with patch("duniterpy.api.client.API.request_url", side_effect=urllib.error.HTTPError):
    #        network_tools.send_document(bma.blockchain.membership, membership_doc)
    #
    #    display = capsys.readouterr().out
    #    assert "Error while publishing Membership:" in display