Exemple #1
0
        super(_PartialEnabledContext, self).__init__(*args)
        self.disable_partial = False


def get_client():
    return peeringdb.PeeringDB(helper.CONFIG)


# test single-object, aka. partial sync (disabled in release)
def get_pclient():
    c = peeringdb.PeeringDB(helper.CONFIG)
    c._updater._ContextClass = _PartialEnabledContext
    return c


client_dup = helper.client_fixture('insert_nonunique.sql')


def test_full(client_empty):
    client = get_client()
    rs = all_resources()
    client.update_all(rs)


# Ensure fetching is not order-dependent
def test_reversed(client_empty):
    client = client_empty
    # sanity check for empty client
    B = peeringdb.get_backend()
    with pytest.raises(B.object_missing_error()):
        client.get(Network, FIRST_NET)
Exemple #2
0
import io
import os
import re

import helper
import pytest

import peeringdb
from peeringdb import cli as _cli

CMD = "peeringdb_test"

client = helper.client_fixture("full")


# Run with config dir
class RunCli:
    def __init__(self, c):
        self.config_dir = str(c)

    def __call__(self, *args):
        fullargs = [CMD]
        fullargs.extend(["-C", self.config_dir])
        fullargs.extend(args)
        return _cli.main(fullargs)


@pytest.fixture
def runcli(config0_dir):
    return RunCli(config0_dir)
Exemple #3
0
import pytest, os

import helper
import peeringdb
from peeringdb import resource

helper.set_data_path(__file__, 'data')
client = helper.client_fixture('insert_full.sql')
NET0 = 7


def test_nonexistent_config():
    with pytest.raises(Exception):
        peeringdb.client.Client({})


def test_get(client):
    assert client.get(resource.Network, NET0)
    with pytest.raises(Exception):
        client.get(resource.Network, 12)


def test_type_wrap(client):
    assert client.tags.net.get(NET0)
    assert client.tags.net.all()


def test_version_check(client_empty, patch_version, patch_backend_version):
    with patch_version:
        with pytest.raises(peeringdb.sync.CompatibilityError):
            client_empty.fetch(resource.Network, NET0)
Exemple #4
0
sys.path.append(_path.join(_path.dirname(__file__)))

import helper
import peeringdb

from peeringdb.client import Client

peeringdb._config_logs(logging.DEBUG)


@pytest.fixture
def config0_dir():
    return _path.join(helper.data_path(), 'config0')


client_empty = helper.client_fixture(None)


@pytest.fixture
def patch_version(monkeypatch):
    @contextmanager
    def func():
        with monkeypatch.context() as mc:
            mc.setattr('peeringdb.__version__', '0.1.0')
            yield

    return func()


@pytest.fixture
def patch_backend_version(monkeypatch):
Exemple #5
0
        super().__init__(*args)
        self.disable_partial = False


def get_client():
    return Client(helper.CONFIG)


# test single-object, aka. partial sync (disabled in release)
def get_pclient():
    c = Client(helper.CONFIG)
    c._updater._ContextClass = _PartialEnabledContext
    return c


client_dup = helper.client_fixture("full_nonunique")


def test_full(client_empty):
    client = get_client()
    rs = all_resources()
    client.update_all(rs)
    assert client.get(Network, FIRST_NET)


# Ensure fetching is not order-dependent
def test_reversed(client_empty):
    client = client_empty
    # sanity check for empty client
    B = peeringdb.get_backend()
    with pytest.raises(B.object_missing_error()):