summaryrefslogtreecommitdiff
path: root/morphlib/gitdir_tests.py
blob: 2494981ae2a8ba6238bf0a38f4e4b0e1200c336e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Copyright (C) 2013  Codethink Limited
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# =*= License: GPL-2 =*=


import os
import shutil
import tempfile
import unittest

import morphlib


class GitDirectoryTests(unittest.TestCase):

    def setUp(self):
        self.tempdir = tempfile.mkdtemp()
        self.dirname = os.path.join(self.tempdir, 'foo')

    def tearDown(self):
        shutil.rmtree(self.tempdir)

    def fake_git_clone(self):
        os.mkdir(self.dirname)
        os.mkdir(os.path.join(self.dirname, '.git'))

    def test_has_dirname_attribute(self):
        self.fake_git_clone()
        gitdir = morphlib.gitdir.GitDirectory(self.dirname)
        self.assertEqual(gitdir.dirname, self.dirname)

    def test_runs_command_in_right_directory(self):
        self.fake_git_clone()
        gitdir = morphlib.gitdir.GitDirectory(self.dirname)
        output = gitdir._runcmd(['pwd'])
        self.assertEqual(output.strip(), self.dirname)

    def test_sets_and_gets_configuration(self):
        os.mkdir(self.dirname)
        gitdir = morphlib.gitdir.init(self.dirname)
        gitdir.set_config('foo.bar', 'yoyo')
        self.assertEqual(gitdir.get_config('foo.bar'), 'yoyo')

    def test_sets_remote(self):
        os.mkdir(self.dirname)
        gitdir = morphlib.gitdir.init(self.dirname)
        self.assertEqual(gitdir.get_remote_fetch_url('origin'), None)

        gitdir._runcmd(['git', 'remote', 'add', 'origin', 'foobar'])
        url = 'git://git.example.com/foo'
        gitdir.set_remote_fetch_url('origin', url)
        self.assertEqual(gitdir.get_remote_fetch_url('origin'), url)