class TestUpgradeWithEjectAccept(BaseTestUpgradeWithEject): """Test 'aea upgrade' command with request for ejection, accepted by the user.""" CONFIRM_OUTPUT = [True, True] EXPECTED_CLICK_ECHO_CALLS = [ "Ejecting (skill, fetchai/generic_seller:0.19.0)...", "Ejecting item skill fetchai/generic_seller:0.19.0", "Fingerprinting skill components of 'default_author/generic_seller:0.1.0' ...", "Successfully ejected skill fetchai/generic_seller:0.19.0 to ./skills/generic_seller as default_author/generic_seller:0.1.0.", ] EXPECTED_CLICK_CONFIRM_CALLS = [ RegexComparator( "Skill fetchai/generic_seller:0.19.0 prevents the upgrade of the following vendor packages:" ), RegexComparator( "as there isn't a compatible version available on the AEA registry. Would you like to eject it?" ), ] def test_run(self, *mocks): """Run the test.""" super().test_run(*mocks) ejected_package_path = Path( self.t, self.current_agent_context, "skills", "generic_seller" ) assert ejected_package_path.exists() assert ejected_package_path.is_dir()
async def test_send(self): """Test the connect functionality of the webhook connection.""" await self.webhook_connection.connect() assert self.webhook_connection.is_connected is True http_message = HttpMessage( dialogue_reference=("", ""), target=0, message_id=1, performative=HttpMessage.Performative.REQUEST, method="get", url="/", headers="", bodyy="", version="", ) envelope = Envelope( to="addr", sender="my_id", protocol_id=PublicId.from_str("fetchai/http:0.4.0"), message=http_message, ) with patch.object(self.webhook_connection.logger, "warning") as mock_logger: await self.webhook_connection.send(envelope) await asyncio.sleep(0.01) mock_logger.assert_any_call( RegexComparator( "Dropping envelope=.* as sending via the webhook is not possible!" ) )
class TestUpgradeWithEjectAbort(BaseTestUpgradeWithEject): """Test 'aea upgrade' command with request for ejection, refused.""" EXPECTED_CLICK_ECHO_CALLS = ["Abort."] EXPECTED_CLICK_CONFIRM_CALLS = [ RegexComparator( r"Skill fetchai/generic_seller:0.19.0 prevents the upgrade of the following vendor packages:.*as there isn't a compatible version available on the AEA registry\. Would you like to eject it\?" ) ]
def test_build_positive_aea(self): """Test build project-wide entrypoint, positive.""" with cd(self._get_cwd()): self.script_path.write_text("") with patch.object(self.builder.logger, "info") as info_mock: self.builder.call_all_build_entrypoints() info_mock.assert_any_call("Building AEA package...") info_mock.assert_any_call(RegexComparator("Running command '.*script.py .*'"))
async def test_late_message_get_timeout_error(self): """Test send get request w/ 200 response.""" self.http_connection.channel.RESPONSE_TIMEOUT = 1 request_task = self.loop.create_task(self.request("get", "/pets")) envelope = await asyncio.wait_for(self.http_connection.receive(), timeout=10) assert envelope incoming_message, dialogue = self._get_message_and_dialogue(envelope) message = HttpMessage( performative=HttpMessage.Performative.RESPONSE, dialogue_reference=dialogue.dialogue_label.dialogue_reference, target=incoming_message.message_id, message_id=incoming_message.message_id + 1, version=incoming_message.version, headers=incoming_message.headers, status_code=200, status_text="Success", bodyy=b"Response body", ) message.counterparty = incoming_message.counterparty assert dialogue.update(message) response_envelope = Envelope( to=envelope.sender, sender=envelope.to, protocol_id=envelope.protocol_id, context=envelope.context, message=message, ) await asyncio.sleep(1.5) with patch.object(self.http_connection.logger, "warning") as mock_logger: await self.http_connection.send(response_envelope) mock_logger.assert_any_call( RegexComparator( "Dropping message=.* for incomplete_dialogue_label=.* which has timed out." ) ) response = await asyncio.wait_for(request_task, timeout=10) assert ( response.status == 408 and response.reason == "Request Timeout" and await response.text() == "" )
def test_build_positive_package(self): """Test build package entrypoint, positive.""" with cd(self._get_cwd()): self.script_path.write_text("") # add mock configuration build entrypoint with patch.object(self.builder, "_package_dependency_manager") as _mock_mgr: mock_config = MagicMock( component_id=self.component_id, build_entrypoint=str(self.script_path), directory=".", build_directory="test", ) mock_values = MagicMock(return_value=[mock_config]) _mock_mgr._dependencies = MagicMock(values=mock_values) with patch.object(self.builder.logger, "info") as info_mock: self.builder.call_all_build_entrypoints() info_mock.assert_any_call(f"Building package {self.component_id}...") info_mock.assert_any_call(RegexComparator("Running command '.*script.py .*'"))
def test_upgrade(self, mock_confirm, confirm): """Test upgrade.""" mock_confirm.return_value = confirm result = self.run_cli_command("upgrade", "--remote", cwd=self._get_cwd()) assert result.exit_code == 0 mock_confirm.assert_any_call( RegexComparator( r"Found a newer version of this project:.*Would you like to replace this project with it\?.*Warning: the content in the current directory.*will be removed" ) ) # compare with latest fetched agent. ignore = [DEFAULT_AEA_CONFIG_FILE] + filecmp.DEFAULT_IGNORES dircmp = filecmp.dircmp( self.current_agent_context, self.EXPECTED, ignore=ignore ) _left_only, _right_only, diff = dircmp_recursive(dircmp) if confirm: assert diff == _right_only == _left_only == set() else: assert diff == _right_only == set() # temporary: due to change in deps assert _left_only == {"vendor/fetchai/skills/error"}