# Path: nappingcat/contrib/git/utils.py
# DEFAULT_USER_NAME = '<nappingcat-user>'
# def get_full_repo_dir(settings, user, repo):
# def get_clone_base_url(settings):


from unittest import TestCase
from nappingcat.contrib.git import utils
import socket
import random
import mox
import os
    def test_use_hostname(self):
        settings = {
            'user':'user-%d' % random.randint(1,100),
        }

        results = utils.get_clone_base_url(settings)
        self.assertEqual('%s@%s.local' % (settings['user'], socket.gethostname()), results)

    def test_uses_getlogin(self):
        settings = {
            'host':'host-%d' % random.randint(1,100),
        }
        _mox = mox.Mox()
        _mox.StubOutWithMock(os, 'getlogin')
        random_user = 'rand-%d' % random.randint(1,100)
        os.getlogin().AndReturn(random_user)
        _mox.ReplayAll()
        results = utils.get_clone_base_url(settings)
        self.assertEqual('%s@%s' % (random_user, settings['host']), results)
        _mox.UnsetStubs()

    def test_getlogin_fails(self):
        settings = {
            'host':'host-%d' % random.randint(1,100),
        }
        _mox = mox.Mox()
        _mox.StubOutWithMock(os, 'getlogin')
        random_user = 'rand-%d' % random.randint(1,100)
        os.getlogin().AndRaise(OSError)
        _mox.ReplayAll()

# Path: nappingcat/contrib/git/utils.py
# DEFAULT_USER_NAME = '<nappingcat-user>'
# def get_full_repo_dir(settings, user, repo):
# def get_clone_base_url(settings):


# Path: tests/gittests/utils.py
from unittest import TestCase
from nappingcat.contrib.git import utils
import socket
import random
import mox
import os

    def test_use_hostname(self):
        settings = {
            'user':'user-%d' % random.randint(1,100),
        }

        results = utils.get_clone_base_url(settings)
        self.assertEqual('%s@%s.local' % (settings['user'], socket.gethostname()), results)

    def test_uses_getlogin(self):
        settings = {
            'host':'host-%d' % random.randint(1,100),
        }
        _mox = mox.Mox()
        _mox.StubOutWithMock(os, 'getlogin')
        random_user = 'rand-%d' % random.randint(1,100)
        os.getlogin().AndReturn(random_user)
        _mox.ReplayAll()
        results = utils.get_clone_base_url(settings)
        self.assertEqual('%s@%s' % (random_user, settings['host']), results)
        _mox.UnsetStubs()

    def test_getlogin_fails(self):
        settings = {
            'host':'host-%d' % random.randint(1,100),
        }
        _mox = mox.Mox()
        _mox.StubOutWithMock(os, 'getlogin')
        random_user = 'rand-%d' % random.randint(1,100)
        os.getlogin().AndRaise(OSError)
        _mox.ReplayAll()

        results = utils.get_clone_base_url(settings)