コード例 #1
0
def mock_masterweb_service():
    MasterWebService.__bases__ = (AgentMock.imitate(Agent, Agent()), )
    masterweb = MasterWebService(serverkey=MagicMock(),
                                 identity=MagicMock(),
                                 address=MagicMock(),
                                 bind_web_address=MagicMock())
    rpc_caller = masterweb.vip.rpc
    masterweb._admin_endpoints = AdminEndpoints(rpc_caller=rpc_caller)
    yield masterweb
コード例 #2
0
def mock_platformweb_service() -> PlatformWebService:
    PlatformWebService.__bases__ = (AgentMock.imitate(Agent, Agent()), )
    platformweb = PlatformWebService(serverkey=MagicMock(),
                                     identity=MagicMock(),
                                     address=MagicMock(),
                                     bind_web_address=MagicMock())
    # rpc_caller = platformweb.vip.rpc
    # platformweb._admin_endpoints = AdminEndpoints(rpc_caller=rpc_caller)

    # Internally the register uses this value to determine the caller's identity
    # to allow the platform web service to map calls back to the proper agent
    platformweb.vip.rpc.context.vip_message.peer.return_value = "foo"

    yield platformweb
コード例 #3
0
pytestmark = [pytest.mark.actuator_unit, pytest.mark.unit]

PEER = "peer-1"
SENDER = "sender-1"
HEADERS = {"requesterID": "id-12345"}
MESSAGE = "message-1"
BUS = "bus-1"
GET_TOPIC = "devices/actuators/get/somepath/actuationpoint"
SET_TOPIC = "devices/actuators/set/somepath/actuationpoint"
REQUEST_TOPIC = "devices/actuators/schedule/request"
REVERT_DEVICE_TOPIC = "devices/actuators/revert/device/somedevicepath"
REVERT_POINT_TOPIC = "actuators/revert/point/somedevicepath/someactuationpoint"

agent._log = logging.getLogger("test_logger")
ActuatorAgent.__bases__ = (AgentMock.imitate(Agent, Agent()),)


def test_handle_get_should_succeed():
    with get_actuator_agent() as actuator_agent:
        actuator_agent.handle_get(PEER, SENDER, BUS, GET_TOPIC, HEADERS, MESSAGE)

        actuator_agent.vip.rpc.call.assert_called_once()
        actuator_agent.vip.pubsub.publish.assert_called_once()


def test_handle_get_should_handle_standard_error(caplog):
    with get_actuator_agent(vip_identity=None) as actuator_agent:
        actuator_agent.handle_get(PEER, SENDER, BUS, GET_TOPIC, HEADERS, MESSAGE)

        actuator_agent.vip.rpc.call.assert_not_called()
コード例 #4
0
ファイル: test_platforms.py プロジェクト: VOLTTRON/volttron
def mock_vc():
    VolttronCentralAgent.__bases__ = (AgentMock.imitate(
        Agent, VolttronCentralAgent()), )
    vc = VolttronCentralAgent()
    vc._configure("test_config", "NEW", {})
    yield vc
コード例 #5
0
ファイル: test_masterweb.py プロジェクト: tpktang/volttron
from volttron.platform.vip.agent.subsystems.web import ResourceType
from volttron.platform.vip.socket import decode_key
from volttron.platform.web import MasterWebService
from volttron.platform.web.admin_endpoints import AdminEndpoints
from volttron.utils import get_random_key
from volttrontesting.utils.platformwrapper import create_volttron_home
from volttrontesting.fixtures.volttron_platform_fixtures import get_test_volttron_home

from volttrontesting.utils.web_utils import get_test_web_env
from volttrontesting.utils.utils import AgentMock, get_hostname_and_random_port
#from volttrontesting.utils.platformwrapper import create_volttron_home
from volttrontesting.fixtures.cert_fixtures import certs_profile_1

# Patch the MasterWebService so the underlying Agent interfaces are mocked
# so we can just test the things that the MasterWebService is responsible for.
MasterWebService.__bases__ = (AgentMock.imitate(Agent, Agent()), )

#TODO add tests for new RPC calls


@pytest.fixture()
def master_web_service():
    serverkey = "serverkey"
    mock_aip = mock.Mock()
    yield MasterWebService(serverkey=serverkey,
                           identity=MASTER_WEB,
                           address="tcp://stuff",
                           bind_web_address="http://v2:8888")


@contextlib.contextmanager
コード例 #6
0
ファイル: test_vcp_units.py プロジェクト: VOLTTRON/volttron
from volttron.platform.vip.agent import Agent
from volttrontesting.utils.utils import AgentMock
from vcplatform.agent import VolttronCentralPlatform

# Patch the VolttronCentralPlatform so the underlying Agent interfaces are mocked
# so we can just test the things that the PlatformWebService is responsible for.
VolttronCentralPlatform.__bases__ = (AgentMock.imitate(Agent, Agent()), )
コード例 #7
0
ファイル: test_driver.py プロジェクト: VOLTTRON/volttron
from mock import create_autospec

import pytest
import pytz

from platform_driver import agent
from platform_driver.agent import DriverAgent
from platform_driver.interfaces import BaseInterface
from platform_driver.interfaces.fakedriver import Interface as FakeInterface
from volttrontesting.utils.utils import AgentMock
from volttron.platform.vip.agent import Agent
from volttron.platform.messaging.utils import Topic
from volttron.platform.vip.agent.core import ScheduledEvent

agent._log = logging.getLogger("test_logger")
DriverAgent.__bases__ = (AgentMock.imitate(Agent, Agent()), )


@pytest.mark.driver_unit
def test_update_publish_types_should_only_set_depth_first_to_true():
    publish_depth_first_all = True
    publish_breadth_first_all = True
    publish_depth_first = True
    publish_breadth_first = True

    with get_driver_agent() as driver_agent:
        driver_agent.update_publish_types(publish_depth_first_all,
                                          publish_breadth_first_all,
                                          publish_depth_first,
                                          publish_breadth_first)
コード例 #8
0
    ]


    # When the base_historian is handling duplicates from the cache, the base_historian is expected to make multiple calls to publish_to_historian
    # in which each call contains exactly one duplicate record. More importanly, the base_historian is also expected to make each call to publish_to_historian
    # in the order in which the duplicates were initially inserted into the cache (i.e. First-in, First Out, FIFO)
    # In this specific case, we have three duplicates that need to be processed. Thus, publish_to_historian will get called thrice.
    # On the first call, publish_to_historian will publish 'unique_record_2', 'unique_record_3', 'unique_record_4' AND  'last_duplicate_40'
    # On the second call, publish_to_historian will publish last_duplicate_41
    # On the third and final call, publish_to_historian will publish last_duplicate_42
    # Since it is difficult to validate every call except the last call, we will simply validate that the last call
    # did indeed publish exactly one duplicate record that was the last duplicate record inserted into the cache.
    assert base_historian_agent.last_to_publish_list == expected_to_publish_list


BaseHistorianAgent.__bases__ = (AgentMock.imitate(Agent, Agent()),)


class BaseHistorianAgentTestWrapper(BaseHistorianAgent):
    def __init__(self, **kwargs):
        self.last_to_publish_list = ""
        super(BaseHistorianAgentTestWrapper, self).__init__(**kwargs)

    def publish_to_historian(self, to_publish_list):
        self.report_all_handled()
        self.last_to_publish_list = to_publish_list


@pytest.fixture()
def base_historian_agent():
    base_historian = BaseHistorianAgentTestWrapper()
コード例 #9
0
def mock_auth_service():
    AuthService.__bases__ = (AgentMock.imitate(Agent, Agent()), )
    yield AuthService(auth_file=MagicMock(),
                      protected_topics_file=MagicMock(),
                      setup_mode=MagicMock(),
                      aip=MagicMock())
コード例 #10
0
from volttron.platform.vip.agent.subsystems.web import ResourceType
from volttron.platform.vip.socket import decode_key
from volttron.platform.web import PlatformWebService
from volttron.platform.web.admin_endpoints import AdminEndpoints
from volttron.utils import get_random_key
from volttrontesting.utils.platformwrapper import create_volttron_home
from volttrontesting.fixtures.volttron_platform_fixtures import get_test_volttron_home

from volttrontesting.utils.web_utils import get_test_web_env
from volttrontesting.utils.utils import AgentMock, get_hostname_and_random_port
#from volttrontesting.utils.platformwrapper import create_volttron_home
from volttrontesting.fixtures.cert_fixtures import certs_profile_1

# Patch the PlatformWebService so the underlying Agent interfaces are mocked
# so we can just test the things that the PlatformWebService is responsible for.
PlatformWebService.__bases__ = (AgentMock.imitate(Agent, Agent()), )

#TODO add tests for new RPC calls


@pytest.fixture()
def platform_web_service():
    serverkey = "serverkey"
    mock_aip = mock.Mock()
    yield PlatformWebService(serverkey=serverkey,
                             identity=PLATFORM_WEB,
                             address="tcp://stuff",
                             bind_web_address="http://v2:8888")


@contextlib.contextmanager
コード例 #11
0
 def setUp(self):
     ThresholdDetectionAgent.__bases__ = (AgentMock.imitate(Agent,
                                                            Agent()), )