def test_BcfProxy(): """ Tests bcf """ filemap = { '/data/controller/applications/bcf/info/fabric/switch': 'sample_switches.json', '/data/controller/applications/bcf/info/endpoint-manager/tenant' : 'sample_tenants.json', '/data/controller/applications/bcf/info/endpoint-manager/segment' : 'sample_segments.json', '/data/controller/applications/bcf/info/endpoint-manager/endpoint' : 'sample_endpoints.json', '/data/controller/applications/bcf/span-fabric' : 'sample_span_fabric.json', '/data/controller/applications/bcf/span-fabric[name=%22vent%22]': 'sample_span_fabric.json', # %22 = url-encoded double quotes } proxy = None with HTTMock(mock_factory(r'.*', filemap)): proxy = BcfProxy('http://localhost', 'login', {'username': username, 'password': password}) endpoints = proxy.get_endpoints() assert endpoints switches = proxy.get_switches() assert switches tenants = proxy.get_tenants() assert tenants segments = proxy.get_segments() assert segments span_fabric = proxy.get_span_fabric() assert span_fabric span_fabric = proxy.get_span_fabric(span_name="vent") assert span_fabric with HTTMock(mock_factory2(r'.*')): # Normally shutdown_endpoint does not return a value. # You should call get_endpoint() afterwards to verify that a shutdown request went through. # In addition, the mock endpoint generated does not check for duplicates. # TODO: ***This code below is temporary.*** r = proxy.shutdown_endpoint(tenant="TENANT", segment="SEGMENT", endpoint_name="test", mac="00:00:00:00:00:00", shutdown=True) assert r r = proxy.shutdown_endpoint(tenant="TENANT", segment="SEGMENT", endpoint_name="test", mac="00:00:00:00:00:00", shutdown=False) assert r r = proxy.mirror_traffic(seq=2, mirror=True, tenant="TENANT", segment="SEGMENT") assert r r = proxy.mirror_traffic(seq=2, mirror=False) assert r r = lambda: None r.text = "" BcfProxy.parse_json(r) proxy.session.cookies.clear_session_cookies() proxy.base_uri = "http://jsonplaceholder.typicode.com" r = proxy.post_resource('posts') r.raise_for_status() r = proxy.request_resource(method="PUT", url="http://jsonplaceholder.typicode.com/posts/1") r.raise_for_status()
def test_BcfProxy(): """ Tests bcf """ filemap = { '/data/controller/applications/bcf/info/fabric/switch': 'sample_switches.json', '/data/controller/applications/bcf/info/endpoint-manager/tenant': 'sample_tenants.json', '/data/controller/applications/bcf/info/endpoint-manager/segment': 'sample_segments.json', '/data/controller/applications/bcf/info/endpoint-manager/endpoint': 'sample_endpoints.json', '/data/controller/applications/bcf/span-fabric[name=%22SPAN_FABRIC%22]': 'sample_span_fabric.json', # %22 = url-encoded double quotes '/data/controller/applications/bcf/span-fabric[name=%22SPAN_FABRIC%22][dest-interface-group=%22INTERFACE_GROUP%22]': 'sample_span_fabric.json', '/data/controller/applications/bcf/span-fabric[name=%22empty%22][dest-interface-group=%22empty%22]': 'sample_span_fabric_empty.json', } proxy = None with HTTMock(mock_factory(r'.*', filemap)): proxy = BcfProxy('http://localhost', 'login', { 'username': username, 'password': password }, span_fabric_name='SPAN_FABRIC', interface_group='INTERFACE_GROUP') endpoints = proxy.get_endpoints() assert endpoints switches = proxy.get_switches() assert switches tenants = proxy.get_tenants() assert tenants segments = proxy.get_segments() assert segments span_fabric = proxy.get_span_fabric() assert span_fabric span_fabric = proxy.get_span_fabric(span_name='SPAN_FABRIC') assert span_fabric span_fabric = proxy.get_span_fabric(span_name='empty', interface_group='empty') assert not span_fabric with HTTMock(mock_factory2(r'.*')): # Normally shutdown_endpoint does not return a value. # You should call get_endpoint() afterwards to verify that a shutdown request went through. # In addition, the mock endpoint generated does not check for duplicates. # TODO: ***This code below is temporary.*** r = proxy.shutdown_endpoint(tenant='TENANT', segment='SEGMENT', endpoint_name='test', mac='00:00:00:00:00:00', shutdown=True) assert r r = proxy.shutdown_endpoint(tenant='TENANT', segment='SEGMENT', endpoint_name='test', mac='00:00:00:00:00:00', shutdown=False) assert r r = proxy.mirror_traffic(seq=2, mirror=True, tenant='TENANT', segment='SEGMENT') assert r r = proxy.mirror_traffic(seq=2, mirror=False) assert r def r(): return True r.text = '' # cover object assert r() BcfProxy.parse_json(r) proxy.session.cookies.clear_session_cookies() proxy.base_uri = 'http://jsonplaceholder.typicode.com' r = proxy.post_resource('posts') r.raise_for_status() r = proxy.request_resource( method='PUT', url='http://jsonplaceholder.typicode.com/posts/1') r.raise_for_status()