mirror of
https://github.com/kevinveenbirkenbach/docker-volume-backup.git
synced 2025-12-29 03:42:08 +00:00
- Use module logger in backup/db.py - Skip db dump when no databases.csv entry is present - Apply black/formatting cleanup across backup/restore/tests https://chatgpt.com/share/69519d45-b0dc-800f-acb6-6fb8504e9b46
41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
import unittest
|
|
from unittest.mock import patch
|
|
|
|
from baudolo.backup.app import requires_stop
|
|
|
|
|
|
class TestRequiresStop(unittest.TestCase):
|
|
@patch("baudolo.backup.app.get_image_info")
|
|
def test_requires_stop_false_when_all_images_are_whitelisted(
|
|
self, mock_get_image_info
|
|
):
|
|
# All containers use images containing allowed substrings
|
|
mock_get_image_info.side_effect = [
|
|
"repo/mastodon:v4",
|
|
"repo/wordpress:latest",
|
|
]
|
|
containers = ["c1", "c2"]
|
|
whitelist = ["mastodon", "wordpress"]
|
|
self.assertFalse(requires_stop(containers, whitelist))
|
|
|
|
@patch("baudolo.backup.app.get_image_info")
|
|
def test_requires_stop_true_when_any_image_is_not_whitelisted(
|
|
self, mock_get_image_info
|
|
):
|
|
mock_get_image_info.side_effect = [
|
|
"repo/mastodon:v4",
|
|
"repo/nginx:latest",
|
|
]
|
|
containers = ["c1", "c2"]
|
|
whitelist = ["mastodon", "wordpress"]
|
|
self.assertTrue(requires_stop(containers, whitelist))
|
|
|
|
@patch("baudolo.backup.app.get_image_info")
|
|
def test_requires_stop_true_when_whitelist_empty(self, mock_get_image_info):
|
|
mock_get_image_info.return_value = "repo/anything:latest"
|
|
self.assertTrue(requires_stop(["c1"], []))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|