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
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
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']
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']
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
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
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()
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()