Skip to content

Commit

Permalink
MULTIPLE_APP_MODE defaults to True now so no breaking changes happen
Browse files Browse the repository at this point in the history
fixed tests with the new MULTIPLE_APP_MODE default
Added an ObjectDoesNotExist exception for when no apps are installed
  • Loading branch information
ckrew committed Mar 14, 2024
1 parent c1ad7b3 commit 6f2cba4
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.core.exceptions import ValidationError
from unittest import mock
from conda.cli.python_api import Commands
from tethys_apps.cli import install_commands
from tethys_cli import install_commands

FNULL = open(os.devnull, "w")

Expand Down
14 changes: 14 additions & 0 deletions tests/unit_tests/test_tethys_apps/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,20 @@ def test_get_configured_standalone_app_given_app_name(self):
self.assertEqual(result.package, "test_app")
mock_tethysapp.objects.get.assert_called_with(package="test_app")

@override_settings(MULTIPLE_APP_MODE=False)
def test_get_configured_standalone_app_no_app_name_no_installed(self):
from tethys_apps.models import TethysApp
from django.core.exceptions import ObjectDoesNotExist

with mock.patch(
"tethys_apps.models.TethysApp", wraps=TethysApp
) as mock_tethysapp:
mock_tethysapp.objects.first.return_value = []
with self.assertRaises(ObjectDoesNotExist):
utilities.get_configured_standalone_app()

mock_tethysapp.objects.first.assert_called_once()

def test_update_decorated_websocket_consumer_class(self):
class TestConsumer(WebsocketConsumer):
def authorized_connect(self):
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/test_tethys_portal/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,11 @@ def test_bokeh_django_staticfiles_finder(self, _):
@mock.patch(
"tethys_portal.settings.yaml.safe_load",
return_value={
"settings": {"TETHYS_PORTAL_CONFIG": {"STANDALONE_APP": "test_app"}}
"settings": {"TETHYS_PORTAL_CONFIG": {"MULTIPLE_APP_MODE": False}}
},
)
def test_portal_config_settings_standalone_app(self, _):
reload(settings)

self.assertTrue(settings.STANDALONE_APP == "test_app")
self.assertTrue(settings.STANDALONE_APP is None)
self.assertTrue(settings.BYPASS_TETHYS_HOME_PAGE)
2 changes: 2 additions & 0 deletions tethys_apps/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,8 @@ def get_configured_standalone_app():
app = TethysApp.objects.get(package=standalone_app)
else:
app = TethysApp.objects.first()
if not app:
raise ObjectDoesNotExist("No Tethys Apps have been installed")

return app

Expand Down
2 changes: 1 addition & 1 deletion tethys_portal/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@

REGISTER_CONTROLLER = TETHYS_PORTAL_CONFIG.pop("REGISTER_CONTROLLER", None)

MULTIPLE_APP_MODE = TETHYS_PORTAL_CONFIG.pop("MULTIPLE_APP_MODE", False)
MULTIPLE_APP_MODE = TETHYS_PORTAL_CONFIG.pop("MULTIPLE_APP_MODE", True)
STANDALONE_APP = TETHYS_PORTAL_CONFIG.pop("STANDALONE_APP", None)
if not MULTIPLE_APP_MODE:
BYPASS_TETHYS_HOME_PAGE = True
Expand Down

0 comments on commit 6f2cba4

Please sign in to comment.