Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sdc50 committed Apr 5, 2024
1 parent 7b34f8a commit 1c454dd
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 24 deletions.
4 changes: 2 additions & 2 deletions tests/apps/tethysapp-test_app/tethysapp/test_app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ class TestApp(TethysAppBase):
"""

name = "Test App"
description = "Place a brief description of your app here."
index = "home"
icon = "test_app/images/icon.gif"
package = "test_app"
icon = f"{package}/images/icon.gif"
root_url = "test-app"
color = "#2c3e50"
description = "Place a brief description of your app here."
tags = ""
enable_feedback = False
feedback_emails = []
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.shortcuts import render
from tethys_sdk.routing import handler, consumer
from tethys_sdk.gizmos import Button
from .app import TestApp as app

from channels.generic.websocket import WebsocketConsumer
import json
Expand Down Expand Up @@ -72,7 +72,7 @@ def home_controller(request):
"script": script,
}

return render(request, "test_app/home.html", context)
return app.render(request, "home.html", context)


@handler(
Expand Down
55 changes: 35 additions & 20 deletions tests/unit_tests/test_tethys_apps/test_base/test_app_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ class TethysAppChild(tethys_app_base.TethysAppBase):
description = "Place a brief description of your app here."


class TethysBaseChild(tethys_app_base.TethysBase):
"""
Tethys Base class for testing
"""

package = "test_base"


class TestTethysBase(unittest.TestCase):
def setUp(self):
pass
Expand All @@ -45,14 +53,6 @@ def get_package_namespace():

self.assertRaises(NotImplementedError, get_package_namespace)

@mock.patch("tethys_cli.cli_colors.write_warning")
def test_index_namespace_deprecation(self, mock_warning):
class TethysAppSubChild(TethysAppChild):
index = "namespace:home"

TethysAppSubChild()
mock_warning.assert_called_once()

@mock.patch("tethys_apps.base.controller.register_controllers")
def test_register_url_maps(self, mock_rc):
app = tethys_app_base.TethysAppBase()
Expand All @@ -71,18 +71,6 @@ def test_register_url_maps(self, mock_rc):
self.assertIn(m, modules)
self.assertIn(app.index, kwargs["index"])

@mock.patch("tethys_cli.cli_colors.write_warning")
def test_register_url_maps_deprecation(self, mock_warning):
app = tethys_app_base.TethysAppBase()
app.package = "package"
app.root_url = "root_url"
app.index = "index"

app.url_maps = mock.MagicMock(return_value=["test"])
result = app.registered_url_maps
self.assertEqual(app.url_maps(), result)
mock_warning.assert_called_once()

@mock.patch("tethys_apps.base.app_base.re_path")
@mock.patch("tethys_apps.base.app_base.TethysBaseMixin")
def test_url_patterns(self, mock_tbm, mock_re_path):
Expand Down Expand Up @@ -394,6 +382,33 @@ def test_db_object(self):
with self.assertRaises(NotImplementedError):
tethys_app_base.TethysBase.db_object

@mock.patch("tethys_apps.base.app_base.render")
def test_render(self, mock_render):
mock_request = mock.MagicMock()
template = "test.html"
TethysBaseChild.render(mock_request, template)
self.assertEqual(
mock_render.call_args.args,
(mock_request, f"{TethysBaseChild.package}/{template}"),
)

@mock.patch("tethys_apps.base.app_base.redirect")
def test_redirect(self, mock_redirect):
TethysBaseChild.redirect("test")
mock_redirect.assert_called_with(f"{TethysBaseChild.package}:test")

@mock.patch("tethys_apps.base.app_base.redirect")
def test_redirect_absolute(self, mock_redirect):
TethysBaseChild.redirect("/test")
mock_redirect.assert_called_with("/test")

@mock.patch("tethys_apps.base.app_base.reverse")
def test_reverse(self, mock_reverse):
TethysBaseChild.reverse("test")
self.assertEqual(
mock_reverse.call_args.args, (f"{TethysBaseChild.package}:test",)
)


class TestTethysExtensionBase(unittest.TestCase):
def setUp(self):
Expand Down
12 changes: 12 additions & 0 deletions tests/unit_tests/test_tethys_apps/test_templatetags/test_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,15 @@ def test_get_tags_from_apps_dict_dont_show(self):
)
ret_tag_list = t.get_tags_from_apps(self.mock_dict_apps)
self.assertNotIn("disabled", ret_tag_list)

def test_url(self):
app = {"package": "test"}
controller_name = "controller"
ret = t.url(app, controller_name)
self.assertEqual(ret, f"{app['package']}:{controller_name}")

def test_public(self):
app = {"package": "test"}
static_path = "path/to/static"
ret = t.public(app, static_path)
self.assertEqual(ret, f"{app['package']}/{static_path}")

0 comments on commit 1c454dd

Please sign in to comment.