def test_app_with_wrapper(self): app = application.Application( app_name="foo", app_properties={ "command": "/test-command", "stop-command": "/test-stop-command", "daemon": "simple", }, base="core18", prime_dir=self.path, ) self.assertThat( app.get_yaml(prepend_command_chain=["prepend-command-chain"]), Equals( { "command": "command-foo.wrapper", "stop-command": "stop-command-foo.wrapper", "daemon": "simple", "command-chain": ["prepend-command-chain"], } ), ) app.generate_command_wrappers() self.expectThat("command-foo.wrapper", FileExists()) self.expectThat("stop-command-foo.wrapper", FileExists())
def test_socket_mode_change_to_octal(self): app = application.Application( app_name="foo", app_properties={ "command": "test-command", "daemon": "simple", "sockets": { "sock1": {"listen-stream": 8080}, "sock2": { "listen-stream": "$SNAP_COMMON/sock2", "socket-mode": 1000, }, }, }, base="core18", prime_dir=self.path, ) self.expectThat( type( app.get_yaml(prepend_command_chain=[])["sockets"]["sock2"][ "socket-mode" ] ), Equals(yaml_utils.OctInt), )
def test_wrapper(self): app = application.Application( app_name="foo", app_properties=self.app_properties, base=self.base, prime_dir=self.path, ) self.assertThat(app._can_use_wrapper(), Equals(self.expect_wrappers))
def test_no_command_chain_prepended(self): app = application.Application( app_name="foo", app_properties={"command": "test-command"}, base="core18", prime_dir=self.path, ) self.assertThat( app.get_yaml(prepend_command_chain=[]), Equals({"command": "test-command"}) )
def test_no_passthroug(self): app = application.Application( app_name="foo", adapter=application.ApplicationAdapter.NONE, command_chain=["test-command-chain"], passthrough=None, ) app_dict = app.to_dict() self.assertThat(app_dict, Equals({"command-chain": ["test-command-chain"]}))
def _get_apps(self) -> Dict[str, application.Application]: apps = dict() for app_name, app_properties in self._config_data.get("apps", dict()).items(): apps[app_name] = application.Application( app_name=app_name, app_properties=app_properties, base=self._project_config.project.info.base, prime_dir=self._prime_dir, ) return apps
def test_no_mangling(self): app = application.Application( app_name="foo", app_properties={"command": "$SNAP/test-command"}, base="core20", prime_dir=self.path, ) self.assertRaises( errors.InvalidAppCommandNotExecutable, app.get_yaml, prepend_command_chain=["prepend-command-chain"], )
def test_mangling(self): app = application.Application( app_name="foo", app_properties={"command": "$SNAP/test-command"}, base="core18", prime_dir=self.path, ) self.assertThat( app.get_yaml(prepend_command_chain=["prepend-command-chain"]), Equals( {"command": "test-command", "command-chain": ["prepend-command-chain"]} ), )
def test_passthrough_to_dict(self): app = application.Application( app_name="foo", adapter=application.ApplicationAdapter.NONE, command_chain=["test-command-chain"], passthrough={"test-property": "test-value"}, ) app_dict = app.to_dict() self.assertThat( app_dict, Equals({ "command-chain": ["test-command-chain"], "test-property": "test-value" }), )
def test_desktop_file(self): desktop_file_path = "foo.desktop" with open(desktop_file_path, "w") as desktop_file: print("[Desktop Entry]", file=desktop_file) print("Exec=in-snap-exe", file=desktop_file) open("command-chain", "w").close() os.chmod("command-chain", 0o755) app = application.Application( app_name="foo", app_properties=dict(command="/foo", desktop=desktop_file_path), base="core", prime_dir=self.path, ) app.generate_desktop_file(snap_name="foo", gui_dir="gui") expected_desktop_file_path = os.path.join("gui", "foo.desktop") self.expectThat( app.get_yaml(prepend_command_chain=["command-chain"]), Not(Contains("desktop")), ) self.expectThat(expected_desktop_file_path, FileExists())