<filename>tests/lib/bes/git/test_git_config.py
#!/usr/bin/env python
#-*- coding:utf-8; mode:python; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*-
#
from bes.testing.unit_test import unit_test
from bes.system.env_override import env_override_temp_home_func

from bes.git.git_config import git_config

class test_git_config(unit_test):

  @env_override_temp_home_func()
  def test_get_never_set(self):
    self.assertEqual( None, git_config.get_value('user.name') )
    self.assertEqual( None, git_config.get_value('user.email') )

  @env_override_temp_home_func()
  def test_set_user_name_and_email(self):
    git_config.set_value('user.name', 'foo bar')
    self.assertEqual( 'foo bar', git_config.get_value('user.name') )
      
    git_config.set_value('user.email', '<EMAIL>')
    self.assertEqual( '<EMAIL>', git_config.get_value('user.email') )
    self.assertEqual( ( 'foo bar', '<EMAIL>' ), git_config.get_identity() )

  @env_override_temp_home_func()
  def test_set_identity(self):
    git_config.set_identity('green kiwi', '<EMAIL>')
    self.assertEqual( ( 'green kiwi', '<EMAIL>' ), git_config.get_identity() )

  @env_override_temp_home_func()
  def test_unset(self):
    git_config.set_identity('green kiwi', '<EMAIL>')
    git_config.unset_value('user.email')
    self.assertEqual( ( 'green kiwi', None ), git_config.get_identity() )

    git_config.unset_value('user.name')
    self.assertEqual( ( None, None ), git_config.get_identity() )
      
if __name__ == '__main__':
  unit_test.main()
