Пример #1
0
def test_load_keys():
    config1 = {
        'public_key_path': 'tests/data/certs/public.pem',
        'private_key_path': 'tests/data/certs/private.pem'
    }

    cfg = load_keys(config1)
    assert cfg['private'] is not None
    assert cfg['public'] is not None
    assert cfg.get('secret') is None

    config1 = {'secret': 'abc123'}

    cfg = load_keys(config1)
    assert cfg.get('private') is None
    assert cfg.get('public') is None
    assert cfg['secret'] == b'abc123'

    bad_config = {
        'public_key_path': 'tests/data/certs/public.pem',
        'private_key_path': 'tests/data/certs/private.pemz'
    }

    with pytest.raises(Exception) as ex:
        load_keys(bad_config)

    bad_config = {
        'public_key_path': 'tests/data/certs/public.pemz',
        'private_key_path': 'tests/data/certs/private.pem'
    }

    with pytest.raises(Exception) as ex:
        load_keys(bad_config)
Пример #2
0
def test_load_keys():
    config1 = {
        "public_key_path": "tests/data/certs/public.pem",
        "private_key_path": "tests/data/certs/private.pem",
    }

    cfg = load_keys(config1)
    assert cfg["private"] is not None
    assert cfg["public"] is not None
    assert cfg.get("secret") is None

    config1 = {"secret": "abc123"}

    cfg = load_keys(config1)
    assert cfg.get("private") is None
    assert cfg.get("public") is None
    assert cfg["secret"] == b"abc123"

    bad_config = {
        "public_key_path": "tests/data/certs/public.pem",
        "private_key_path": "tests/data/certs/private.pemz",
    }

    with pytest.raises(Exception) as ex:
        load_keys(bad_config)

    bad_config = {
        "public_key_path": "tests/data/certs/public.pemz",
        "private_key_path": "tests/data/certs/private.pem",
    }

    with pytest.raises(Exception) as ex:
        load_keys(bad_config)