Exemple #1
0
def test_get_all_users():
    mocked_key_dir = MagicMock()
    mocked_file = MagicMock()
    mocked_dir = MagicMock()
    mocked_re = MagicMock()

    mocked_user = MagicMock()
    mocked_user.get_by_name.return_value = 'test_user'

    mocked_path.return_value = mocked_key_dir
    mocked_dir.isdir.return_value = True
    mocked_file.isdir.return_value = False
    mocked_file.__str__ = lambda x: 'ok_file'

    mocked_re.compile().findall.return_value = ['file1.pub']

    mocked_key_dir.walk.return_value = [mocked_file, mocked_dir]

    UserManager.__bases__ = (MockManager,)
    with patch.multiple('pyolite.managers.user', User=mocked_user,
                        Path=mocked_path, re=mocked_re):
        users = UserManager('~/path/to/admin/gitolite/repo')

        assert users.all() == ['test_user']
        mocked_path.has_calls([call(mocked_path, 'keydir')])
        assert mocked_key_dir.walk.call_count == 1
        assert mocked_dir.isdir.call_count == 1
        assert mocked_file.isdir.call_count == 1

        mocked_re.compile.has_calls([call(r'(\w.pub)')])
        mocked_re.compile('\w.pub').findall.assert_called_once_with(r'ok_file')

        mocked_user.get_by_name.assert_called_once_with('file1', mocked_path, mocked_git)
Exemple #2
0
def test_it_should_commit_if_a_new_repository_was_succesfully_created():
    mocked_repository = MagicMock()

    mocked_file = MagicMock()
    mocked_file.__str__ = lambda x: 'dont_exists'

    mocked_file.exists.return_value = False
    mocked_path.return_value = mocked_file

    mocked_repository.return_value = 'new repo'

    RepositoryManager.__bases__ = (MockManager, )

    with patch.multiple('pyolite.managers.repository',
                        Path=mocked_path,
                        Repository=mocked_repository):
        repos = RepositoryManager('/path/to/admin/repo/')
        repo = repos.create('dont_exists')

        mocked_path.has_calls(call(mocked_path, 'conf/repos/dont_exists.conf'))
        assert mocked_file.exists.call_count == 1
        mocked_file.write_file.assert_called_once_with('repo dont_exists\n')
        mocked_git.commit.has_calls(
            call(['dont_exists'], 'Created repo dont_exists'))
        mocked_repository.assert_called_once_with('dont_exists', mocked_path,
                                                  mocked_git)
        assert repo == 'new repo'
Exemple #3
0
  def test_get_all_users(self):
    mocked_key_dir = MagicMock()
    mocked_file = MagicMock()
    mocked_dir = MagicMock()
    mocked_re = MagicMock()

    mocked_user = MagicMock()
    mocked_user.get_by_name.return_value = 'test_user'

    mocked_path.return_value = mocked_key_dir
    mocked_dir.isdir.return_value = True
    mocked_file.isdir.return_value = False
    mocked_file.__str__ = lambda x: 'ok_file'

    mocked_re.compile().findall.return_value = ['file1.pub']

    mocked_key_dir.walk.return_value = [mocked_file, mocked_dir]

    UserManager.__bases__ = (MockManager, )
    with patch.multiple('pyolite.managers.user', User=mocked_user,
                        Path=mocked_path, re=mocked_re):
      users = UserManager('~/path/to/admin/gitolite/repo')

      eq_(users.all(), ['test_user'])
      mocked_path.has_calls([call(mocked_path, 'keydir')])
      eq_(mocked_key_dir.walk.call_count, 1)
      eq_(mocked_dir.isdir.call_count, 1)
      eq_(mocked_file.isdir.call_count, 1)

      mocked_re.compile.has_calls([call('(\w.pub)')])
      mocked_re.compile('\w.pub').findall.assert_called_once_with('ok_file')

      mocked_user.get_by_name.assert_called_once_with('file1', mocked_path,
                                                      mocked_git)
Exemple #4
0
  def test_it_should_commit_if_a_new_repository_was_succesfully_created(self):
    mocked_repository = MagicMock()

    mocked_file = MagicMock()
    mocked_file.__str__ = lambda x: 'dont_exists'

    mocked_file.exists.return_value = False
    mocked_path.return_value = mocked_file

    mocked_repository.return_value = 'new repo'

    RepositoryManager.__bases__ = (MockManager, )

    with patch.multiple('managers.repository',
                        Path=mocked_path,
                        Repository=mocked_repository):
      repos = RepositoryManager('/path/to/admin/repo/')
      repo = repos.create('dont_exists')

      mocked_path.has_calls(call(mocked_path,
                                 'conf/repos/dont_exists.conf'))
      eq_(mocked_file.exists.call_count, 1)
      mocked_file.write_file.assert_called_once_with('repo dont_exists\n')
      mocked_git.commit.has_calls(call(['dont_exists'],
                                       'Created repo dont_exists'))
      mocked_repository.assert_called_once_with('dont_exists', mocked_path,
                                                mocked_git)
      eq_(repo, 'new repo')
Exemple #5
0
    def test_it_should_commit_if_a_new_repository_was_succesfully_created(self):
        mocked_repository = MagicMock()

        mocked_file = MagicMock()
        mocked_file.__str__ = lambda x: "dont_exists"

        mocked_file.exists.return_value = False
        mocked_path.return_value = mocked_file

        mocked_repository.return_value = "new repo"

        RepositoryManager.__bases__ = (MockManager,)

        with patch.multiple("pyolite.managers.repository", Path=mocked_path, Repository=mocked_repository):
            repos = RepositoryManager("/path/to/admin/repo/")
            repo = repos.create("dont_exists")

            mocked_path.has_calls(call(mocked_path, "conf/repos/dont_exists.conf"))
            eq_(mocked_file.exists.call_count, 1)
            mocked_file.write_file.assert_called_once_with("repo dont_exists\n")
            mocked_git.commit.has_calls(call(["dont_exists"], "Created repo dont_exists"))
            mocked_repository.assert_called_once_with("dont_exists", mocked_path, mocked_git)
            eq_(repo, "new repo")