40 lines
1.4 KiB
Python
40 lines
1.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
This program has been developed by students from the bachelor Computer Science at Utrecht
|
|
University within the Software Project course.
|
|
© Copyright Utrecht University (Department of Information and Computing Sciences)
|
|
"""
|
|
|
|
from mock import patch, mock
|
|
|
|
from robot_interface.core.config import Settings
|
|
from robot_interface.endpoints.main_receiver import MainReceiver
|
|
|
|
|
|
def test_environment_variables(monkeypatch):
|
|
"""
|
|
When environment variables are set, creating settings should use these.
|
|
"""
|
|
monkeypatch.setenv("AGENT__CONTROL_BACKEND_HOST", "some_value_that_should_be_different")
|
|
|
|
settings = Settings()
|
|
|
|
assert settings.agent_settings.control_backend_host == "some_value_that_should_be_different"
|
|
|
|
|
|
@patch("robot_interface.endpoints.main_receiver.settings")
|
|
@patch("robot_interface.endpoints.socket_base.settings")
|
|
def test_create_endpoint_custom_host(base_settings, main_settings):
|
|
"""
|
|
When a custom host is given in the settings, check that an endpoint's socket connects to it.
|
|
"""
|
|
fake_context = mock.Mock()
|
|
fake_socket = mock.Mock()
|
|
fake_context.socket.return_value = fake_socket
|
|
base_settings.agent_settings.control_backend_host = "not_localhost"
|
|
main_settings.agent_settings.main_receiver_port = 9999
|
|
|
|
_ = MainReceiver(fake_context)
|
|
|
|
fake_socket.connect.assert_called_once_with("tcp://not_localhost:9999")
|