def testCreateNginxConfig(self): self.prj.create_nginx_config() nginx_conf = os.path.join( self.prj._conf_dir, '{0}_nginx.conf'.format(self.prj._project_name)) self.assertTrue(os.path.exists(nginx_conf)) f = open(nginx_conf, 'r') cfg = f.read() f.close() # search config for project_name -- not the best validation, but some self.assertTrue(cfg.find(self.prj._project_name) > -1) # search for 'http' section (standalone hosting self.assertTrue(cfg.find('http {') > -1) os.remove(nginx_conf) # create project with shared hosting self.prj = ProjectCreator(root_dir=self.root_dir, project_name=self.project_name, modules=self.modules, shared_hosting=True) self.prj.create_nginx_config() nginx_conf = os.path.join( self.prj._conf_dir, '{0}_nginx.conf'.format(self.prj._project_name)) self.assertTrue(os.path.exists(nginx_conf)) f = open(nginx_conf, 'r') cfg = f.read() f.close() # search config for project_name -- not the best validation, but some self.assertTrue(cfg.find(self.prj._project_name) > -1) # search for 'http' section (standalone hosting self.assertTrue(cfg.find('http {') == -1)
def setUp(self): self.root_dir = tempfile.mkdtemp() self.project_name = 'testproject' self.modules = [] self.prj = ProjectCreator(root_dir=self.root_dir, project_name=self.project_name, modules=self.modules)
def __init__(self, project_name=None, root_dir=os.getcwd(), modules=[], **kwargs): ProjectCreator.__init__(self, project_name, root_dir, modules, **kwargs) self.log = logging.getLogger('DjangoCreator') # add Django django_found = False for m in self._modules: if m.find('django') > -1: django_found = True if not django_found: self._modules.append('django')
def __init__(self, project_name=None, root_dir=os.getcwd(), modules=[], **kwargs): """ Handles creating Flask projects :keyword project_name: Name of project to create or edit :keyword root_dir: Base directory where projects are stored :keyword modules: List of Python modules to install into virtualenv (uses PIP) """ ProjectCreator.__init__(self, project_name, root_dir, modules, **kwargs) self.log = logging.getLogger('FlaskCreator') # add Flask flask_found = False for m in self._modules: if m.find('flask') > -1: flask_found = True if not flask_found: self._modules.append('flask')
class ProjectCreatorTestCase(unittest.TestCase): def setUp(self): self.root_dir = tempfile.mkdtemp() self.project_name = 'testproject' self.modules = [] self.prj = ProjectCreator(root_dir=self.root_dir, project_name=self.project_name, modules=self.modules) def tearDown(self): if os.path.exists(self.root_dir): shutil.rmtree(self.root_dir) def testCheckDirectories(self): self.prj.check_directories() self.assertTrue(os.path.exists(self.prj._ve_dir)) def testCreateVirtualenv(self): self.prj.create_virtualenv() self.assertTrue(os.path.exists(os.path.join(self.prj._ve_dir, self.project_name))) py = self.prj._ve_dir + os.sep + self.project_name + os.sep + \ 'bin' + os.sep + 'python' # run a simple import check to make sure we have working # python environment self.assertEqual(commands.getoutput('{0} -c \'import {1}\''.format(py, 'os')), '') def testCreateNginxConfig(self): self.prj.create_nginx_config() nginx_conf = os.path.join(self.prj._conf_dir, '{0}_nginx.conf'.format(self.prj._project_name)) self.assertTrue(os.path.exists(nginx_conf)) f = open(nginx_conf, 'r') cfg = f.read() f.close() # search config for project_name -- not the best validation, but some self.assertTrue(cfg.find(self.prj._project_name) > -1) def testCreateManageScripts(self): self.prj.create_manage_scripts() self.assertTrue(os.path.exists('{0}_start.sh'.format(os.path.join(self.prj._script_dir, self.prj._project_name)))) self.assertTrue(os.path.exists('{0}_stop.sh'.format(os.path.join(self.prj._script_dir, self.prj._project_name))))
def testCreateNginxConfig(self): self.prj.create_nginx_config() nginx_conf = os.path.join(self.prj._conf_dir, '{0}_nginx.conf'.format(self.prj._project_name)) self.assertTrue(os.path.exists(nginx_conf)) f = open(nginx_conf, 'r') cfg = f.read() f.close() # search config for project_name -- not the best validation, but some self.assertTrue(cfg.find(self.prj._project_name) > -1) # search for 'http' section (standalone hosting self.assertTrue(cfg.find('http {') > -1) os.remove(nginx_conf) # create project with shared hosting self.prj = ProjectCreator(root_dir=self.root_dir, project_name=self.project_name, modules=self.modules, shared_hosting=True) self.prj.create_nginx_config() nginx_conf = os.path.join(self.prj._conf_dir, '{0}_nginx.conf'.format(self.prj._project_name)) self.assertTrue(os.path.exists(nginx_conf)) f = open(nginx_conf, 'r') cfg = f.read() f.close() # search config for project_name -- not the best validation, but some self.assertTrue(cfg.find(self.prj._project_name) > -1) # search for 'http' section (standalone hosting self.assertTrue(cfg.find('http {') == -1)
class ProjectCreatorTestCase(unittest.TestCase): def setUp(self): self.root_dir = tempfile.mkdtemp() self.project_name = 'testproject' self.modules = [] self.prj = ProjectCreator(root_dir=self.root_dir, project_name=self.project_name, modules=self.modules) def tearDown(self): if os.path.exists(self.root_dir): shutil.rmtree(self.root_dir) def testCheckDirectories(self): self.prj.check_directories() self.assertTrue(os.path.exists(self.prj._ve_dir)) def testCreateVirtualenv(self): self.prj.create_virtualenv() self.assertTrue(os.path.exists(os.path.join(self.prj._ve_dir, self.project_name))) py = self.prj._ve_dir + os.sep + self.project_name + os.sep + \ 'bin' + os.sep + 'python' # run a simple import check to make sure we have working # python environment self.assertEqual(commands.getoutput('{0} -c \'import {1}\''.format(py, 'os')), '') def testCreateNginxConfig(self): self.prj.create_nginx_config() nginx_conf = os.path.join(self.prj._conf_dir, '{0}_nginx.conf'.format(self.prj._project_name)) self.assertTrue(os.path.exists(nginx_conf)) f = open(nginx_conf, 'r') cfg = f.read() f.close() # search config for project_name -- not the best validation, but some self.assertTrue(cfg.find(self.prj._project_name) > -1) # search for 'http' section (standalone hosting self.assertTrue(cfg.find('http {') > -1) os.remove(nginx_conf) # create project with shared hosting self.prj = ProjectCreator(root_dir=self.root_dir, project_name=self.project_name, modules=self.modules, shared_hosting=True) self.prj.create_nginx_config() nginx_conf = os.path.join(self.prj._conf_dir, '{0}_nginx.conf'.format(self.prj._project_name)) self.assertTrue(os.path.exists(nginx_conf)) f = open(nginx_conf, 'r') cfg = f.read() f.close() # search config for project_name -- not the best validation, but some self.assertTrue(cfg.find(self.prj._project_name) > -1) # search for 'http' section (standalone hosting self.assertTrue(cfg.find('http {') == -1) def testAddStaticNginxDir(self): self.prj.create_nginx_config() nginx_config = self.prj.get_nginx_config() self.assertIsNotNone(nginx_config) # generate a random static dir to add to config vdir = ''.join(Random().sample(string.letters, 5)) common.add_static_dir(root_dir=self.prj.get_root_dir(), project_name=self.prj.get_project_name(),\ static_dir_path='/tmp', alias=vdir) nginx_config = self.prj.get_nginx_config() self.assertTrue(nginx_config.find(vdir) > -1) def testCreateManageScripts(self): self.prj.create_manage_scripts() self.assertTrue(os.path.exists('{0}_start.sh'.format(os.path.join(self.prj._script_dir, self.prj._project_name)))) self.assertTrue(os.path.exists('{0}_stop.sh'.format(os.path.join(self.prj._script_dir, self.prj._project_name))))
class ProjectCreatorTestCase(unittest.TestCase): def setUp(self): self.root_dir = tempfile.mkdtemp() self.project_name = 'testproject' self.modules = [] self.prj = ProjectCreator(root_dir=self.root_dir, project_name=self.project_name, modules=self.modules) def tearDown(self): if os.path.exists(self.root_dir): shutil.rmtree(self.root_dir) def testCheckDirectories(self): self.prj.check_directories() self.assertTrue(os.path.exists(self.prj._ve_dir)) def testCreateVirtualenv(self): self.prj.create_virtualenv() self.assertTrue( os.path.exists(os.path.join(self.prj._ve_dir, self.project_name))) py = self.prj._ve_dir + os.sep + self.project_name + os.sep + \ 'bin' + os.sep + 'python' # run a simple import check to make sure we have working # python environment self.assertEqual( commands.getoutput('{0} -c \'import {1}\''.format(py, 'os')), '') def testCreateNginxConfig(self): self.prj.create_nginx_config() nginx_conf = os.path.join( self.prj._conf_dir, '{0}_nginx.conf'.format(self.prj._project_name)) self.assertTrue(os.path.exists(nginx_conf)) f = open(nginx_conf, 'r') cfg = f.read() f.close() # search config for project_name -- not the best validation, but some self.assertTrue(cfg.find(self.prj._project_name) > -1) # search for 'http' section (standalone hosting self.assertTrue(cfg.find('http {') > -1) os.remove(nginx_conf) # create project with shared hosting self.prj = ProjectCreator(root_dir=self.root_dir, project_name=self.project_name, modules=self.modules, shared_hosting=True) self.prj.create_nginx_config() nginx_conf = os.path.join( self.prj._conf_dir, '{0}_nginx.conf'.format(self.prj._project_name)) self.assertTrue(os.path.exists(nginx_conf)) f = open(nginx_conf, 'r') cfg = f.read() f.close() # search config for project_name -- not the best validation, but some self.assertTrue(cfg.find(self.prj._project_name) > -1) # search for 'http' section (standalone hosting self.assertTrue(cfg.find('http {') == -1) def testAddStaticNginxDir(self): self.prj.create_nginx_config() nginx_config = self.prj.get_nginx_config() self.assertIsNotNone(nginx_config) # generate a random static dir to add to config vdir = ''.join(Random().sample(string.letters, 5)) common.add_static_dir(root_dir=self.prj.get_root_dir(), project_name=self.prj.get_project_name(),\ static_dir_path='/tmp', alias=vdir) nginx_config = self.prj.get_nginx_config() self.assertTrue(nginx_config.find(vdir) > -1) def testCreateManageScripts(self): self.prj.create_manage_scripts() self.assertTrue( os.path.exists('{0}_start.sh'.format( os.path.join(self.prj._script_dir, self.prj._project_name)))) self.assertTrue( os.path.exists('{0}_stop.sh'.format( os.path.join(self.prj._script_dir, self.prj._project_name))))