def test_get_server_dir(self, server): ext = self.mox.CreateMock(External) self.mox.StubOutWithMock(omego.upgrade, 'Artifacts') self.mox.StubOutWithMock(fileutils, 'get_as_local_path') self.mox.StubOutWithMock(fileutils, 'unzip') args = self.Args({ 'server': None, 'skipunzip': False, 'overwrite': 'error', 'unzipdir': None, 'httpuser': '******', 'httppassword': '******' }) if server == 'local': args.server = 'local-server-dir' fileutils.get_as_local_path( args.server, args.overwrite, progress=0, httpuser=args.httpuser, httppassword=args.httppassword).AndReturn( ('directory', 'local-server-dir')) expected = 'local-server-dir' elif server == 'remote': args.server = 'http://example.org/remote/server.zip' fileutils.get_as_local_path( args.server, args.overwrite, progress=0, httpuser=args.httpuser, httppassword=args.httppassword).AndReturn( ('file', 'server.zip')) fileutils.unzip('server.zip', match_dir=True, destdir=args.unzipdir).AndReturn('server') expected = 'server' else: artifact_args = copy.copy(args) artifact_args.sym = '' omego.upgrade.Artifacts(artifact_args).AndReturn( self.MockArtifacts()) expected = 'server-dir' self.mox.ReplayAll() upgrade = self.PartialMockUnixInstall(args, ext) s = upgrade.get_server_dir() assert s == expected self.mox.VerifyAll()
def test_download(self): url = 'http://example.org/test/component-0.0.0.zip' a = self.MockArtifacts('testcomponent', url) self.mox.StubOutWithMock(fileutils, 'get_as_local_path') self.mox.StubOutWithMock(fileutils, 'unzip') fileutils.get_as_local_path( url, 'error', progress=0, httpuser=None, httppassword=None).AndReturn( ('file', 'component-0.0.0.zip')) fileutils.unzip('component-0.0.0.zip', match_dir=True, destdir='unzip/dir').AndReturn('component-0.0.0') self.mox.ReplayAll() assert a.download('testcomponent') == 'component-0.0.0' self.mox.VerifyAll()
def test_get_as_local_path(self, exists, remote, overwrite, httpauth): if remote: p = 'http://example.org/test.zip' expectedp = 'test.zip' else: p = '/example/test.zip' expectedp = p self.mox.StubOutWithMock(os.path, 'exists') self.mox.StubOutWithMock(os.path, 'isdir') self.mox.StubOutWithMock(fileutils, 'rename_backup') self.mox.StubOutWithMock(fileutils, 'download') if httpauth: kwargs = {'httpuser': '******', 'httppassword': '******'} else: kwargs = {'httpuser': None, 'httppassword': None} if remote: os.path.exists(expectedp).AndReturn(exists) if remote and exists and overwrite == 'backup': fileutils.rename_backup(expectedp) if (remote and exists and overwrite == 'backup') or ( remote and not exists): fileutils.download(p, expectedp, 0, **kwargs) if not remote or (remote and not exists) or ( remote and exists and overwrite != 'error'): os.path.isdir(expectedp).AndReturn(False) os.path.exists(expectedp).AndReturn(True) self.mox.ReplayAll() if remote and exists and overwrite == 'error': with pytest.raises(fileutils.FileException): fileutils.get_as_local_path(p, overwrite, **kwargs) else: ptype, lpath = fileutils.get_as_local_path(p, overwrite, **kwargs) assert ptype == 'file' assert lpath == expectedp self.mox.VerifyAll()
def test_download(self): url = 'http://example.org/test/component-0.0.0.zip' a = self.MockArtifacts('testcomponent', url) self.mox.StubOutWithMock(fileutils, 'get_as_local_path') self.mox.StubOutWithMock(fileutils, 'unzip') fileutils.get_as_local_path(url, 'error', progress=0, httpuser=None, httppassword=None).AndReturn( ('file', 'component-0.0.0.zip')) fileutils.unzip('component-0.0.0.zip', match_dir=True, destdir='unzip/dir').AndReturn('component-0.0.0') self.mox.ReplayAll() assert a.download('testcomponent') == 'component-0.0.0' self.mox.VerifyAll()
def test_get_server_dir(self, server): ext = self.mox.CreateMock(External) self.mox.StubOutWithMock(omego.upgrade, 'Artifacts') self.mox.StubOutWithMock(fileutils, 'get_as_local_path') self.mox.StubOutWithMock(fileutils, 'unzip') args = self.Args({'server': None, 'skipunzip': False, 'overwrite': 'error', 'unzipdir': None, 'httpuser': '******', 'httppassword': '******'}) if server == 'local': args.server = 'local-server-dir' fileutils.get_as_local_path( args.server, args.overwrite, progress=0, httpuser=args.httpuser, httppassword=args.httppassword ).AndReturn(('directory', 'local-server-dir')) expected = 'local-server-dir' elif server == 'remote': args.server = 'http://example.org/remote/server.zip' fileutils.get_as_local_path( args.server, args.overwrite, progress=0, httpuser=args.httpuser, httppassword=args.httppassword ).AndReturn(('file', 'server.zip')) fileutils.unzip( 'server.zip', match_dir=True, destdir=args.unzipdir ).AndReturn('server') expected = 'server' else: artifact_args = copy.copy(args) artifact_args.sym = '' omego.upgrade.Artifacts(artifact_args).AndReturn( self.MockArtifacts()) expected = 'server-dir' self.mox.ReplayAll() upgrade = self.PartialMockUnixInstall(args, ext) s = upgrade.get_server_dir() assert s == expected self.mox.VerifyAll()