示例#1
0
def test_client():
    # check the built-in uac xml scenario
    remote_sock = ("192.168.1.1", 5060)
    uac = agent.client(destaddr=remote_sock)
    cmdstr = uac.render()
    assert "-sn 'uac'" in cmdstr
    assert "'{}':'{}'".format(*remote_sock) in cmdstr

    # pretend script file
    script = "/home/sipp_scen/uac.xml"
    uac2 = agent.client(destaddr=remote_sock, scen_file=script)
    cmdstr = uac2.render()
    assert "-sn 'uac'" not in cmdstr
    assert "-sf '{}'".format(script) in cmdstr
示例#2
0
def test_client():
    # check the built-in uac xml scenario
    remote_sock = ('192.168.1.1', 5060)
    uac = agent.client(destaddr=remote_sock)
    cmdstr = uac.render()
    assert "-sn 'uac'" in cmdstr
    assert "'{}':'{}'".format(*remote_sock) in cmdstr

    # pretend script file
    script = '/home/sipp_scen/uac.xml'
    uac2 = agent.client(destaddr=remote_sock, scen_file=script)
    cmdstr = uac2.render()
    assert "-sn 'uac'" not in cmdstr
    assert "-sf '{}'".format(script) in cmdstr
示例#3
0
def test_authentication_arguments():
    client = agent.client(auth_username="******", auth_password="******")

    cmd = client.render()

    assert "-au 'username'" in cmd
    assert "-ap 'passw0rd'" in cmd
示例#4
0
def test_scenario():
    uas, uac = agent.server(), agent.client()
    agents = [uas, uac]
    scen = agent.Scenario(agents)
    scen2 = agent.Scenario(agents)

    # verify contained agents
    assert list(scen.agents.values()) == agents == scen._agents
    assert scen.prepare() != agents  # new copies

    # verify order
    agents = list(scen.agents.values())
    assert uas is agents[0]
    assert uac is agents[1]
    # verify servers
    assert uas is list(scen.servers.values())[0]
    # verify clients
    assert uac is list(scen.clients.values())[0]

    # ensure defaults attr setting works
    doggy = "doggy"
    scen.local_host = doggy
    uas, uac = scen.prepare()
    assert uac.local_host == uas.local_host == doggy

    # should be no shared state between instances
    assert scen2.local_host != doggy
    scen2.local_host = 10
    assert scen.local_host == doggy

    # same error for any non-spec defined agent attr
    with pytest.raises(AttributeError):
        scen.agentdefaults.local_man = "flasher"
        scen.prepare()

    # defaults on servers only
    scen.serverdefaults.uri_username = doggy
    uas, uac = scen.prepare()
    assert uas.uri_username == doggy
    assert uac.uri_username != doggy

    assert scen.name == "uas_uac"
示例#5
0
文件: test_agent.py 项目: SIPp/pysipp
def test_scenario():
    uas, uac = agent.server(), agent.client()
    agents = [uas, uac]
    scen = agent.Scenario(agents)
    scen2 = agent.Scenario(agents)

    # verify contained agents
    assert list(scen.agents.values()) == agents == scen._agents
    assert scen.prepare() != agents  # new copies

    # verify order
    agents = list(scen.agents.values())
    assert uas is agents[0]
    assert uac is agents[1]
    # verify servers
    assert uas is list(scen.servers.values())[0]
    # verify clients
    assert uac is list(scen.clients.values())[0]

    # ensure defaults attr setting works
    doggy = 'doggy'
    scen.local_host = doggy
    uas, uac = scen.prepare()
    assert uac.local_host == uas.local_host == doggy

    # should be no shared state between instances
    assert scen2.local_host != doggy
    scen2.local_host = 10
    assert scen.local_host == doggy

    # same error for any non-spec defined agent attr
    with pytest.raises(AttributeError):
        scen.agentdefaults.local_man = 'flasher'
        scen.prepare()

    # defaults on servers only
    scen.serverdefaults.uri_username = doggy
    uas, uac = scen.prepare()
    assert uas.uri_username == doggy
    assert uac.uri_username != doggy

    assert scen.name == 'uas_uac'
示例#6
0
def test_agent_fails():
    uas = server(call_count=1)
    # apply bogus ip which can't be bound
    uas.local_host, uas.local_port = '99.99.99.99', 5060
    # client calls server at bogus addr
    uac = client(destaddr=(uas.local_host, uas.local_port))
    uac.recv_timeout = 1  # avoids SIPp issue #176
    uac.call_count = 1  # avoids SIPp issue #176

    runner = run_blocking(uas, uac)

    # fails due to invalid ip
    uasproc = runner.get(timeout=0)[uas.render()]
    assert uasproc.streams.stderr
    assert uasproc.returncode == 255, uasproc.streams.stderr

    # killed by signal
    uacproc = runner.get(timeout=0)[uac.render()]
    # assert not uacproc.streams.stderr  # sometimes this has a log msg?
    ret = uacproc.returncode
    # killed by SIGUSR1 or terminates before it starts (racy)
    assert ret == -10 or ret == 0
示例#7
0
def default_agents():
    uas = agent.server(local_host='127.0.0.1', local_port=5060, call_count=1)
    uac = agent.client(call_count=1, destaddr=(uas.local_host, uas.local_port))
    return uas, uac
示例#8
0
    assert "-sf '{}'".format(script) in cmdstr


def test_server():
    ua = agent.server()
    cmdstr = ua.render()
    assert "-sn 'uas'" in cmdstr
    assert not (ua.remote_host and ua.remote_port)


@pytest.mark.parametrize('ua, retcode, kwargs, exc', [
    # test unspecialized ua failure
    (agent.ua(), 255, {}, RuntimeError),

    # test client failure on bad remote destination
    (agent.client(destaddr=('99.99.99.99', 5060)), 1, {}, RuntimeError),

    # test if server times out it is signalled
    (agent.server(), 0, {'timeout': 1}, launch.TimeoutError)],
    ids=['ua', 'uac', 'uas'],
)
def test_failures(ua, retcode, kwargs, exc):
    """Test failure cases for all types of agents
    """
    # run it without raising
    runner = ua(raise_exc=False, **kwargs)
    cmds2procs = runner.get(timeout=0)
    assert not runner.is_alive()
    assert len(list(runner.iterprocs())) == 0
    # tests transparency of the defaults config pipeline
    scen = plugin.mng.hook.pysipp_conf_scen_protocol(
示例#9
0

def test_server():
    ua = agent.server()
    cmdstr = ua.render()
    assert "-sn 'uas'" in cmdstr
    assert not (ua.remote_host and ua.remote_port)


@pytest.mark.parametrize(
    "ua, retcode, kwargs, exc",
    [
        # test unspecialized ua failure
        (agent.ua(), 255, {}, RuntimeError),
        # test client failure on bad remote destination
        (agent.client(destaddr=("99.99.99.99", 5060)), 1, {}, RuntimeError),
        # test if server times out it is signalled
        (agent.server(), 0, {
            "timeout": 1
        }, launch.TimeoutError),
    ],
    ids=["ua", "uac", "uas"],
)
def test_failures(ua, retcode, kwargs, exc):
    """Test failure cases for all types of agents"""
    # run it without raising
    runner = ua(raise_exc=False, **kwargs)
    cmds2procs = runner.get(timeout=0)
    assert not runner.is_alive()
    assert len(list(runner.iterprocs())) == 0
    # tests transparency of the defaults config pipeline