Browse Source

improve test_get_security_dir

Thomas Waldmann 2 years ago
parent
commit
d9875a4d7e
1 changed files with 9 additions and 10 deletions
  1. 9 10
      src/borg/testsuite/helpers.py

+ 9 - 10
src/borg/testsuite/helpers.py

@@ -702,29 +702,28 @@ def test_get_keys_dir(monkeypatch):
 def test_get_security_dir(monkeypatch):
     """test that get_security_dir respects environment"""
     monkeypatch.delenv("BORG_BASE_DIR", raising=False)
+    home_dir = os.path.expanduser("~")
     if is_win32:
         monkeypatch.delenv("BORG_SECURITY_DIR", raising=False)
-        assert get_security_dir() == os.path.join(
-            os.path.expanduser("~"), "AppData", "Local", "borg", "borg", "security"
-        )
+        assert get_security_dir() == os.path.join(home_dir, "AppData", "Local", "borg", "borg", "security")
         assert get_security_dir(repository_id="1234") == os.path.join(
-            os.path.expanduser("~"), "AppData", "Local", "borg", "borg", "security", "1234"
+            home_dir, "AppData", "Local", "borg", "borg", "security", "1234"
         )
+        monkeypatch.setenv("BORG_SECURITY_DIR", home_dir)
+        assert get_security_dir() == home_dir
     elif is_darwin:
         monkeypatch.delenv("BORG_SECURITY_DIR", raising=False)
-        assert get_security_dir() == os.path.join(os.path.expanduser("~"), "Library", "Preferences", "borg", "security")
+        assert get_security_dir() == os.path.join(home_dir, "Library", "Preferences", "borg", "security")
         assert get_security_dir(repository_id="1234") == os.path.join(
-            os.path.expanduser("~"), "Library", "Preferences", "borg", "security", "1234"
+            home_dir, "Library", "Preferences", "borg", "security", "1234"
         )
         monkeypatch.setenv("BORG_SECURITY_DIR", "/var/tmp")
         assert get_security_dir() == "/var/tmp"
     else:
         monkeypatch.delenv("XDG_CONFIG_HOME", raising=False)
         monkeypatch.delenv("BORG_SECURITY_DIR", raising=False)
-        assert get_security_dir() == os.path.join(os.path.expanduser("~"), ".config", "borg", "security")
-        assert get_security_dir(repository_id="1234") == os.path.join(
-            os.path.expanduser("~"), ".config", "borg", "security", "1234"
-        )
+        assert get_security_dir() == os.path.join(home_dir, ".config", "borg", "security")
+        assert get_security_dir(repository_id="1234") == os.path.join(home_dir, ".config", "borg", "security", "1234")
         monkeypatch.setenv("XDG_CONFIG_HOME", "/var/tmp/.config")
         assert get_security_dir() == os.path.join("/var/tmp/.config", "borg", "security")
         monkeypatch.setenv("BORG_SECURITY_DIR", "/var/tmp")