Exemplo n.º 1
0
def test_correct_site(client, site):
    '''Tests that a resource gets sent to the correct site_id'''
    n = Network(client=client, site_id=site['id'], cidr='8.8.8.0/24')
    assert n.ensure()
    assert n.existing_resource()['site_id'] == site['id']

    from pynsot.util import get_result
    manual = get_result(client.sites(site['id']).networks('8.8.8.0/24').get())
    assert manual['site_id'] == site['id']
Exemplo n.º 2
0
def test_correct_site(client, site):
    '''Tests that a resource gets sent to the correct site_id'''
    n = Network(client=client, site_id=site['id'], cidr='8.8.8.0/24')
    assert n.ensure()
    assert n.existing_resource()['site_id'] == site['id']

    from pynsot.util import get_result
    manual = get_result(client.sites(site['id']).networks('8.8.8.0/24').get())
    assert manual['site_id'] == site['id']
Exemplo n.º 3
0
def test_raw_precedence(client, site):
    '''Makes sure raw kwarg site_id takes precedence'''
    # first create a resource to get raw from
    n = Network(client=client, site_id=site['id'], cidr='8.8.8.0/24')
    assert n.ensure()

    # Make sure that raw settings take precedence
    raw = n.existing_resource()
    n2 = Network(client=client, site=999, raw=raw)
    assert n2['site_id'] != 999
Exemplo n.º 4
0
def test_ip4_send(client, site):
    '''Test upstream write actions for IPv4'''

    site_id = site['id']
    subnet = Network(client=client, site_id=site_id, cidr='254.0.0.0/24')
    host = Network(client=client, site_id=site_id, cidr='254.0.0.1/32')

    assert subnet.purge()
    assert not subnet.exists()
    assert subnet.ensure()
    assert subnet.exists()
    assert host.purge()
    assert not host.exists()
    assert host.ensure()
    assert host.exists()

    host.purge()
    subnet.purge()
    assert not all([subnet.exists(), host.exists()])
Exemplo n.º 5
0
def test_raw_precedence(client, site):
    '''Makes sure raw kwarg site_id takes precedence'''
    # first create a resource to get raw from
    n = Network(client=client, site_id=site['id'], cidr='8.8.8.0/24')
    assert n.ensure()

    # Make sure that raw settings take precedence
    raw = n.existing_resource()
    n2 = Network(client=client, site=999, raw=raw)
    assert n2['site_id'] != 999
Exemplo n.º 6
0
def test_ip4_send(client, site):
    '''Test upstream write actions for IPv4'''

    site_id = site['id']
    subnet = Network(client=client, site_id=site_id, cidr='254.0.0.0/24')
    host = Network(client=client, site_id=site_id, cidr='254.0.0.1/32')

    assert subnet.purge()
    assert not subnet.exists()
    assert subnet.ensure()
    assert subnet.exists()
    assert host.purge()
    assert not host.exists()
    assert host.ensure()
    assert host.exists()

    host.purge()
    subnet.purge()
    assert not all([subnet.exists(), host.exists()])
Exemplo n.º 7
0
def test_net_closest_parent(client, site):
    '''Test that Network.closest_parent returns instance of Network or dict'''
    site_id = site['id']
    c = client

    parent = Network(client=c, site_id=site_id, cidr='8.8.8.0/24')
    assert parent.ensure()

    child = Network(client=c, site_id=site_id, cidr='8.8.8.8/32')
    assert child.closest_parent() == parent

    orphan = Network(client=c, site_id=site_id, cidr='1.1.1.1/32')
    assert not orphan.closest_parent()
    assert orphan.closest_parent() == {}
Exemplo n.º 8
0
def test_net_closest_parent(client, site):
    '''Test that Network.closest_parent returns instance of Network or dict'''
    site_id = site['id']
    c = client

    parent = Network(client=c, site_id=site_id, cidr='8.8.8.0/24')
    assert parent.ensure()

    child = Network(client=c, site_id=site_id, cidr='8.8.8.8/32')
    assert child.closest_parent() == parent

    orphan = Network(client=c, site_id=site_id, cidr='1.1.1.1/32')
    assert not orphan.closest_parent()
    assert orphan.closest_parent() == {}
Exemplo n.º 9
0
def test_existing(client, site):
    '''Test functionality around existing resource and caching of the result'''
    site_id = site['id']
    c = client

    n = Network(client=c, site_id=site_id, cidr='8.8.8.0/24')
    assert n.purge()
    assert not n.exists()
    assert n._existing_resource == {}
    assert n.existing_resource() == n._existing_resource
    assert n.ensure()
    # Make sure cache clearing works
    assert n._existing_resource == {}
    assert n.exists()
    assert n.existing_resource() == n._existing_resource
Exemplo n.º 10
0
def test_existing(client, site):
    '''Test functionality around existing resource and caching of the result'''
    site_id = site['id']
    c = client

    n = Network(client=c, site_id=site_id, cidr='8.8.8.0/24')
    assert n.purge()
    assert not n.exists()
    assert n._existing_resource == {}
    assert n.existing_resource() == n._existing_resource
    assert n.ensure()
    # Make sure cache clearing works
    assert n._existing_resource == {}
    assert n.exists()
    assert n.existing_resource() == n._existing_resource
Exemplo n.º 11
0
def test_payload_not_none_raw_and_not(client, site):
    '''Make sure payload gets set fine for both EZ and raw approaches

    Also make sure both instances are the same, using comparisons
    '''
    n = Network(client=client, site_id=site['id'], cidr='8.8.8.0/24')
    assert n.payload
    assert n.ensure()

    n2 = Network(
        raw=get_result(client.sites(site['id']).networks('8.8.8.0/24').get()))

    assert n2.payload

    # Test some magic methods on raw-init'd instance
    assert len(n2)
    assert n == n2
    assert n2.keys()
    assert n2.items()
Exemplo n.º 12
0
def test_clear_cache_on_change(client, site):
    '''Test that cache is cleared on any change to the instance'''
    site_id = site['id']
    c = client

    n = Network(client=c, site_id=site_id, cidr='8.8.8.0/24')
    assert n.ensure()
    assert n.exists()

    non_existing_site = get_result(c.sites.get())[-1]['id'] + 1000
    n['site_id'] = non_existing_site
    # First assert that the cache property was cleared
    assert not n._existing_resource
    assert not n.existing_resource()
    # assert that the resource isn't successfully looked up if site doesn't
    # match
    assert not n.exists()
    # Change site back and test
    n['site_id'] = site_id
    assert n.exists()
Exemplo n.º 13
0
def test_clear_cache_on_change(client, site):
    '''Test that cache is cleared on any change to the instance'''
    site_id = site['id']
    c = client

    n = Network(client=c, site_id=site_id, cidr='8.8.8.0/24')
    assert n.ensure()
    assert n.exists()

    non_existing_site = get_result(c.sites.get())[-1]['id'] + 1000
    n['site_id'] = non_existing_site
    # First assert that the cache property was cleared
    assert not n._existing_resource
    assert not n.existing_resource()
    # assert that the resource isn't successfully looked up if site doesn't
    # match
    assert not n.exists()
    # Change site back and test
    n['site_id'] = site_id
    assert n.exists()
Exemplo n.º 14
0
def test_payload_not_none_raw_and_not(client, site):
    '''Make sure payload gets set fine for both EZ and raw approaches

    Also make sure both instances are the same, using comparisons
    '''
    n = Network(client=client, site_id=site['id'], cidr='8.8.8.0/24')
    assert n.payload
    assert n.ensure()

    n2 = Network(
        raw=get_result(
            client.sites(site['id']).networks('8.8.8.0/24').get()
        )
    )

    assert n2.payload

    # Test some magic methods on raw-init'd instance
    assert len(n2)
    assert n == n2
    assert n2.keys()
    assert n2.items()