forked from docker-archive/docker-registry
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve coverage of docker_registry.lib
Docker-DCO-1.1-Signed-off-by: Gabor Nagy <mail@aigeruth.hu> (github: Aigeruth)
- Loading branch information
Showing
9 changed files
with
190 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[report] | ||
exclude_lines = | ||
if __name__ == .__main__.: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import mock | ||
import unittest | ||
|
||
from docker_registry.lib import index | ||
|
||
|
||
class TestIndex(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.index = index.Index() | ||
|
||
def test_cover_passed_methods(self): | ||
self.index._handle_repository_created(None, None, None, None) | ||
self.index._handle_repository_updated(None, None, None, None) | ||
self.index._handle_repository_deleted(None, None, None) | ||
|
||
def test_results(self): | ||
self.assertRaises(NotImplementedError, self.index.results, None) | ||
|
||
|
||
class TestLoad(unittest.TestCase): | ||
|
||
@mock.patch('docker_registry.lib.config.load') | ||
def test_search_backend(self, load): | ||
load.return_value = mock.MagicMock(search_backend='x') | ||
self.assertRaises(NotImplementedError, index.load) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import mock | ||
import unittest | ||
|
||
from docker_registry.lib.index import db | ||
|
||
|
||
class TestVersion(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.version = db.Version() | ||
|
||
def test_repr(self): | ||
self.assertEqual(type(repr(self.version)), str) | ||
|
||
|
||
class TestRepository(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.repository = db.Repository() | ||
|
||
def test_repr(self): | ||
self.assertEqual(type(repr(self.repository)), str) | ||
|
||
|
||
class TestSQLAlchemyIndex(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.index = db.SQLAlchemyIndex(database="sqlite://") | ||
|
||
@mock.patch('sqlalchemy.orm.query.Query.first') | ||
def test_setup_database(self, first): | ||
first = mock.Mock( # noqa | ||
side_effect=db.sqlalchemy.exc.OperationalError) | ||
self.assertRaises( | ||
NotImplementedError, db.SQLAlchemyIndex, database="sqlite://") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import mock | ||
|
||
from docker_registry.lib import cache | ||
from tests.base import TestCase | ||
|
||
|
||
class TestCache(TestCase): | ||
|
||
def setUp(self): | ||
self.cache = mock.MagicMock( | ||
host='localhost', port=1234, db=0, password='pass') | ||
|
||
def tearDown(self): | ||
cache.redis_conn = None | ||
cache.cache_prefix = None | ||
|
||
@mock.patch.object(cache, 'logger') | ||
def test_enable_redis_cache(self, logger): | ||
self.assertEqual(cache.redis_conn, None) | ||
self.assertEqual(cache.cache_prefix, None) | ||
cache.enable_redis_cache(None, None) | ||
self.assertEqual(logger.warn.call_count, 1) | ||
|
||
cache.enable_redis_cache(self.cache, None) | ||
self.assertTrue(cache.redis_conn is not None) | ||
self.assertEqual(type(cache.redis_conn), cache.redis.StrictRedis) | ||
self.assertTrue(cache.cache_prefix is not None) | ||
self.assertEqual(cache.cache_prefix, 'cache_path:/') | ||
|
||
cache.enable_redis_cache(self.cache, 'test') | ||
self.assertEqual(cache.cache_prefix, 'cache_path:test') | ||
|
||
@mock.patch.object(cache, 'logger') | ||
@mock.patch.object(cache.lru, 'init') | ||
def test_enable_redis_lru(self, lru_init, logger): | ||
cache.enable_redis_lru(None, None) | ||
self.assertEqual(logger.warn.call_count, 1) | ||
|
||
cache.enable_redis_lru(self.cache, None) | ||
self.assertEqual(logger.info.call_count, 2) | ||
lru_init.assert_called_once_with( | ||
host=self.cache.host, port=self.cache.port, db=self.cache.db, | ||
password=self.cache.password, path='/') | ||
|
||
lru_init.reset_mock() | ||
path = 'test' | ||
cache.enable_redis_lru(self.cache, path) | ||
lru_init.assert_called_once_with( | ||
host=self.cache.host, port=self.cache.port, db=self.cache.db, | ||
password=self.cache.password, path=path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import mock | ||
|
||
from docker_registry.lib import checksums | ||
from tests.base import TestCase | ||
|
||
|
||
class TestShaMethods(TestCase): | ||
|
||
def test_sha256_file(self): | ||
self.assertEqual( | ||
checksums.sha256_file(None, None), | ||
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855') | ||
self.assertEqual( | ||
checksums.sha256_file(None, 'test'), | ||
'9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08') | ||
|
||
def test_compute_simple(self): | ||
out = checksums.compute_simple(None, '') | ||
self.assertTrue(out.startswith('sha256:')) | ||
nl = '01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b' | ||
self.assertTrue(out.endswith(nl)) | ||
|
||
out = checksums.compute_simple(None, 'test') | ||
h = 'f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2' | ||
self.assertTrue(out.endswith(h)) | ||
|
||
|
||
class TestTarSum(TestCase): | ||
|
||
def setUp(self): | ||
self.tar_sum = checksums.TarSum(None) | ||
|
||
def test_append(self): | ||
self.tar_sum.header_fields = tuple() | ||
member = mock.MagicMock(size=1) | ||
tarobj = mock.MagicMock( | ||
extractfile=mock.MagicMock(side_effect=KeyError)) | ||
self.tar_sum.append(member, tarobj) | ||
self.assertEqual(len(self.tar_sum.hashes), 1) | ||
self.assertEqual( | ||
self.tar_sum.hashes[0], | ||
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters