Exemple #1
0
 def setUp(self):
     super(TestLocalRepository, self).setUp()
     store = LocalRepositoryStore(self.mkdir('repo'))
     self.repo = Repository(store)
Exemple #2
0
class TestLocalRepository(TmpDirTestCase):
    '''Integration test: A localRepositoryStore backed Repository'''
    def setUp(self):
        super(TestLocalRepository, self).setUp()
        store = LocalRepositoryStore(self.mkdir('repo'))
        self.repo = Repository(store)

    def test_initial_put(self):
        self.repo.put('foo', '1.0', 'data', {})
        self.assertTMPPContents('data',
                'repo', 'foo', 'master', 'foo.tar.gz', '1.0')

    def test_store_latest(self):
        self.repo.put('foo', '1.0', 'version 1', {})
        self.assertTMPPContents('1.0\n',
                'repo', 'foo', 'master', 'foo.tar.gz', 'latest')
        self.repo.put('foo', '2.0', 'version 2', {})
        self.assertTMPPContents('2.0\n',
                'repo', 'foo', 'master', 'foo.tar.gz', 'latest')

    def test_store_illegal_versions(self):
        self.assertRaises(ValueError, self.repo.put, 'foo', 'latest',
                          'version 1', {})

    def test_meta(self):
        self.repo.put('foo', '1.0', 'data', {'bar': 'baz'})
        with self.repo.get('foo') as f:
            self.assertEqual(f.metadata, {'bar': 'baz'})

    def test_get(self):
        self.repo.put('foo', '1.0', 'data', {})
        with self.repo.get('foo', '1.0') as f:
            self.assertEqual(f.read().decode(), 'data')

    def test_get_latest(self):
        self.repo.put('foo', '1.0', 'old data', {})
        self.repo.put('foo', '2.0', 'new data', {})
        with self.repo.get('foo') as f:
            self.assertEqual(f.read().decode(), 'new data')

    def test_get_missing(self):
        self.repo.put('foo', '1.0', 'old data', {})
        self.assertRaises(KeyError, self.repo.get, 'foo', '2.0')

    def test_get_metadata(self):
        self.repo.put('foo', '1.0', 'data', {'foo': 'bar'})
        self.assertEqual(self.repo.get_metadata('foo', '1.0'), {'foo': 'bar'})

    def test_latest_version(self):
        self.repo.put('foo', '1.0', 'old data', {})
        self.assertEqual(self.repo.latest_version('foo'), '1.0')
        self.repo.put('foo', '2.0', 'new data', {})
        self.assertEqual(self.repo.latest_version('foo'), '2.0')

    def test_targets(self):
        self.repo.put('foo', '1.0', 'master data', {})
        self.repo.put('foo', '2.0', 'dev data', {}, 'dev')
        with self.repo.get('foo') as f:
            self.assertEqual(f.read().decode(), 'master data')
        with self.repo.get('foo', target='dev') as f:
            self.assertEqual(f.read().decode(), 'dev data')

    def test_list_apps(self):
        self.assertFalse(self.repo.list_apps())
        self.repo.put('foo', '1.0', 'data', {})
        self.assertEqual(self.repo.list_apps(), ['foo'])

    def test_list_targets(self):
        self.assertFalse(self.repo.list_targets('foo'))
        self.repo.put('foo', '1.0', 'data', {})
        self.assertEqual(self.repo.list_targets('foo'), ['master'])

    def test_list_artifacts(self):
        self.assertFalse(self.repo.list_artifacts('foo'))
        self.repo.put('foo', '1.0', 'data', {})
        self.assertEqual(self.repo.list_artifacts('foo'), ['foo.tar.gz'])

    def test_list_versions(self):
        self.assertFalse(self.repo.list_versions('foo'))
        self.repo.put('foo', '1.0', 'data', {})
        self.assertEqual(self.repo.list_versions('foo'), ['1.0'])

    def test_delete(self):
        self.repo.put('foo', '1.0', 'data', {})
        self.repo.delete('foo', '1.0')
        self.assertFalse(self.repo.list_versions('foo'))
        self.assertNotTMPPExists('repo', 'foo', 'master', 'foo.tar.gz',
                                 'latest')

    def test_delete_older(self):
        self.repo.put('foo', '1.0', 'old data', {})
        self.repo.put('foo', '2.0', 'new data', {})

        self.repo.delete('foo', '1.0')

        self.assertEqual(self.repo.list_versions('foo'), ['2.0'])
        with self.repo.get('foo') as f:
            self.assertEqual(f.read().decode(), 'new data')

    def test_delete_latest(self):
        self.repo.put('foo', '1.0', 'old data', {})
        self.assertTMPPContents(
            '1.0\n', 'repo', 'foo', 'master', 'foo.tar.gz', 'latest')
        self.repo.put('foo', '2.0', 'new data', {})

        self.repo.delete('foo', '2.0')

        self.assertTMPPContents(
            '1.0\n', 'repo', 'foo', 'master', 'foo.tar.gz', 'latest')
        with self.repo.get('foo') as f:
            self.assertEqual(f.read().decode(), 'old data')

    def test_delete_missing_app(self):
        self.assertRaises(ValueError, self.repo.delete, 'foo', '1.0')

    def test_delete_missing_version(self):
        self.repo.put('foo', '1.0', 'data', {})
        self.assertRaises(ValueError, self.repo.delete, 'foo', '2.0')

    def test_gc(self):
        self.repo.put('foo', '1.0', 'data', {})
        self.repo.put('foo', '2.0', 'data', {})
        self.repo.put('foo', '3.0', 'data', {})
        self.repo.put('foo', '4.0', 'data', {})
        self.repo.put('foo', '3.1', 'data', {}, 'dev')
        self.repo.put('foo', '4.1', 'data', {}, 'dev')
        self.repo.gc(2)
        self.assertEqual(self.repo.list_versions('foo'), ['3.0', '4.0'])
        self.assertEqual(self.repo.list_versions('foo', 'dev'), ['3.1', '4.1'])