Skip to content

Commit

Permalink
Test case where there is no userinfo in global gitconfig
Browse files Browse the repository at this point in the history
Tests are failing for now.
  • Loading branch information
agateau committed Jan 10, 2016
1 parent 6c3baac commit 0a56c12
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions yokadi/tests/gitvcsimpltestcase.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
import os
import shutil
import subprocess
import tempfile
import unittest

from os.path import join
from tempfile import TemporaryDirectory

from yokadi.sync.gitvcsimpl import GitVcsImpl
from yokadi.tests.testutils import EnvironSaver


def createGitRepository(path):
os.mkdir(path)
subprocess.check_call(('git', 'init', '--quiet'), cwd=path)


def createGitConfig():
subprocess.check_call(('git', 'config', '--global', 'user.name', 'Test User'))
subprocess.check_call(('git', 'config', '--global', 'user.email', 'test@example.com'))


def gitAdd(path):
dirname = os.path.dirname(path)
basename = os.path.basename(path)
Expand Down Expand Up @@ -57,6 +65,19 @@ def createGitRepositoryWithConflict(tmpDir, path):


class GitVcsImplTestCase(unittest.TestCase):
def setUp(self):
self._envSaver = EnvironSaver()
self.testHomeDir = tempfile.mkdtemp(prefix="yokadi-basepaths-testcase")
os.environ["HOME"] = self.testHomeDir
createGitConfig()

def tearDown(self):
shutil.rmtree(self.testHomeDir)
self._envSaver.restore()

def _deleteGitConfig(self):
os.remove(join(self.testHomeDir, ".gitconfig"))

def testIsValidVcsDir(self):
with TemporaryDirectory() as tmpDir:
repoDir = join(tmpDir, "repo")
Expand Down Expand Up @@ -107,6 +128,21 @@ def testCommitAll(self):
impl.commitAll()
self.assertTrue(impl.isWorkTreeClean())

def testInitNoGitUserInfo(self):
# If there is no user info, init() should set some default info so that
# commitAll() does not fail
self._deleteGitConfig()
with TemporaryDirectory() as tmpDir:
repoDir = join(tmpDir, "repo")
os.mkdir(repoDir)

impl = GitVcsImpl()
impl.setDir(repoDir)
impl.init()

touch(repoDir, "foo")
impl.commitAll()

def testClone(self):
with TemporaryDirectory() as tmpDir:
remoteRepoDir = join(tmpDir, "remote")
Expand All @@ -125,6 +161,17 @@ def testClone(self):
fooPath = join(repoDir, "foo")
self.assertTrue(os.path.exists(fooPath))

def testCloneNoGitUserInfo(self):
self._deleteGitConfig()
with TemporaryDirectory() as tmpDir:
remoteRepoDir = join(tmpDir, "remote")
createGitRepository(remoteRepoDir)

touch(remoteRepoDir, "foo")
impl = GitVcsImpl()
impl.setDir(remoteRepoDir)
impl.commitAll()

def testPull(self):
with TemporaryDirectory() as tmpDir:
remoteRepoDir = join(tmpDir, "remote")
Expand Down

0 comments on commit 0a56c12

Please sign in to comment.