Beispiel #1
0
    def setUp(self):

        # Change home path for a temporary one.
        self._directory = tempfile.mkdtemp()
        environ['HOME'] = self._directory
        from gitomatic import Gitomatic
        self.gitomatic = Gitomatic()
Beispiel #2
0
    def setUp(self):

        # Change home path for a temporary one.
        self._directory = tempfile.mkdtemp()

        # Mock os.path.expanduser function.
        self.mock_expanduser = patch("os.path.expanduser")
        mock = self.mock_expanduser.start()
        mock.side_effect = lambda x: x.replace("~", self._directory)

        from gitomatic import Gitomatic

        self.gitomatic = Gitomatic()
Beispiel #3
0
class GitomaticTestCase(unittest.TestCase):
    def setUp(self):

        # Change home path for a temporary one.
        self._directory = tempfile.mkdtemp()

        # Mock os.path.expanduser function.
        self.mock_expanduser = patch("os.path.expanduser")
        mock = self.mock_expanduser.start()
        mock.side_effect = lambda x: x.replace("~", self._directory)

        from gitomatic import Gitomatic

        self.gitomatic = Gitomatic()

    def tearDown(self):
        # Delete temporary directory
        self.mock_expanduser.stop()
        shutil.rmtree(self._directory)

    def test_initialize_gitomatic(self):

        self.gitomatic.initialize()

        self.assertTrue(path.exists(path.join(self._directory, ".ssh")))
        self.assertTrue(path.exists(path.join(self._directory, ".gitomatic")))
        self.assertTrue(path.exists(path.join(self._directory, ".gitomatic/keys")))
        self.assertTrue(path.exists(path.join(self._directory, ".gitomatic/repositories")))

    def test_add_repo(self):

        self.gitomatic.initialize()
        self.gitomatic.repository.create("test.git")

        self.assertTrue(path.exists(path.join(self._directory, ".gitomatic/repositories/test.git")))

    def test_delete_repo(self):

        # Add repo
        self.gitomatic.initialize()
        self.gitomatic.repository.create("test.git")
        self.assertTrue(path.exists(path.join(self._directory, ".gitomatic/repositories/test.git")))

        # Delete repo
        self.gitomatic.repository.delete("test.git")
        self.assertTrue(not path.exists(path.join(self._directory, ".gitomatic/repositories/test.git")))

    def test_add_key(self):

        # Initialize repo.
        self.gitomatic.initialize()

        key = "ssh-rsa asasdav asda"
        hash_1 = sha1(key).hexdigest()
        hash_2 = self.gitomatic.keys.add("*****@*****.**", key)
        self.assertEqual(hash_1, hash_2)
        self.assertTrue(path.exists(path.join(self._directory, ".gitomatic/keys/[email protected]:%s" % (hash_1,))))

    def test_delete_key(self):

        # Initialize repo.
        self.gitomatic.initialize()

        key = "ssh-rsa asasdav asda"
        hash_ = self.gitomatic.keys.add("*****@*****.**", key)
        self.assertTrue(path.exists(path.join(self._directory, ".gitomatic/keys/[email protected]:%s" % (hash_,))))

        self.gitomatic.keys.remove("*****@*****.**", hash_)
        self.assertTrue(not path.exists(path.join(self._directory, ".gitomatic/keys/[email protected]:%s" % (hash_,))))

    def test_add_and_read_perm(self):

        # Initialize repo.
        self.gitomatic.initialize()
        self.gitomatic.repository.create("test.git")
        self.gitomatic.permissions.add("*****@*****.**", "test", "R")

        self.assertTrue("R" in self.gitomatic.permissions.get("*****@*****.**", "test"))

        self.assertTrue(not "W" in self.gitomatic.permissions.get("*****@*****.**", "test"))

        self.gitomatic.permissions.add("*****@*****.**", "test", "W")

        self.assertTrue("R" in self.gitomatic.permissions.get("*****@*****.**", "test"))

        self.assertTrue("W" in self.gitomatic.permissions.get("*****@*****.**", "test"))

    def test_delete_perm(self):

        # Initialize repo.
        self.gitomatic.initialize()
        self.gitomatic.repository.create("test.git")
        self.gitomatic.permissions.add("*****@*****.**", "test", "RW")

        self.assertTrue("R" in self.gitomatic.permissions.get("*****@*****.**", "test"))

        self.assertTrue("W" in self.gitomatic.permissions.get("*****@*****.**", "test"))

        self.gitomatic.permissions.remove("*****@*****.**", "test", "R")

        self.assertTrue(not "R" in self.gitomatic.permissions.get("*****@*****.**", "test"))

        self.assertTrue(not "W" in self.gitomatic.permissions.get("*****@*****.**", "test"))
Beispiel #4
0
class GitomaticTestCase(unittest.TestCase):

    def setUp(self):

        # Change home path for a temporary one.
        self._directory = tempfile.mkdtemp()
        environ['HOME'] = self._directory
        from gitomatic import Gitomatic
        self.gitomatic = Gitomatic()

    def tearDown(self):
        # Delete temporary directory
        shutil.rmtree(self._directory)

    def test_initialize_gitomatic(self):

        self.gitomatic.initialize()

        self.assertTrue(path.exists(path.join(
            self._directory, '.ssh')))
        self.assertTrue(path.exists(path.join(
            self._directory, '.gitomatic')))
        self.assertTrue(path.exists(path.join(
            self._directory, '.gitomatic/keys')))
        self.assertTrue(path.exists(path.join(
            self._directory, '.gitomatic/repositories')))

    def test_add_repo(self):

        self.gitomatic.initialize()
        self.gitomatic.repository.create('test.git')

        self.assertTrue(path.exists(path.join(
            self._directory, '.gitomatic/repositories/test.git')))

    def test_delete_repo(self):

        # Add repo
        self.gitomatic.initialize()
        self.gitomatic.repository.create('test.git')
        self.assertTrue(path.exists(path.join(
            self._directory, '.gitomatic/repositories/test.git')))

        # Delete repo
        self.gitomatic.repository.delete('test.git')
        self.assertTrue(not path.exists(path.join(
            self._directory, '.gitomatic/repositories/test.git')))

    def test_add_key(self):

        # Initialize repo.
        self.gitomatic.initialize()

        key = 'ssh-rsa asasdav asda'
        hash_1 = sha1(key).hexdigest()
        hash_2 = self.gitomatic.keys.add('*****@*****.**', key)
        self.assertEqual(hash_1, hash_2)
        self.assertTrue(path.exists(path.join(
            self._directory, '.gitomatic/keys/[email protected]:%s' % (hash_1, ))))

    def test_delete_key(self):

        # Initialize repo.
        self.gitomatic.initialize()

        key = 'ssh-rsa asasdav asda'
        hash_ = self.gitomatic.keys.add('*****@*****.**', key)
        self.assertTrue(path.exists(path.join(
            self._directory, '.gitomatic/keys/[email protected]:%s' % (hash_, ))))

        self.gitomatic.keys.delete('*****@*****.**', hash_)
        self.assertTrue(not path.exists(path.join(
            self._directory, '.gitomatic/keys/[email protected]:%s' % (hash_, ))))

    def test_add_and_read_perm(self):

        # Initialize repo.
        self.gitomatic.initialize()
        self.gitomatic.repositoriy.create('test.git')
        self.gitomatic.permission.add('*****@*****.**', 'test', 'R')

        self.assertTrue(
            'R' in self.gitomatic.permission.get('*****@*****.**', 'test'))

        self.assertTrue(not
            'W' in self.gitomatic.permission.get('*****@*****.**', 'test'))

        self.gitomatic.permission.add('*****@*****.**', 'test', 'W')

        self.assertTrue(
            'R' in self.gitomatic.permission.get('*****@*****.**', 'test'))

        self.assertTrue(
            'W' in self.gitomatic.permission.get('*****@*****.**', 'test'))

    def test_delete_perm(self):

        # Initialize repo.
        self.gitomatic.initialize()
        self.gitomatic.repositoriy.add('test.git')
        self.gitomatic.permission.add('*****@*****.**', 'test', 'RW')

        self.assertTrue(
            'R' in self.gitomatic.permission.get('*****@*****.**', 'test'))

        self.assertTrue(
            'W' in self.gitomatic.permission.get('*****@*****.**', 'test'))

        self.gitomatic.permission.remove('*****@*****.**', 'test', 'R')

        self.assertTrue(not
            'R' in self.gitomatic.permission.get('*****@*****.**', 'test'))

        self.assertTrue(not
            'W' in self.gitomatic.permission.get('*****@*****.**', 'test'))