def test_update_endpoint_state(): class mybcf(): def __init__(self): pass def format_endpoints(self, data): a = [{ 'ip-address': '10.0.0.1', 'mac': 'f8:b1:56:fe:f2:de', 'segment': 'prod', 'tenant': 'FLOORPLATE', 'name': None }, { 'ip-address': '10.0.0.2', 'mac': '20:4c:9e:5f:e3:c3', 'segment': 'to-core-router', 'tenant': 'EXTERNAL', 'name': None }] return a def get_endpoints(self, messages=None): pass uss = controller_interface.get_endpoint('Update_Switch_State') uss.sdnc = mybcf() output = json.loads(uss.update_endpoint_state()) correct_output = json.loads( '{"service": "NorthBoundControllerAbstraction:Update_Switch_State", "times": 0, "machines": [{"ip-address": "10.0.0.1", "mac": "f8:b1:56:fe:f2:de", "segment": "prod", "tenant": "FLOORPLATE", "name": null}, {"ip-address": "10.0.0.2", "mac": "20:4c:9e:5f:e3:c3", "segment": "to-core-router", "tenant": "EXTERNAL", "name": null}], "resp": "ok"}' ) assert str(output) == str(correct_output)
Created on 28 June 2016 @author: dgrossman """ import ast import logging import falcon import pytest from poseidon.poseidonMonitor.NorthBoundControllerAbstraction.NorthBoundControllerAbstraction import controller_interface module_logger = logging.getLogger(__name__) application = falcon.API() application.add_route('/v1/Nbca/resource/{resource}', controller_interface.get_endpoint('Handle_Resource')) application.add_route('/v1/Nbca/periodic', controller_interface.get_endpoint('Handle_Periodic')) # exposes the application for testing @pytest.fixture def app(): return application def test_NorthBoundControllerAbstraction(client): """ Tests the NorthBoundControllerAbstraction Handle_Resource class """