diff --git a/tests/unit_tests/test_tethys_cli/test_proxyapps_commands.py b/tests/unit_tests/test_tethys_cli/test_proxyapps_commands.py new file mode 100644 index 000000000..fc484ecd0 --- /dev/null +++ b/tests/unit_tests/test_tethys_cli/test_proxyapps_commands.py @@ -0,0 +1,43 @@ +from tethys_apps.models import ProxyApp + +from unittest import mock +from io import StringIO +from tethys_cli.proxyapps_commands import add_proxyapp, update_proxyapp, list_apps + +from django.test import TestCase +import unittest + + +class TestProxyAppsCommand(TestCase): + def setUp(self): + self.app_name = "My Proxy App for Testing" + self.endpoint = "http://foo.example.com/my-proxy-app" + self.back_url = "http://bar.example.com/apps/" + self.logo = "http://foo.example.com/my-proxy-app/logo.png" + self.description = "This is an app that is not here." + self.tags = '"Water","Earth","Fire","Air"' + self.open_in_new_tab = True + + self.proxy_app = ProxyApp( + name=self.app_name, + endpoint=self.endpoint, + logo_url=self.logo, + back_url=self.back_url, + description=self.description, + tags=self.tags, + open_in_new_tab=self.open_in_new_tab, + ) + self.proxy_app.save() + + + def tearDown(self): + print("hellos") + self.proxy_app.delete() + + @mock.patch('sys.stdout', new_callable=StringIO) + def test_list_proxy_apps(self,mock_stdout): + expected_output = "Proxy Apps:\n My Proxy App for Testing" + list_apps() + self.assertEqual(mock_stdout.getvalue().strip(), expected_output) + + \ No newline at end of file diff --git a/tethys_cli/proxyapps_commands.py b/tethys_cli/proxyapps_commands.py index f9cb79e4d..1aefac678 100644 --- a/tethys_cli/proxyapps_commands.py +++ b/tethys_cli/proxyapps_commands.py @@ -24,7 +24,7 @@ def add_proxyapps_parser(subparsers): proxyapps_parser.add_argument( "-a", "--add", - help="Add a new proxy app. Arguments: proxy_app_name endpoint description [logo_url] [tags] [enabled] [show_in_apps_library] [back_url] [open_new_tab] [display_external_icon]", + help="Add a new proxy app. Arguments: proxy_app_name endpoint [description] [logo_url] [tags] [enabled] [show_in_apps_library] [back_url] [open_new_tab] [display_external_icon]", nargs="+", ) proxyapps_parser.add_argument( @@ -67,10 +67,10 @@ def update_proxyapp(args): write_error(f"proxy_app_name cannot be empty") return if app_key is None: - write_error(f"proxy_app_name cannot be empty") + write_error(f"proxy_app_key cannot be empty") return if app_value is None: - write_error(f"proxy_app_name cannot be empty") + write_error(f"proxy_app_value cannot be empty") return try: proxy_app = ProxyApp.objects.get(name=app_name) @@ -108,9 +108,6 @@ def add_proxyapp(args): if app_endpoint == "": write_error(f"proxy_app_endpoint cannot be empty") return - if app_description == "": - write_error(f"proxy_app_description cannot be empty") - return try: proxy_app = ProxyApp.objects.create( name=app_name,