feat: initial package, with apt and sync modules

This commit is contained in:
Lance Edgar 2024-09-10 09:50:26 -05:00
commit dcfea3acbb
22 changed files with 767 additions and 0 deletions

0
tests/__init__.py Normal file
View file

1
tests/files/foo Normal file
View file

@ -0,0 +1 @@
foo

41
tests/test_apt.py Normal file
View file

@ -0,0 +1,41 @@
# -*- coding: utf-8; -*-
from unittest import TestCase
from unittest.mock import patch, MagicMock
from wuttamess import apt as mod
class TestDistUpgrade(TestCase):
def test_basic(self):
c = MagicMock()
with patch.object(mod, 'update') as update:
with patch.object(mod, 'upgrade') as upgrade:
mod.dist_upgrade(c, frontend='whatever')
update.assert_called_once_with(c)
upgrade.assert_called_once_with(c, dist_upgrade=True, frontend='whatever')
class TestInstall(TestCase):
def test_basic(self):
c = MagicMock()
mod.install(c, 'postfix')
c.run.assert_called_once_with('DEBIAN_FRONTEND=noninteractive apt-get --assume-yes install postfix')
class TestUpdate(TestCase):
def test_basic(self):
c = MagicMock()
mod.update(c)
c.run.assert_called_once_with('apt-get update')
class TestUpgrade(TestCase):
def test_basic(self):
c = MagicMock()
mod.upgrade(c)
c.run.assert_called_once_with('DEBIAN_FRONTEND=noninteractive apt-get --assume-yes --option Dpkg::Options::="--force-confdef" --option Dpkg::Options::="--force-confold" upgrade')

67
tests/test_sync.py Normal file
View file

@ -0,0 +1,67 @@
# -*- coding: utf-8; -*-
from pathlib import Path
from unittest import TestCase
from unittest.mock import patch, MagicMock
from fabsync import SyncedRoot, ItemSelector
from wuttamess import sync as mod
class TestMakeRoot(TestCase):
def test_basic(self):
root = mod.make_root('files')
self.assertIsInstance(root, SyncedRoot)
self.assertEqual(root.src, Path('files'))
self.assertEqual(root.dest, Path('/'))
class TestIsync(TestCase):
def test_basic(self):
c = MagicMock()
root = mod.make_root('files')
with patch.object(mod, 'fabsync') as fabsync:
fabsync.ItemSelector = ItemSelector
# nothing to sync
fabsync.isync.return_value = []
results = list(mod.isync(c, root))
self.assertEqual(results, [])
fabsync.isync.assert_called_once_with(c, root)
# sync one file
fabsync.isync.reset_mock()
result = MagicMock(path='/foo', modified=True)
fabsync.isync.return_value = [result]
results = list(mod.isync(c, root))
self.assertEqual(results, [result])
fabsync.isync.assert_called_once_with(c, root)
# sync with selector
fabsync.isync.reset_mock()
result = MagicMock(path='/foo', modified=True)
fabsync.isync.return_value = [result]
results = list(mod.isync(c, root, 'foo'))
self.assertEqual(results, [result])
fabsync.isync.assert_called_once_with(c, root, selector=fabsync.ItemSelector.new('foo'))
class TestCheckIsync(TestCase):
def test_basic(self):
c = MagicMock()
root = mod.make_root('files')
with patch.object(mod, 'isync') as isync:
# file(s) modified
result = MagicMock(path='/foo', modified=True)
isync.return_value = [result]
self.assertTrue(mod.check_isync(c, root))
# not modified
result = MagicMock(path='/foo', modified=False)
isync.return_value = [result]
self.assertFalse(mod.check_isync(c, root))