Beispiel #1
0
    def test_command_not_known(self):
        """
        Test command not known

        Running a command not known to the program will exit it
        """
        with assert_raises(SystemExit):
            main.run_command("Warp 8", "Engage!")
Beispiel #2
0
    def test_command_add(self, mock_get_dotconfig, mock_set_dotconfig):
        """
        Test command 'add'

        Command add should run correctly given the right arguments
        """
        mock_get_dotconfig.return_value = self.dotconfig_tracking

        args = ["tempfile", self.tempfile_tracking.name]
        main.run_command("add", args)
        assert_in("added to the .dotconfig file", self.output.getvalue())
Beispiel #3
0
    def test_command_run(self, mock_get_dot_path):
        """
        Test command 'run'

        When running the command run without arguments it should run the run
        method and because we don't have a backup folder it should raise a
        system
        """
        mock_get_dot_path.return_value = ""
        with assert_raises(SystemExit) as cm:
            main.run_command(None, None)
        assert_in("no backup and/or files folder found", cm.exception.args[0])
Beispiel #4
0
    def test_command_list_no_tracked_files(self, mock_get_dotconfig):
        """
        Test command 'list' when files aren't being tracked

        Running the list command should return a message that no files are
        being tracked when the dotconfig file is empty
        """
        data = json.loads(self.dotconfig_non_tracking)
        mock_get_dotconfig.return_value = data

        main.run_command("list", "")
        assert_in("No files are being tracked, add them with 'dot add'",
                  self.output.getvalue())
Beispiel #5
0
    def test_command_list_tracked_files(self, mock_get_dotconfig):
        """
        Test command 'list' when files are being tracked

        Running the list command should return a list of files that are being
        tracked. Given that the config files is present and files are being
        tracked.
        """
        data = json.loads(self.dotconfig_tracking)
        mock_get_dotconfig.return_value = data

        main.run_command("list", "")
        assert_in("The following files are being tracked",
                  self.output.getvalue())
Beispiel #6
0
    def test_command_init_dir_exists(self, mock_getcwd, mock_exists,
                                     mock_create_config_file,
                                     mock_set_dot_path):
        """
        Test command 'init' with a directory that exists

        When the back up folder and the files folder exist it should give
        notice to the user.
        """
        mock_create_config_file.return_value = True
        mock_set_dot_path.return_value = os.getcwd()
        mock_exists.return_value = True

        main.run_command("init", "")
        assert_in("found", self.output.getvalue())
Beispiel #7
0
    def test_command_init_dir_nonexistent(self, mock_create_config_file,
                                          mock_set_dot_path):
        """
        Test command 'init' with non-existent directory

        When the back up folder and the files folder are not found it should
        be created. We need to make a temp dir in order to let the backup and
        files folder be created.
        """
        mock_create_config_file.return_value = True
        mock_set_dot_path.return_value = True

        tempdir = tempfile.mkdtemp()
        os.chdir(tempdir)
        main.run_command("init", "")

        assert_true(os.path.exists("backup"))
        assert_true(os.path.exists("files"))

        shutil.rmtree(tempdir)