Skip to content

Commit

Permalink
Merge pull request #67 from bartfeenstra/increase-coverage
Browse files Browse the repository at this point in the history
Increase test coverage.
  • Loading branch information
bartfeenstra committed Jun 5, 2018
2 parents 513b3c7 + ddbc397 commit 6316101
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 8 deletions.
8 changes: 4 additions & 4 deletions backuppy/location.py
Expand Up @@ -64,7 +64,7 @@ def __str__(self):
:return: str
"""
pass
pass # pragma: no cover


class FilePath(Path):
Expand Down Expand Up @@ -118,7 +118,7 @@ def is_available(self):
:return: bool
"""
pass
pass # pragma: no cover

@abc.abstractmethod
def to_rsync(self, path=None):
Expand All @@ -127,7 +127,7 @@ def to_rsync(self, path=None):
:param path: Optional[backuppy.location.Path]
:return: str
"""
pass
pass # pragma: no cover


class Source(Location):
Expand All @@ -145,7 +145,7 @@ def snapshot(self, name):
:param name: str
"""
pass
pass # pragma: no cover


class PathLocation(Location):
Expand Down
2 changes: 1 addition & 1 deletion backuppy/notifier.py
Expand Up @@ -37,7 +37,7 @@ def alert(self, message):
:param message: str
"""
pass
pass # pragma: no cover


class GroupedNotifiers(Notifier):
Expand Down
1 change: 1 addition & 0 deletions backuppy/tests/resources/configuration/backuppy.json
@@ -1,6 +1,7 @@
{
"name": "Test",
"verbose": true,
"interactive": false,
"notifications": [
{
"type": "stdio"
Expand Down
1 change: 1 addition & 0 deletions backuppy/tests/resources/configuration/backuppy.yml
@@ -1,5 +1,6 @@
name: Test
verbose: true
interactive: false
notifications:
- type: stdio
source:
Expand Down
11 changes: 11 additions & 0 deletions backuppy/tests/test_config.py
Expand Up @@ -87,6 +87,15 @@ def test_verbose_non_boolean(self):
with self.assertRaises(ValueError):
from_configuration_data(f.name, configuration)

def test_interactive_non_boolean(self):
with open('%s/backuppy.json' % CONFIGURATION_PATH) as f:
configuration = json.load(f)
configuration['interactive'] = 666
with NamedTemporaryFile(mode='w+t') as f:
json.dump(configuration, f)
with self.assertRaises(ValueError):
from_configuration_data(f.name, configuration)

def test_notifier_type_missing(self):
with open('%s/backuppy.json' % CONFIGURATION_PATH) as f:
configuration = json.load(f)
Expand Down Expand Up @@ -159,10 +168,12 @@ def test_from_json(self):
with open('%s/backuppy.json' % CONFIGURATION_PATH) as f:
configuration = from_json(f)
self.assertTrue(configuration.verbose)
self.assertFalse(configuration.interactive)


class FromYamlTest(TestCase):
def test_from_Yaml(self):
with open('%s/backuppy.yml' % CONFIGURATION_PATH) as f:
configuration = from_yaml(f)
self.assertTrue(configuration.verbose)
self.assertFalse(configuration.interactive)
46 changes: 43 additions & 3 deletions backuppy/tests/test_location.py
Expand Up @@ -4,9 +4,11 @@
from logging import getLogger
from unittest import TestCase

from parameterized import parameterized
from paramiko import SSHException, SSHClient, PKey

from backuppy.location import PathLocation, SshTarget, FirstAvailableTarget, _new_snapshot_args, PathTarget, AskPolicy
from backuppy.location import PathLocation, SshTarget, FirstAvailableTarget, _new_snapshot_args, PathTarget, AskPolicy, \
FilePath, DirectoryPath
from backuppy.notifier import Notifier
from backuppy.tests import SshLocationContainer

Expand All @@ -31,6 +33,36 @@ def test_new_snapshot_args(self):
self.assertTrue(os.path.exists('/'.join([path, 'latest'])))


class FilePathTest(TestCase):
@parameterized.expand([
('hi/there', 'hi/there'),
('hi/there', '/hi/there'),
])
def test_str(self, expected, path):
sut = FilePath(path)
self.assertEqual(expected, str(sut))

def test_str_should_error_with_trailing_slash(self):
path = '/hi/there/'
with self.assertRaises(ValueError):
FilePath(path)


class DirectoryPathTest(TestCase):
@parameterized.expand([
('hi/there/', 'hi/there/'),
('hi/there/', '/hi/there/'),
])
def test_str(self, expected, path):
sut = DirectoryPath(path)
self.assertEqual(expected, str(sut))

def test_str_should_error_without_trailing_slash(self):
path = '/hi/there'
with self.assertRaises(ValueError):
DirectoryPath(path)


class PathLocationTest(TestCase):
class PathLocation(PathLocation):
def snapshot(self, name):
Expand Down Expand Up @@ -112,15 +144,23 @@ def test_ask_confirm_no_should_reject(self, m_input):


class SshTargetTest(TestCase):
def test_to_rsync(self):
@parameterized.expand([
(None,),
(FilePath('some.file'),),
(DirectoryPath('some.directory/'),),
])
def test_to_rsync(self, subpath):
notifier = Mock(Notifier)
user = 'bart'
host = 'example.com'
port = 666
path = '/var/cache'
sut = SshTarget(notifier, user, host, path, port)
expected = 'bart@example.com:/var/cache/latest/'
if subpath is not None:
expected += str(subpath)
self.assertEquals(
sut.to_rsync(), 'bart@example.com:/var/cache/latest/')
sut.to_rsync(path=subpath), expected)

def test_ssh_options(self):
notifier = Mock(Notifier)
Expand Down

0 comments on commit 6316101

Please sign in to comment.