Esempio n. 1
0
    def test_set_prof(self):
        """Simulates the set order to check the correct operative effect."""
        warnings.simplefilter("ignore",
                              ResourceWarning)  # Working with tmp files

        # Uses a mock tmp cherfile
        tmp_dir = tempfile.mkdtemp()
        cherfile_path = tempfile.mkstemp(dir=tmp_dir, prefix='tmp_cherfile')
        mock.patch('model_layer.CHERFILE', cherfile_path)
        model_layer.create_cherfile()

        # Commiter data to create the mock repo
        commiter1_name = 'jane'
        commiter1_mail = 'janedoe@home'
        commiter1_sign = "1234567A"
        commiter1_sign_pref = True

        # Create a mock repo
        commiter = commiter1_name + ' <' + commiter1_mail + '>'
        repo_path = create_tmp_dir_with_repo(commiter)

        # Really commiter profile
        prof1_name = "sample1"
        prof1 = prof.Prof(profname=prof1_name,
                          name=commiter1_name,
                          email=commiter1_mail,
                          signkey=commiter1_sign,
                          signpref=commiter1_sign_pref)

        # Another sample profile
        prof2_name = "sample2"
        commiter2_name = 'Pepe García'
        commiter2_mail = '*****@*****.**'
        commiter2_sign = 'None'
        commiter2_sign_pref = False
        prof2 = prof.Prof(profname=prof2_name,
                          name=commiter2_name,
                          email=commiter2_mail,
                          signkey=commiter2_sign,
                          signpref=commiter2_sign_pref)

        gitcher.add_prof_fast(prof1_name, commiter1_name, commiter1_mail,
                              commiter1_sign, commiter1_sign_pref)
        gitcher.add_prof_fast(prof2_name, commiter2_name, commiter2_mail,
                              commiter2_sign, commiter2_sign_pref)

        model_layer.switch_prof(prof1.profname, path=str(repo_path))
        current_prof = model_layer.recuperate_git_current_prof(str(repo_path))

        self.assertEqual(prof1, current_prof)

        # Clean environment
        os.remove(cherfile_path[1])
        remove_tmp_dir(repo_path)
Esempio n. 2
0
def set_prof_global(profname: str) -> None:
    """Function that sets the selected profile globally.

    It is not necessary to be called from a directory with a git repository.
    Profile name must be checked before.

    :param profname: Name of the gitcher profile to operate with
    :type profname: str
    :return: None
    """
    model_layer.switch_prof(profname, flag='--global')
    print(MSG_OK + " Set {0} as git default profile.".format(profname))
Esempio n. 3
0
def set_prof(profname: str) -> None:
    """Function that sets the selected profile locally.

    It is imperative that it be called from a directory with a git
    repository. Profile name must be checked before.

    :param profname: Name of the gitcher profile to operate with
    :type profname: str
    :return: None
    """
    if model_layer.check_git_context():
        model_layer.switch_prof(profname)
        print(MSG_OK + " Switched to {0} profile.".format(profname))
    else:
        print(MSG_ERROR + " Current directory not contains a git repository.")