def test_build_deb(self): basepath = os.path.join(os.path.expanduser('~/')) d = Deployment('testapp', base=basepath) d.root_path = os.path.join(basepath, '.parcel') d.prepare_app() # test build, will not actually call fpm d.build_package() dest_file = os.path.join(os.path.dirname(__file__), "data", "testapp_0.1.2_all.deb") self.assertTrue(os.path.exists(dest_file)) os.unlink(dest_file) # now do it without templates to exercise those paths d = Deployment('testapp', base=basepath) d.root_path = os.path.join(basepath, '.parcel_test') d.build_package(templates=False) dest_file = os.path.join(os.path.dirname(__file__), "data", "testapp_0.1.2_all.deb") self.assertTrue(os.path.exists(dest_file)) os.unlink(dest_file) # now set some prerm etc directly and check d = Deployment('testapp', base=basepath) d.root_path = os.path.join(basepath, '.parcel_test') lines = ['test line one', 'test line two'] d.prerm = " ".join(lines) d.postrm = " ".join(lines) d.preinst = " ".join(lines) d.postinst = " ".join(lines) d.build_package() dest_file = os.path.join(os.path.dirname(__file__), "data", "testapp_0.1.2_all.deb") self.assertTrue(os.path.exists(dest_file)) os.unlink(dest_file)
def test_init(self): basepath = os.path.join(os.path.expanduser('~/')) d = Deployment('testapp', base=basepath) d.prepare_app() # version self.assertEquals(d.version.version, Version('0.1.2').version) # app_name self.assertEquals(d.app_name, 'testapp') # check that that a build_dir has been set up build_dir = os.path.join(basepath, d.build_dir) self.assertTrue(os.path.exists(build_dir)) # no deps to install self.assertFalse(build_deps.called) # update_packages update_packages.assert_called_once() # now check with no basepath d = Deployment('testapp') self.assertTrue(basepath in d.build_path) # now check with basepath without initial slash basepath = os.path.join(os.path.dirname(__file__)) d = Deployment('testapp', base=basepath[1:]) self.assertTrue(basepath in d.build_path)
def test_init_with_deps(self): basepath = os.path.join(os.path.expanduser('~/')) d = Deployment('testapp', base=basepath, build_deps=['requests']) d.prepare_app() # if we supply build_deps then this should be called build_deps.assert_called_once()
def test_add_venv_with_requirements(self): basepath = os.path.join(os.path.expanduser('~/')) d = Deployment('testapp', base=basepath) req_file = os.path.join(os.path.dirname(__file__), "data", "requirements_test") # call _add_venv directly so we can just mock that run out d._add_venv(requirements=req_file) self.assertTrue('PIP_DOWNLOAD_CACHE' in run.call_args[0][0])
def test_prepare_app(self): basepath = os.path.join(os.path.expanduser('~/')) d = Deployment('testapp', base=basepath) d.prepare_app() # check that sync_app worked self.assertTrue(os.path.exists(d.build_path)) # check that virtualenv was built ve_path = os.path.join(d.build_path, d.virtual) self.assertTrue(os.path.exists(ve_path))
def test_build_rpm(self): basepath = os.path.join(os.path.expanduser('~/')) d = Deployment('testapp', base=basepath, arch=centos) d.root_path = os.path.join(basepath, '.parcel') d.prepare_app() # test build, will not actually call fpm d.build_package() dest_file = os.path.join(os.path.dirname(__file__), "data", "testapp_0.1.1-1.noarch.rpm") print dest_file self.assertTrue(os.path.exists(dest_file)) os.unlink(dest_file)
def test_deployment(self): basepath = os.path.join(os.path.expanduser('~/')) d = Deployment('testapp', base=basepath) d.prepare_app() # check that sync_app worked self.assertTrue(os.path.exists(d.build_path)) # check that virtualenv was built ve_path = os.path.join(d.build_path, d.virtual) self.assertTrue(os.path.exists(ve_path)) # check we can add a file test_file = os.path.join(os.path.dirname(__file__), "data", "tip.tar.gz") d.add_to_root_fs(test_file, 'tip.tar.gz') dest_file = os.path.join(d.root_path, "tip.tar.gz") self.assertTrue(os.path.exists(dest_file)) # now check with a leading slash d.add_to_root_fs(test_file, '/tip.tar.gz') dest_file = os.path.join(d.root_path, "tip.tar.gz") self.assertTrue(os.path.exists(dest_file)) # check we can add data data = "this is some test data" d.add_data_to_root_fs(data, "test_data.txt") dest_file = os.path.join(d.root_path, "test_data.txt") self.assertTrue(os.path.exists(dest_file)) with open(dest_file) as f: self.assertEquals(data, f.read()) # try the same with a leading slash data = "this is some test data" d.add_data_to_root_fs(data, "/test_data.txt") dest_file = os.path.join(d.root_path, "test_data.txt") self.assertTrue(os.path.exists(dest_file)) with open(dest_file) as f: self.assertEquals(data, f.read()) # check we can compile python files d.compile_python() dest_file = os.path.join(d.build_path, 'data', 'hello.pyc') self.assertTrue(os.path.exists(dest_file)) # check we can clear .py and just leave .pyc files d.clear_py_files() dest_file = os.path.join(d.build_path, 'data', 'hello.py') self.assertFalse(os.path.exists(dest_file))