Skip to content

Commit

Permalink
Fix unit tests for python 3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
dashmage committed Oct 11, 2023
1 parent 0ef9eb9 commit dfe2a10
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import logging
import os
import subprocess
from os.path import islink

from jinja2 import Template
from ops.charm import CharmBase
Expand Down Expand Up @@ -85,7 +86,7 @@ def _render_config(self, config):
with open("/etc/nginx/sites-available/{}".format(site_conf_name), "wb") as f:
b = t.render(config=config).encode("UTF-8")
f.write(b)
if not os.path.islink("/etc/nginx/sites-enabled/{}".format(site_conf_name)):
if not islink("/etc/nginx/sites-enabled/{}".format(site_conf_name)):
os.symlink(
"/etc/nginx/sites-available/{}".format(site_conf_name),
"/etc/nginx/sites-enabled/{}".format(site_conf_name),
Expand Down
5 changes: 2 additions & 3 deletions tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,16 @@ def test_reload_config(self, mock_subproc):
harness.charm._reload_config()
assert mock_subproc.call_args == call(["service", "nginx", "restart"])

@patch("os.path.islink")
@patch("charm.islink")
@patch("os.symlink")
@patch("subprocess.check_call")
def test_render_config(self, mock_subproc, os_symlink, os_path_islink):
harness = Harness(NginxCharm)
self.addCleanup(harness.cleanup)
harness.begin()
config = {}
mock_open_call = mock_open(read_data="")
os_path_islink.return_value = False
with patch("builtins.open", mock_open_call):
with patch("builtins.open", mock_open()) as mock_open_call:
harness.charm._render_config(config)
assert mock_open_call.call_args_list[0] == call("templates/nginx.conf.j2")
assert mock_open_call.call_args_list[1] == call("/etc/nginx/nginx.conf", "wb")
Expand Down

0 comments on commit dfe2a10

Please sign in to comment.