class TestGitLabClone(TestHttpsClone): testDir = "./__testGitLabClone" def setUp(self): """ put this file in local test dir: [myconfig.py] user, pwd = "gitlab user", "git lab password", url = 'gitlab url' commit_id = "commitid for test" commit_exists = '/path/somefilename' then pass this test :return: """ self.cf = __import__("myconfig") self.gc = GitCmd(work_dir=self.testDir, user=self.cf.user, pwd=self.cf.pwd, url=self.cf.url) self.gc.clone() def testCheckout(self): self.gc.checkout(self.cf.commit_id) self.exists(self.cf.commit_exists) self.gc.checkout() def testPull(self): self.gc.pull()
def push(self, repo, filename, options): from gitbundler.poster.encode import multipart_encode from gitbundler.poster.streaminghttp import register_openers import urllib2 register_openers() repo = os.path.abspath(repo) if not os.path.exists(repo): print "error: repo folder %s doesn't existed" %repo return print "Bundle> \n File :: %s, git: %s, %s" % (filename, repo, options) git = GitCmd(filename, repo) git.get_branch() print git.pull() print git.bundle_create(filename, options) if os.path.exists(os.path.join(repo, filename)): print " Info :: %s" % git.ls_remote(filename) print " Server:: %s" % self.url file = open(os.path.join(repo, filename), "rb") params = {'fileName': file} datagen, headers = multipart_encode(params) headers['gitbundler-user'] = self.user headers['gitbundler-password'] = self.password request = urllib2.Request(self.url, datagen, headers) result = urllib2.urlopen(request) print " Upload:: %s" % result.read() file.close() os.unlink(os.path.relpath(os.path.join(repo, filename))) else: print "error: generate git bundle fails."
class TestSSHClone(TestHttpsClone): testDir = "./__testSSHClone" def setUp(self): self.gc = GitCmd(work_dir=self.testDir, url='[email protected]:philoprove/gitcmd.git') self.gc.clone() assert os.path.exists(self.testDir) self.exists('/README.rst') def testPull(self): self.gc.pull() def tearDown(self): os.popen("rm -rf " + self.testDir)
class TestHttpsClone(unittest.TestCase): testDir = "./__testHttpsClone" def setUp(self): self.gc = GitCmd(work_dir=self.testDir, url='https://github.com/philoprove/gitcmd') self.gc.clone() assert os.path.exists(self.testDir) assert os.path.exists(self.testDir + '/README.rst') def testPull(self): self.gc.pull() def tearDown(self): os.popen("rm -rf " + self.testDir) def exists(self, filename): assert os.path.exists(self.testDir + filename)