Ejemplo n.º 1
0
    def test_delete_prof(self):
        """Simulates the delete 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)

        # Now, deletes prof2
        gitcher.delete_prof(prof2.profname)

        profs = model_layer.recuperate_profs()
        self.assertTrue(prof1 in profs)
        self.assertFalse(prof2 in profs)

        # Clean environment
        os.remove(cherfile_path[1])
        remove_tmp_dir(repo_path)
Ejemplo n.º 2
0
MSG_OK = "[" + COLOR_GREEN + "OK" + COLOR_RST + "]"
MSG_ERROR = "[" + COLOR_RED + "ERROR" + COLOR_RST + "]"
MSG_WARNING = "[" + COLOR_YELLOW + "WARNING" + COLOR_RST + "]"

# ===============================================
# =             Initial validations             =
# ===============================================
# First, check if git is installed
if not model_layer.check_git_installed():
    print(MSG_ERROR + " git is not installed in this machine. Impossible to "
          "continue.")
    sys.exit(1)

# Next, check if CHERFILE exists. If not, create it
if not model_layer.check_cherfile():
    model_layer.create_cherfile()
    print(MSG_OK + " Gitcher config dotfile created. Go on...")

# Unique global instance for the execution gitcher dictionary
dictionary = dictionary.Dictionary()


# ===============================================
# =             Auxiliary functions             =
# ===============================================
def quit_gracefully(signum, frame) -> None:
    """Function that prints a bye message. It is used to attach to escape
    signal (i.e.: Ctrl.+C) during the performance of the program. So, it
    is the exit function.

    :return: None, print function