summaryrefslogtreecommitdiff
path: root/morphlib/remoterepocache_tests.py
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2016-03-02 17:11:34 +0000
committerSam Thursfield <sam.thursfield@codethink.co.uk>2016-03-16 19:11:21 +0000
commitd58d8e8f7a4ec03ff14021a4515c8283dad52573 (patch)
tree5ece2d0524e4423bb953e6140831c9fde93b7219 /morphlib/remoterepocache_tests.py
parent014a029ade9a045a839ca86c35690b218098ea33 (diff)
downloadmorph-d58d8e8f7a4ec03ff14021a4515c8283dad52573.tar.gz
Unify local and remote repo cache modules
There's not really any reason you'd want to use the RemoteRepoCache class except as a workaround for the slow speed of some LocalRepoCache operations, so I can't see this ruining anyone's day. The main reason for doing this is so we can simply the sourceresolver code. One reason that the sourceresolver class is so hopelessly complicated is that it right now has to use two incompatible interfaces for Git repo caches. I've taken the opportunity to detangle the RepoCache class from the App class. Now all of the configuration for the RepoCache class is passed into the constructor explicitly. This makes the class usable from outside Morph: resolver = morphlib.repoaliasresolver.RepoAliasResolver(aliases=[]) repo_cache = morphlib.repocache.RepoCache('/src/cache/gits', resolver) Change-Id: I596c81d7645b67504c88e555172a8c238f4f8a66
Diffstat (limited to 'morphlib/remoterepocache_tests.py')
-rw-r--r--morphlib/remoterepocache_tests.py137
1 files changed, 0 insertions, 137 deletions
diff --git a/morphlib/remoterepocache_tests.py b/morphlib/remoterepocache_tests.py
deleted file mode 100644
index 966e74d5..00000000
--- a/morphlib/remoterepocache_tests.py
+++ /dev/null
@@ -1,137 +0,0 @@
-# Copyright (C) 2012-2015 Codethink Limited
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; version 2 of the License.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License along
-# with this program. If not, see <http://www.gnu.org/licenses/>.
-
-
-import json
-import unittest
-import urllib2
-
-import morphlib
-
-
-class RemoteRepoCacheTests(unittest.TestCase):
-
- def _resolve_ref_for_repo_url(self, repo_url, ref):
- return self.sha1s[repo_url][ref]
-
- def _cat_file_for_repo_url(self, repo_url, sha1, filename):
- try:
- return self.files[repo_url][sha1][filename]
- except KeyError:
- raise urllib2.HTTPError(url='', code=404, msg='Not found',
- hdrs={}, fp=None)
-
- def _ls_tree_for_repo_url(self, repo_url, sha1):
- return json.dumps({
- 'repo': repo_url,
- 'ref': sha1,
- 'tree': self.files[repo_url][sha1]
- })
-
- def setUp(self):
- self.sha1s = {
- 'git://gitorious.org/baserock/morph': {
- 'master': 'e28a23812eadf2fce6583b8819b9c5dbd36b9fb9'
- }
- }
- self.files = {
- 'git://gitorious.org/baserock-morphs/linux': {
- 'e28a23812eadf2fce6583b8819b9c5dbd36b9fb9': {
- 'linux.morph': 'linux morphology'
- }
- }
- }
- self.server_url = 'http://foo.bar'
- aliases = [
- 'upstream=git://gitorious.org/baserock-morphs/#foo',
- 'baserock=git://gitorious.org/baserock/#foo'
- ]
- resolver = morphlib.repoaliasresolver.RepoAliasResolver(aliases)
- self.cache = morphlib.remoterepocache.RemoteRepoCache(
- self.server_url, resolver)
- self.cache._resolve_ref_for_repo_url = self._resolve_ref_for_repo_url
- self.cache._cat_file_for_repo_url = self._cat_file_for_repo_url
- self.cache._ls_tree_for_repo_url = self._ls_tree_for_repo_url
-
- def test_sets_server_url(self):
- self.assertEqual(self.cache.server_url, self.server_url)
-
- def test_resolve_existing_ref_for_existing_repo(self):
- sha1 = self.cache.resolve_ref('baserock:morph', 'master')
- self.assertEqual(
- sha1,
- self.sha1s['git://gitorious.org/baserock/morph']['master'])
-
- def test_fail_resolving_existing_ref_for_non_existent_repo(self):
- self.assertRaises(morphlib.remoterepocache.ResolveRefError,
- self.cache.resolve_ref, 'non-existent-repo',
- 'master')
-
- def test_fail_resolving_non_existent_ref_for_existing_repo(self):
- self.assertRaises(morphlib.remoterepocache.ResolveRefError,
- self.cache.resolve_ref, 'baserock:morph',
- 'non-existent-ref')
-
- def test_fail_resolving_non_existent_ref_for_non_existent_repo(self):
- self.assertRaises(morphlib.remoterepocache.ResolveRefError,
- self.cache.resolve_ref, 'non-existent-repo',
- 'non-existent-ref')
-
- def test_cat_existing_file_in_existing_repo_and_ref(self):
- content = self.cache.cat_file(
- 'upstream:linux', 'e28a23812eadf2fce6583b8819b9c5dbd36b9fb9',
- 'linux.morph')
- self.assertEqual(content, 'linux morphology')
-
- def test_fail_cat_file_using_invalid_sha1(self):
- self.assertRaises(morphlib.remoterepocache.CatFileError,
- self.cache.cat_file, 'upstream:linux', 'blablabla',
- 'linux.morph')
-
- def test_fail_cat_non_existent_file_in_existing_repo_and_ref(self):
- self.assertRaises(morphlib.remoterepocache.CatFileError,
- self.cache.cat_file, 'upstream:linux',
- 'e28a23812eadf2fce6583b8819b9c5dbd36b9fb9',
- 'non-existent-file')
-
- def test_fail_cat_file_in_non_existent_ref_in_existing_repo(self):
- self.assertRaises(morphlib.remoterepocache.CatFileError,
- self.cache.cat_file, 'upstream:linux',
- 'ecd7a325095a0d19b8c3d76f578d85b979461d41',
- 'linux.morph')
-
- def test_fail_cat_file_in_non_existent_repo(self):
- self.assertRaises(morphlib.remoterepocache.CatFileError,
- self.cache.cat_file, 'non-existent-repo',
- 'e28a23812eadf2fce6583b8819b9c5dbd36b9fb9',
- 'some-file')
-
- def test_ls_tree_in_existing_repo_and_ref(self):
- content = self.cache.ls_tree(
- 'upstream:linux', 'e28a23812eadf2fce6583b8819b9c5dbd36b9fb9')
- self.assertEqual(content, ['linux.morph'])
-
- def test_fail_ls_tree_using_invalid_sha1(self):
- self.assertRaises(morphlib.remoterepocache.LsTreeError,
- self.cache.ls_tree, 'upstream:linux', 'blablabla')
-
- def test_fail_ls_file_in_non_existent_ref_in_existing_repo(self):
- self.assertRaises(morphlib.remoterepocache.LsTreeError,
- self.cache.ls_tree, 'upstream:linux',
- 'ecd7a325095a0d19b8c3d76f578d85b979461d41')
-
- def test_fail_ls_tree_in_non_existent_repo(self):
- self.assertRaises(morphlib.remoterepocache.LsTreeError,
- self.cache.ls_tree, 'non-existent-repo',
- 'e28a23812eadf2fce6583b8819b9c5dbd36b9fb9')