def test_start_websocket_connection_thread_pool_executor_instantiated():
        thread_pool_executor_mock = MagicMock()
        with patch("gsy_e_sdk.clients.rest_asset_client.ThreadPoolExecutor",
                   return_value=thread_pool_executor_mock) as mocked_class:
            client = RestAssetClient(asset_uuid=TEST_ASSET_UUID)

            mocked_class.assert_called_with(max_workers=MAX_WORKER_THREADS)
            assert client.callback_thread is thread_pool_executor_mock
 def test_constructor_setup_variables_from_env(simulation_id, exp_sim_id, domain_name,
                                               exp_dom_name, wss_domain, exp_wss_domain):
     """Test whether simulation_id, domain_name and websockets_domain_name attributes
     are properly set when explicitly specified and when they are not (call env variables)."""
     client = RestAssetClient(asset_uuid=TEST_ASSET_UUID,
                              simulation_id=simulation_id,
                              domain_name=domain_name,
                              websockets_domain_name=wss_domain)
     assert client.simulation_id == exp_sim_id
     assert client.domain_name == exp_dom_name
     assert client.websockets_domain_name == exp_wss_domain
    def test_start_websocket_connection_websocket_thread_instantiated_and_started():
        websocket_thread_mock = MagicMock()
        with patch("gsy_e_sdk.clients.rest_asset_client.WebsocketThread",
                   return_value=websocket_thread_mock) as mocked_class:
            client = RestAssetClient(asset_uuid=TEST_ASSET_UUID)
            websocket_uri = f"{client.websockets_domain_name}/" \
                            f"{client.simulation_id}/{client.asset_uuid}/"

            mocked_class.assert_called_with(websocket_uri,
                                            client.domain_name,
                                            client.dispatcher)
            assert client.websocket_thread is websocket_thread_mock
            client.websocket_thread.start.assert_called()
    def on_trade(self, trade_info):
        logging.debug("Trade info: %s", trade_info)

    def on_finish(self, finish_info):
        self.is_finished = True


simulation_id, domain_name, websockets_domain_name = get_sim_id_and_domain_names(
)

aggr = TestAggregator(aggregator_name="test_aggr")

load1_uuid = get_area_uuid_from_area_name_and_collaboration_id(
    simulation_id, "Load", domain_name)
load1 = RestAssetClient(load1_uuid)

pv1_uuid = get_area_uuid_from_area_name_and_collaboration_id(
    simulation_id, "PV", domain_name)
pv1 = RestAssetClient(pv1_uuid)

load1.select_aggregator(aggr.aggregator_uuid)
pv1.select_aggregator(aggr.aggregator_uuid)

house_uuid = get_area_uuid_from_area_name_and_collaboration_id(
    simulation_id, "House", domain_name)
house_market = RestMarketClient(house_uuid)
house_market.select_aggregator(aggr.aggregator_uuid)

while not aggr.is_finished:
    sleep(0.5)
 def test_start_websocket_connection_device_websocket_message_receiver_instantiated():
     device_websocket_msg_rec_mock = MagicMock()
     with patch("gsy_e_sdk.clients.rest_asset_client.DeviceWebsocketMessageReceiver",
                return_value=device_websocket_msg_rec_mock):
         client = RestAssetClient(asset_uuid=TEST_ASSET_UUID)
         assert client.dispatcher is device_websocket_msg_rec_mock
 def test_constructor_jwt_token_setup(set_value, expected_call_val):
     with patch("gsy_e_sdk.clients.rest_asset_client."
                "retrieve_jwt_key_from_server") as mocked_func:
         RestAssetClient(asset_uuid=TEST_ASSET_UUID,
                         sim_api_domain_name=set_value)
         mocked_func.assert_called_with(expected_call_val)
def fixture_rest_asset_client():
    return RestAssetClient(asset_uuid=TEST_ASSET_UUID,
                           simulation_id=TEST_SIMULATION_ID,
                           domain_name=TEST_DOMAIN_NAME,
                           websockets_domain_name=TEST_WEBSOCKETS_DOMAIN_NAME)
        self.current_pv_energy_measurement_kWh += 1
        self.current_load_energy_measurement_kWh += 1

    def on_tick(self, tick_info):
        """Execute the following code when a new tick was started."""
        logging.debug("Progress information on the device: %s", tick_info)

    def on_trade(self, trade_info):
        """Execute the following code when a trade happened in the current market."""
        logging.debug("Trade info: %s", trade_info)


simulation_id, domain_name, websockets_domain_name = get_sim_id_and_domain_names(
)

load_uuid = get_area_uuid_from_area_name_and_collaboration_id(
    simulation_id, "Load", domain_name)
load = RestAssetClient(load_uuid)

pv_uuid = get_area_uuid_from_area_name_and_collaboration_id(
    simulation_id, "PV", domain_name)
pv = RestAssetClient(pv_uuid)

aggregator = TestAggregator(aggregator_name="test_aggregator")

pv.select_aggregator(aggregator.aggregator_uuid)
load.select_aggregator(aggregator.aggregator_uuid)

while True:
    sleep(0.5)