Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge duplicate "version command" tests and remove extemporaneous one #1141

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
### Description
This merge request addresses...

### Changes Made to Code:
### Changes Made to Code
-

### Related
### Related PRs, Issues, and Discussions
-

### Additional Notes
-

### Quality Checks
- [ ] New code is 100% tested
- [ ] Code has been formated
- [ ] Code has been linted
- [ ] At least one new test has been written for new code
- [ ] New code has 100% test coverage
- [ ] Code has been formatted with Black
- [ ] Code has been linted with flake8
- [ ] Docstrings for new methods have been added
- [ ] The documentation has been updated appropriately
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@ def tearDown(self):

@mock.patch("tethys_apps.templatetags.site_settings.settings")
@mock.patch("tethys_apps.templatetags.site_settings.Path.is_file")
def test_get_css_in_static_root(self, mock_isfile, mock_settings):
def test_load_custom_css_empty_str(self, mock_isfile, mock_settings):
mock_isfile.return_value = True
mock_settings.STATIC_ROOT = "test_base_path"

ret = ss.load_custom_css("") # test empty str value
self.assertEqual(ret, "")

@mock.patch("tethys_apps.templatetags.site_settings.settings")
@mock.patch("tethys_apps.templatetags.site_settings.Path.is_file")
def test_load_custom_css_in_static_root(self, mock_isfile, mock_settings):
mock_isfile.return_value = True
mock_settings.STATIC_ROOT = "test_base_path"

Expand All @@ -24,7 +33,7 @@ def test_get_css_in_static_root(self, mock_isfile, mock_settings):

@mock.patch("tethys_apps.templatetags.site_settings.settings")
@mock.patch("tethys_apps.templatetags.site_settings.Path.is_file")
def test_get_css_in_staticfiles_dirs(self, mock_isfile, mock_settings):
def test_load_custom_css_in_staticfiles_dirs(self, mock_isfile, mock_settings):
mock_isfile.side_effect = [False, True]
mock_settings.STATIC_ROOT = "test_base_path1"
mock_settings.STATICFILES_DIRS = ["test_base_path2"]
Expand All @@ -37,7 +46,7 @@ def test_get_css_in_staticfiles_dirs(self, mock_isfile, mock_settings):

@mock.patch("tethys_apps.templatetags.site_settings.settings")
@mock.patch("tethys_apps.templatetags.site_settings.Path.is_file")
def test_get_css_is_code(self, mock_isfile, mock_settings):
def test_load_custom_css_is_code(self, mock_isfile, mock_settings):
mock_isfile.return_value = False
mock_settings.STATIC_ROOT = "test_base_path1"
mock_settings.STATICFILES_DIRS = ["test_base_path2"]
Expand All @@ -47,7 +56,7 @@ def test_get_css_is_code(self, mock_isfile, mock_settings):
ret, "<style>.navbar-brand { background-color: darkred; }</style>"
)

def test_long_css_text(self):
def test_load_custom_css_long_css_text(self):
long_css_text = """
.site-header { margin: 0 50px 0 0; background-color: red; }
.site-header .navbar-brand {
Expand All @@ -62,3 +71,18 @@ def test_long_css_text(self):

ret = ss.load_custom_css(long_css_text)
self.assertEqual(ret, f"<style>{long_css_text}</style>")

@mock.patch("tethys_apps.templatetags.site_settings.log")
@mock.patch("tethys_apps.templatetags.site_settings.settings")
@mock.patch("tethys_apps.templatetags.site_settings.Path.is_file")
def test_load_custom_css_long_path(self, mock_isfile, mock_settings, mock_log):
mock_settings.STATIC_ROOT = "test_base_path1"
mock_settings.STATICFILES_DIRS = ["test_base_path2"]
long_path = "im/a/very/long/path/to/a/file/that/does/not/exist.css"
mock_isfile.side_effect = OSError("TEST OUTPUT: File path too long")

ret = ss.load_custom_css(long_path)
self.assertEqual(ret, "")
mock_log.warning.assert_called_with(
f"Could not load file '{long_path}' for custom styles: TEST OUTPUT: File path too long"
)
6 changes: 3 additions & 3 deletions tests/unit_tests/test_tethys_cli/test_version_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ def test_add_version_parser(self):
func=vc.version_command
)

@mock.patch("builtins.print")
@mock.patch("tethys_cli.version_command.print")
def test_version_command(self, mock_print):
import tethys_portal
from tethys_portal import __version__

mock_args = mock.MagicMock()
vc.version_command(mock_args)
mock_print.assert_called_with(tethys_portal.__version__)
mock_print.assert_called_with(__version__)
Original file line number Diff line number Diff line change
Expand Up @@ -1370,7 +1370,6 @@ class CustomMapLayoutThing(MapLayoutMixin):
"renamable": False,
"show_legend": True,
"legend_url": None,
"legend_url": None,
},
)

Expand Down
21 changes: 0 additions & 21 deletions tests/unit_tests/test_version_command.py

This file was deleted.

4 changes: 2 additions & 2 deletions tethys_apps/templatetags/site_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def load_custom_css(var):
# an OSError will be raised during the file path checks. This could also happen
# if a lengthy file path is given or is otherwise invalid.
except OSError as e:
oserror_exception = ": " + str(e)
oserror_exception = str(e)
else:
oserror_exception = ""

Expand All @@ -52,7 +52,7 @@ def load_custom_css(var):
if not any(c in var for c in common_css_chars):
# This appears to be a filename and not a CSS string
log.warning(
"Could not load file '%s' for custom styles%s", var, oserror_exception
f"Could not load file '{var}' for custom styles: {oserror_exception}"
)
return ""

Expand Down
Loading