def test_delete_files(self):
     args = Namespace(verbose=False, dry_run=False)
     file1 = SyncFile('index.json', 33, 'md5-asdf', 'application/json', '')
     file2 = SyncFile('other.json', 33, 'md5-asdf', 'application/json', '')
     blob_service = FakeBlobService({
         'tools/index.json':
         FakeBlob.from_sync_file(file1),
         'tools/other.json':
         FakeBlob.from_sync_file(file2)
     })
     delete_files(blob_service, 'released', ['index.json'], args)
     self.assertIsNone(
         blob_service.containers[JUJU_DIST].get('tools/index.json'))
     self.assertEqual(
         file2.path,
         blob_service.containers[JUJU_DIST]['tools/other.json'].name)
 def test_two_files(self):
     with temp_dir() as local_dir:
         foo_path = os.path.join(local_dir, 'foo')
         baz_path = os.path.join(local_dir, 'baz')
         expected = [
             SyncFile('bools/baz',
                      size=3,
                      local_path=baz_path,
                      md5content=md5sum['qux'],
                      mimetype=None),
             SyncFile('bools/foo',
                      size=3,
                      local_path=foo_path,
                      md5content=md5sum['bar'],
                      mimetype=None),
         ]
         write_file(foo_path, 'bar')
         write_file(baz_path, 'qux')
         result = get_local_sync_files('bools', local_dir)
         self.assertEqual(expected, result)
 def test_one_remote_file(self):
     args = Namespace(verbose=False, dry_run=False)
     expected = SyncFile('index.json', 33, 'md5-asdf', 'application/json',
                         '')
     service = FakeBlobService(
         {'tools/index.json': FakeBlob.from_sync_file(expected)})
     with temp_dir() as local_dir:
         sync_files(service, 'tools', local_dir, args)
     self.assertEqual(['tools/index.json'],
                      service.containers[JUJU_DIST].keys())
     blob = service.containers[JUJU_DIST]['tools/index.json']
     self.assertEqual({}, blob._blocks)
 def test_includes_mirror(self):
     with temp_dir() as local_dir:
         foo_path = os.path.join(local_dir, 'foo-mirror')
         expected = [
             SyncFile('bools/foo-mirror',
                      size=3,
                      local_path=foo_path,
                      md5content=md5sum['bar'],
                      mimetype=None),
         ]
         write_file(foo_path, 'bar')
         result = get_local_sync_files('bools', local_dir)
         self.assertEqual(expected, result)
 def test_different_local_remote_dry_run(self):
     args = Namespace(verbose=False, dry_run=True)
     expected = SyncFile('tools/index2.json', 33, 'md5-asdf',
                         'application/json', '')
     service = FakeBlobService(
         {'tools/index2.json': FakeBlob.from_sync_file(expected)})
     with temp_dir() as local_dir:
         write_file(os.path.join(local_dir, 'index2.json'), '{}\n')
         sync_files(service, 'tools', local_dir, args)
     self.assertEqual(['tools/index2.json'],
                      service.containers[JUJU_DIST].keys())
     blob = service.containers[JUJU_DIST]['tools/index2.json']
     self.assertEqual({}, blob._blocks)
 def test_one_local_file(self):
     args = Namespace(verbose=False, dry_run=False)
     expected = SyncFile('index.json', 33, 'md5-asdf', 'application/json',
                         '')
     service = FakeBlobService(
         {'tools/index.json': FakeBlob.from_sync_file(expected)})
     with temp_dir() as local_dir:
         write_file(os.path.join(local_dir, 'index2.json'), '{}\n')
         publish_files(service, RELEASED, local_dir, args)
     self.assertEqual(['tools/index.json', 'tools/index2.json'],
                      service.containers[JUJU_DIST].keys())
     blob = service.containers[JUJU_DIST]['tools/index2.json']
     self.assertEqual({BlobBlock('MA==').id: '{}\n'}, blob._blocks)
 def test_same_local_remote(self):
     args = Namespace(verbose=False, dry_run=False)
     with temp_dir() as local_dir:
         file_path = os.path.join(local_dir, 'index2.json')
         write_file(file_path, '{}\n')
         md5_sum = get_md5content(file_path)
         expected = SyncFile('tools/index2.json', 33, md5_sum,
                             'application/json', '')
         service = FakeBlobService(
             {'tools/index2.json': FakeBlob.from_sync_file(expected)})
         sync_files(service, 'tools', local_dir, args)
     self.assertEqual(['tools/index2.json'],
                      service.containers[JUJU_DIST].keys())
     blob = service.containers[JUJU_DIST]['tools/index2.json']
     self.assertEqual({}, blob._blocks)
 def test_prefix_right(self):
     expected = SyncFile('index.json', 33, 'md5-asdf', 'application/json',
                         '')
     service = FakeBlobService(
         {'tools/index.json': FakeBlob.from_sync_file(expected)})
     self.assertEqual([expected], list_sync_files('tools', service))
 def test_prefix_wrong(self):
     expected = SyncFile('index.json', 33, 'md5-asdf', 'application/json',
                         '')
     service = FakeBlobService(
         {'fools/index.json': FakeBlob.from_sync_file(expected)})
     self.assertEqual([], get_published_files(RELEASED, service))