Skip to content

Commit

Permalink
added tests and
Browse files Browse the repository at this point in the history
  • Loading branch information
romer8 committed Dec 26, 2023
1 parent fcc8f51 commit 1de2699
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
43 changes: 43 additions & 0 deletions tests/unit_tests/test_tethys_cli/test_proxyapps_commands.py
Original file line number Diff line number Diff line change
@@ -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)


9 changes: 3 additions & 6 deletions tethys_cli/proxyapps_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 1de2699

Please sign in to comment.