def testClone(self): self._make_testapp() child_stdout, child_stderr = sh_open("{0} push -v my-app {1}couchapp-test".format(self.cmd, url)) design_doc = self._retrieve_ddoc() app_dir = os.path.join(self.tempdir, "couchapp-test") child_stdout, child_stderr = sh_open( "{0} clone {1} {2}".format(self.cmd, url + "couchapp-test/_design/my-app", app_dir) ) # should create .couchapprc self.assertTrue(os.path.isfile(os.path.join(app_dir, ".couchapprc"))) # should clone the views self.assertTrue(os.path.isdir(os.path.join(app_dir, "views"))) # should create foo/bar.txt file self.assertTrue(os.path.isfile(os.path.join(app_dir, "foo/bar.txt"))) # should create lib/helpers/math.js file self.assertTrue(os.path.isfile(os.path.join(app_dir, "lib/helpers/math.js"))) # should work when design doc is edited manually design_doc["test.txt"] = "essai" design_doc = self.db.save_doc(design_doc) deltree(app_dir) child_stdout, child_stderr = sh_open( "{0} clone {1} {2}".format(self.cmd, url + "couchapp-test/_design/my-app", app_dir) ) self.assertTrue(os.path.isfile(os.path.join(app_dir, "test.txt"))) # should work when a view is added manually design_doc["views"]["more"] = {"map": "function(doc) { emit(null, doc); }"} design_doc = self.db.save_doc(design_doc) deltree(app_dir) child_stdout, child_stderr = sh_open( "{0} clone {1} {2}".format(self.cmd, url + "couchapp-test/_design/my-app", app_dir) ) self.assertTrue(os.path.isfile(os.path.join(app_dir, "views/example/map.js"))) # should work without manifest del design_doc["couchapp"]["manifest"] design_doc = self.db.save_doc(design_doc) deltree(app_dir) child_stdout, child_stderr = sh_open( "{0} clone {1} {2}".format(self.cmd, url + "couchapp-test/_design/my-app", app_dir) ) self.assertTrue(os.path.isfile(os.path.join(app_dir, "views/example/map.js"))) # should create foo/bar without manifest self.assertTrue(os.path.isfile(os.path.join(app_dir, "foo/bar"))) # should create lib/helpers.json without manifest self.assertTrue(os.path.isfile(os.path.join(app_dir, "lib/helpers.json")))
def testPushApps(self): os.chdir(self.tempdir) docsdir = os.path.join(self.tempdir, "docs") os.makedirs(docsdir) # create 2 apps child_stdout, child_stderr = sh_open("{0} init -t default docs/app1".format(self.cmd)) child_stdout, child_stderr = sh_open("{0} init -t default docs/app2".format(self.cmd)) child_stdout, child_stderr = sh_open("{0} pushapps docs/ {1}couchapp-test".format(self.cmd, url)) alldocs = self.db.all_docs()["rows"] self.assertEqual(len(alldocs), 2) self.assertEqual("_design/app1", alldocs[0]["id"])
def testPush(self): self._make_testapp() child_stdout, child_stderr = sh_open("{0} push -v my-app {1}couchapp-test".format(self.cmd, url)) design_doc = self._retrieve_ddoc() # should create view self.assertIn("function", design_doc["views"]["example"]["map"]) # should use macros self.assertIn("stddev", design_doc["views"]["example"]["map"]) self.assertIn("ejohn.org", design_doc["shows"]["example-show"]) self.assertIn("included by foo.js", design_doc["shows"]["example-show"]) # should create index content_type = design_doc["_attachments"]["index.html"]["content_type"] self.assertEqual(content_type, "text/html") # should create manifest self.assertIn("foo/", design_doc["couchapp"]["manifest"]) # should push and macro the doc shows self.assertIn("Generated CouchApp Form Template", design_doc["shows"]["example-show"]) # should push and macro the view lists self.assertIn("Test XML Feed", design_doc["lists"]["feed"]) # should allow deeper includes self.assertNotIn('"helpers"', design_doc["shows"]["example-show"]) # deep require macros self.assertNotIn('"template"', design_doc["shows"]["example-show"]) self.assertIn("Resig", design_doc["shows"]["example-show"])
class HgVendor(BackendVendor): url = "http://github.com/couchapp/couchapp" author = "Benoit Chesneau" author_email = "*****@*****.**" description = "HG vendor handler" long_description = """couchapp vendor install|update from mercurial:: hg://somerepo (repo available via http, use http+ssh:// for ssh repos) """ scheme = ['hg', 'hg+ssh'] def fetch(self, url, path, *args, **opts): """ return git cmd path """ if url.startswith("hg+ssh://"): url = url[8:] else: url = url.replace("hg://", "http://") try: cmd = locate_program("hg", raise_error=True) except ValueError, e: raise VendorError(e) cmd += " clone %s %s" % (url, path) # exec cmd child_stdout, child_stderr = sh_open(cmd) if child_stderr: raise VendorError(str(child_stderr)) logger.debug(child_stdout.read())
def test_sh_open(): ''' Test case for ``util.sh_open`` ''' out, err = sh_open('echo mock') assert out.startswith('mock'), out assert not err, err
class GitVendor(BackendVendor): url = "http://github.com/couchapp/couchapp" author = "Benoit Chesneau" author_email = "*****@*****.**" description = "Git vendor handler" long_description = """couchapp vendor install|update from git:: git://somerepo.git (use git+ssh:// for ssh repos) """ scheme = ['git', 'git+ssh'] def fetch(self, url, path, *args, **opts): if url.startswith("git+ssh://"): url = url[9:] """ return git cmd path """ try: cmd = locate_program("git", raise_error=True) except ValueError, e: raise VendorError(e) cmd += " clone %s %s" % (url, path) # exec cmd child_stdout, child_stderr = sh_open(cmd) if child_stderr: raise VendorError(str(child_stderr)) logger.debug(child_stdout.read())
def testPushApps(self): os.chdir(self.tempdir) docsdir = os.path.join(self.tempdir, 'docs') os.makedirs(docsdir) # create 2 apps child_stdout, child_stderr = sh_open( '{0} init -t app docs/app1'.format(self.cmd)) child_stdout, child_stderr = sh_open( '{0} init -t app docs/app2'.format(self.cmd)) child_stdout, child_stderr = sh_open( '{0} pushapps docs/ {1}couchapp-test'.format(self.cmd, url)) alldocs = self.db.all_docs()['rows'] self.assertEqual(len(alldocs), 2) self.assertEqual('_design/app1', alldocs[0]['id'])
def test_init_template(self): os.chdir(self.tempdir) child_stdout, child_stderr = sh_open("{0} init -t default my-app".format(self.cmd)) appdir = os.path.join(self.tempdir, "my-app") self.assertTrue(os.path.isdir(appdir)) cfile = os.path.join(appdir, ".couchapprc") self.assertTrue(os.path.isfile(cfile)) self.assertTrue(os.path.isdir(os.path.join(appdir, "_attachments"))) self.assertTrue(os.path.isfile(os.path.join(appdir, "_attachments", "index.html"))) self.assertTrue(os.path.isfile(os.path.join(self.app_dir, "_attachments", "style", "main.css"))) self.assertTrue(os.path.isdir(os.path.join(appdir, "views"))) self.assertTrue(os.path.isdir(os.path.join(appdir, "shows"))) self.assertTrue(os.path.isdir(os.path.join(appdir, "lists")))
def test_init_template(self): os.chdir(self.tempdir) child_stdout, child_stderr = sh_open('{0} init -t app my-app'.format( self.cmd)) appdir = os.path.join(self.tempdir, 'my-app') self.assertTrue(os.path.isdir(appdir)) cfile = os.path.join(appdir, '.couchapprc') self.assertTrue(os.path.isfile(cfile)) self.assertTrue(os.path.isdir(os.path.join(appdir, '_attachments'))) self.assertTrue( os.path.isfile(os.path.join(appdir, '_attachments', 'index.html'))) self.assertTrue( os.path.isfile( os.path.join(self.app_dir, '_attachments', 'style', 'main.css'))) self.assertTrue(os.path.isdir(os.path.join(appdir, 'views'))) self.assertTrue(os.path.isdir(os.path.join(appdir, 'shows'))) self.assertTrue(os.path.isdir(os.path.join(appdir, 'lists')))
def testPushNoAtomic(self): self._make_testapp() child_stdout, child_stderr = sh_open( '{0} push --no-atomic my-app {1}couchapp-test'.format( self.cmd, url)) design_doc = self._retrieve_ddoc() # there are 3 revisions (1 doc creation + 2 attachments) self.assertTrue(design_doc['_rev'].startswith('3-')) # should create view self.assertIn('function', design_doc['views']['example']['map']) # should use macros self.assertIn('stddev', design_doc['views']['example']['map']) self.assertIn('ejohn.org', design_doc['shows']['example-show']) # should create index content_type = design_doc['_attachments']['index.html']['content_type'] self.assertEqual(content_type, 'text/html') # should create manifest self.assertIn('foo/', design_doc['couchapp']['manifest']) # should push and macro the doc shows self.assertIn('Generated CouchApp Form Template', design_doc['shows']['example-show']) # should push and macro the view lists self.assertIn('Test XML Feed', design_doc['lists']['feed']) # should allow deeper includes self.assertNotIn('"helpers"', design_doc['shows']['example-show']) # deep require macros self.assertNotIn('"template"', design_doc['shows']['example-show']) self.assertIn('Resig', design_doc['shows']['example-show'])
def testClone(self): self._make_testapp() child_stdout, child_stderr = sh_open( '{0} push -v my-app {1}couchapp-test'.format(self.cmd, url)) design_doc = self._retrieve_ddoc() app_dir = os.path.join(self.tempdir, "couchapp-test") child_stdout, child_stderr = sh_open('{0} clone {1} {2}'.format( self.cmd, url + 'couchapp-test/_design/my-app', app_dir)) # should create .couchapprc self.assertTrue(os.path.isfile(os.path.join(app_dir, ".couchapprc"))) # should clone the views self.assertTrue(os.path.isdir(os.path.join(app_dir, "views"))) # should create foo/bar.txt file self.assertTrue(os.path.isfile(os.path.join(app_dir, 'foo/bar.txt'))) # should create lib/helpers/math.js file self.assertTrue( os.path.isfile(os.path.join(app_dir, 'lib/helpers/math.js'))) # should work when design doc is edited manually design_doc['test.txt'] = "essai" design_doc = self.db.save_doc(design_doc) deltree(app_dir) child_stdout, child_stderr = sh_open('{0} clone {1} {2}'.format( self.cmd, url + 'couchapp-test/_design/my-app', app_dir)) self.assertTrue(os.path.isfile(os.path.join(app_dir, 'test.txt'))) # should work when a view is added manually design_doc["views"]["more"] = { "map": "function(doc) { emit(null, doc); }" } design_doc = self.db.save_doc(design_doc) deltree(app_dir) child_stdout, child_stderr = sh_open('{0} clone {1} {2}'.format( self.cmd, url + 'couchapp-test/_design/my-app', app_dir)) self.assertTrue( os.path.isfile(os.path.join(app_dir, 'views/example/map.js'))) # should work without manifest del design_doc['couchapp']['manifest'] design_doc = self.db.save_doc(design_doc) deltree(app_dir) child_stdout, child_stderr = sh_open('{0} clone {1} {2}'.format( self.cmd, url + 'couchapp-test/_design/my-app', app_dir)) self.assertTrue( os.path.isfile(os.path.join(app_dir, 'views/example/map.js'))) # should create foo/bar without manifest self.assertTrue(os.path.isfile(os.path.join(app_dir, 'foo/bar'))) # should create lib/helpers.json without manifest self.assertTrue( os.path.isfile(os.path.join(app_dir, 'lib/helpers.json')))