Example #1
0
    def should_clone_git_repo(self, mock_working_dir):

        # Create a fake temp repo w/ commit
        git_dir = tempfile.mkdtemp(prefix='git')
        git_repo = Repo.init(git_dir)
        try:
            f = open(os.path.join(git_dir, 'foo.txt'), 'w')
            f.write('blah')
        except IOError:
            assert False
        finally:
            f.close()
        cwd = os.getcwd()
        os.chdir(git_dir)
        git_repo.index.add(['foo.txt'])
        git_repo.index.commit("Added foo.txt")
        os.chdir(cwd)

        # Fake Template Path
        mock_working_dir.return_value = tempfile.gettempdir()

        # Now attempt to clone but patch for Exception throw
        self.config.template = 'git+' + git_dir
        t = Template(self.config)
        t.copy_template()

        # Clean up
        rmtree(t.project_root)

        self.assertFalse(os.path.isdir(t.config.template))
        self.assertFalse(self.config.cli_opts.error.called)
Example #2
0
    def should_clone_git_repo(self, mock_working_dir):

        # Create a fake temp repo w/ commit
        git_dir = tempfile.mkdtemp(prefix='git')
        git_repo = Repo.init(git_dir)
        try:
            f = open(os.path.join(git_dir, 'foo.txt'), 'w')
            f.write('blah')
        except IOError:
            assert False
        finally:
            f.close()
        cwd = os.getcwd()
        os.chdir(git_dir)
        git_repo.index.add(['foo.txt'])
        git_repo.index.commit("Added foo.txt")
        os.chdir(cwd)

        # Fake Template Path
        mock_working_dir.return_value = tempfile.gettempdir()

        # Now attempt to clone but patch for Exception throw
        self.config.template = 'git+' + git_dir
        t = Template(self.config)
        t.copy_template()

        # Clean up
        rmtree(t.project_root)

        self.assertFalse(os.path.isdir(t.config.template))
        self.assertFalse(self.config.cli_opts.error.called)
Example #3
0
 def ensure_excluded_dirs_are_not_copied(self, mock_working_dir):
     mock_working_dir.return_value = tempfile.gettempdir()
     t = Template(self.config)
     t.exclude_dirs.append('.exclude_this')
     t.copy_template()
     self.assertFalse(
         os.path.isdir(os.path.join(t.project_root, '.exclude_this')))
     rmtree(t.project_root)
Example #4
0
 def test_excluded_dirs_are_not_copied(self, mock_working_dir):
     mock_working_dir.return_value = tempfile.gettempdir()
     t = Template(self.config)
     t.exclude_dirs.append('.exclude_this')
     t.copy_template()
     self.assertFalse(os.path.isdir(os.path.join(t.project_root,
                                                 '.exclude_this')))
     rmtree(t.project_root)
Example #5
0
 def test_copy_directory_tree_if_is_dir(self, mock_working_dir):
     mock_working_dir.return_value = tempfile.gettempdir()
     t = Template(self.config)
     t.exclude_dirs.append('.exclude_this')
     t.copy_template()
     self.assertTrue(os.path.isdir(os.path.join(t.project_root,
                                                'should_copy_this')))
     rmtree(t.project_root)
Example #6
0
 def test_directory_not_renamed_if_not_in_placeholders(self,
                                                       mock_working_dir):
     mock_working_dir.return_value = tempfile.gettempdir()
     t = Template(self.config)
     t.copy_template()
     self.assertTrue(os.path.isdir(os.path.join(t.project_root,
                                                '__NOT_IN_PLACEHOLDERS__')))
     rmtree(t.project_root)
Example #7
0
 def test_rename_files_in_placeholders(self, mock_working_dir):
     mock_working_dir.return_value = tempfile.gettempdir()
     t = Template(self.config)
     t.copy_template()
     self.assertTrue(os.path.isfile(os.path.join(
         t.project_root, '__NOT_IN_PLACEHOLDERS__',
         '%s.txt' % self.config.project_name)))
     rmtree(t.project_root)
Example #8
0
 def should_copy_directory_tree_if_is_dir(self, mock_working_dir):
     mock_working_dir.return_value = tempfile.gettempdir()
     t = Template(self.config)
     t.exclude_dirs.append('.exclude_this')
     t.copy_template()
     self.assertTrue(
         os.path.isdir(os.path.join(t.project_root, 'should_copy_this')))
     rmtree(t.project_root)
Example #9
0
 def ensure_directory_not_renamed_if_not_in_placeholders(
         self, mock_working_dir):
     mock_working_dir.return_value = tempfile.gettempdir()
     t = Template(self.config)
     t.copy_template()
     self.assertTrue(
         os.path.isdir(
             os.path.join(t.project_root, '__NOT_IN_PLACEHOLDERS__')))
     rmtree(t.project_root)
Example #10
0
 def should_rename_files_in_placeholders(self, mock_working_dir):
     mock_working_dir.return_value = tempfile.gettempdir()
     t = Template(self.config)
     t.copy_template()
     self.assertTrue(
         os.path.isfile(
             os.path.join(t.project_root, '__NOT_IN_PLACEHOLDERS__',
                          '%s.txt' % self.config.project_name)))
     rmtree(t.project_root)
Example #11
0
 def test_copy_template_failes_if_dir_does_not_exist(
         self, mock_working_dir, mock_error, mock_isdir):
     mock_working_dir.return_value = tempfile.gettempdir()
     tmp_dir = tempfile.mkdtemp(suffix=self.config.project_name, prefix='')
     tmp_dir_name = list(os.path.split(tmp_dir))[-1:][0]
     self.config.project_name = tmp_dir_name
     t = Template(self.config)
     t.copy_template()
     self.config._error.assert_called_with(
         'Unable to copy template, directory does not exist')
Example #12
0
 def test_copy_template_failes_if_dir_does_not_exist(
         self, mock_working_dir, mock_error, mock_isdir):
     mock_working_dir.return_value = tempfile.gettempdir()
     tmp_dir = tempfile.mkdtemp(suffix=self.config.project_name, prefix='')
     tmp_dir_name = list(os.path.split(tmp_dir))[-1:][0]
     self.config.project_name = tmp_dir_name
     t = Template(self.config)
     t.copy_template()
     self.config._error.assert_called_with(
         'Unable to copy template, directory does not exist')
Example #13
0
    def test_dir_cannot_be_created_if_already_exists(self, mock_working_dir,
                                                     mock_error, mock_isdir):
        mock_working_dir.return_value = tempfile.gettempdir()
        tmp_dir = tempfile.mkdtemp(suffix=self.config.project_name, prefix='')
        tmp_dir_name = list(os.path.split(tmp_dir))[-1:][0]
        self.config.project_name = tmp_dir_name
        t = Template(self.config)
        t.copy_template()
        rmtree(tmp_dir)

        self.config._error.assert_called_with('%s already exists' % (tmp_dir))
Example #14
0
    def test_dir_cannot_be_created_if_already_exists(self, mock_working_dir,
                                                     mock_error, mock_isdir):
        mock_working_dir.return_value = tempfile.gettempdir()
        tmp_dir = tempfile.mkdtemp(suffix=self.config.project_name, prefix='')
        tmp_dir_name = list(os.path.split(tmp_dir))[-1:][0]
        self.config.project_name = tmp_dir_name
        t = Template(self.config)
        t.copy_template()
        rmtree(tmp_dir)

        self.config._error.assert_called_with('%s already exists' % (tmp_dir))
Example #15
0
    def test_exception_if_directory_creation_fails(self, mock_working_dir,
                                                   mock_error, mock_os_mkdir):
        mock_working_dir.return_value = tempfile.gettempdir()
        tmp_dir = tempfile.mkdtemp(suffix=self.config.project_name, prefix='')
        tmp_dir_name = list(os.path.split(tmp_dir))[-1:][0]
        self.config.project_name = tmp_dir_name
        t = Template(self.config)
        t.copy_template()

        self.config._error.assert_called_with(
            'Error creating project directory')
        mock_os_mkdir.assert_called_with(
            os.path.join(t.working_dir, self.config.project_name))
Example #16
0
    def ensure_exception_if_directory_creation_fails(self, mock_os_mkdir):
        try:
            t = Template(self.config)
            t.copy_template()
        except Exception:
            assert True
        else:
            assert False

        self.config.cli_opts.error.assert_called_with(
            'Error creating project directory')
        mock_os_mkdir.assert_called_with(os.path.join(
            t.working_dir, self.config.project_name))
Example #17
0
    def ensure_exception_if_directory_creation_fails(self, mock_os_mkdir):
        try:
            t = Template(self.config)
            t.copy_template()
        except Exception:
            assert True
        else:
            assert False

        self.config.cli_opts.error.assert_called_with(
            'Error creating project directory')
        mock_os_mkdir.assert_called_with(
            os.path.join(t.working_dir, self.config.project_name))
Example #18
0
    def test_exception_if_directory_creation_fails(self, mock_working_dir,
                                                   mock_error,
                                                   mock_os_mkdir):
        mock_working_dir.return_value = tempfile.gettempdir()
        tmp_dir = tempfile.mkdtemp(suffix=self.config.project_name, prefix='')
        tmp_dir_name = list(os.path.split(tmp_dir))[-1:][0]
        self.config.project_name = tmp_dir_name
        t = Template(self.config)
        t.copy_template()

        self.config._error.assert_called_with(
            'Error creating project directory')
        mock_os_mkdir.assert_called_with(os.path.join(
            t.working_dir, self.config.project_name))
Example #19
0
 def ensure_copy_template_failes_if_dir_does_not_exist(
         self, mock_working_dir, mock_isdir):
     mock_working_dir.return_value = tempfile.gettempdir()
     tmp_dir = tempfile.mkdtemp(suffix=self.config.project_name, prefix='')
     tmp_dir_name = list(os.path.split(tmp_dir))[-1:][0]
     self.config.project_name = tmp_dir_name
     try:
         t = Template(self.config)
         t.copy_template()
     except:
         self.config.cli_opts.error.assert_called_with(
             'Unable to copy template, directory does not exist')
         assert True
     else:
         assert False
Example #20
0
 def ensure_copy_template_failes_if_dir_does_not_exist(
         self, mock_working_dir, mock_isdir):
     mock_working_dir.return_value = tempfile.gettempdir()
     tmp_dir = tempfile.mkdtemp(suffix=self.config.project_name, prefix='')
     tmp_dir_name = list(os.path.split(tmp_dir))[-1:][0]
     self.config.project_name = tmp_dir_name
     try:
         t = Template(self.config)
         t.copy_template()
     except:
         self.config.cli_opts.error.assert_called_with(
             'Unable to copy template, directory does not exist')
         assert True
     else:
         assert False
Example #21
0
    def ensure_dir_cannot_be_created_if_already_exists(self, mock_working_dir):
        mock_working_dir.return_value = tempfile.gettempdir()
        tmp_dir = tempfile.mkdtemp(suffix=self.config.project_name, prefix='')
        tmp_dir_name = list(os.path.split(tmp_dir))[-1:][0]
        self.config.project_name = tmp_dir_name
        try:
            t = Template(self.config)
            t.copy_template()
            rmtree(tmp_dir)
        except Exception:
            assert True
        else:
            assert False

        self.config.cli_opts.error.assert_called_with('%s already exists' % (
            tmp_dir))
Example #22
0
    def ensure_dir_cannot_be_created_if_already_exists(self, mock_working_dir):
        mock_working_dir.return_value = tempfile.gettempdir()
        tmp_dir = tempfile.mkdtemp(suffix=self.config.project_name, prefix='')
        tmp_dir_name = list(os.path.split(tmp_dir))[-1:][0]
        self.config.project_name = tmp_dir_name
        try:
            t = Template(self.config)
            t.copy_template()
            rmtree(tmp_dir)
        except Exception:
            assert True
        else:
            assert False

        self.config.cli_opts.error.assert_called_with('%s already exists' %
                                                      (tmp_dir))
Example #23
0
    def test_clone_git_repo(self, mock_working_dir):

        # Create a fake temp repo w/ commit
        git_dir = tempfile.mkdtemp(prefix='git')
        git.init(git_dir)

        try:
            f = open(os.path.join(git_dir, 'foo.txt'), 'w')
            f.write('blah')
        except IOError:
            assert False
        finally:
            f.close()
        cwd = os.getcwd()
        os.chdir(git_dir)
        git.add('foo.txt')
        if os.environ.get('TRAVIS_CI') == 'true':
            git.config('--global', 'user.email',
                       '"*****@*****.**"')
            git.config('--global', 'user.name',
                       '"Testing on Travis CI"')
        git.commit('-m "Added foo.txt"')
        os.chdir(cwd)

        # Fake Template Path
        mock_working_dir.return_value = tempfile.gettempdir()

        # Now attempt to clone but patch for Exception throw
        self.config.template = 'git+' + git_dir
        self.config._tpl = git_dir
        t = Template(self.config)
        t.copy_template()

        # Clean up
        rmtree(t.project_root)

        self.assertFalse(os.path.isdir(t.config.template))
        self.assertFalse(self.config.cli_opts.error.called)
Example #24
0
    def test_clone_git_repo(self, mock_working_dir):

        # Create a fake temp repo w/ commit
        git_dir = tempfile.mkdtemp(prefix='git')
        git.init(git_dir)

        try:
            f = open(os.path.join(git_dir, 'foo.txt'), 'w')
            f.write('blah')
        except IOError:
            assert False
        finally:
            f.close()
        cwd = os.getcwd()
        os.chdir(git_dir)
        git.add('foo.txt')
        if os.environ.get('TRAVIS_CI') == 'true':
            git.config('--global', 'user.email',
                       '"*****@*****.**"')
            git.config('--global', 'user.name', '"Testing on Travis CI"')
        git.commit('-m "Added foo.txt"')
        os.chdir(cwd)

        # Fake Template Path
        mock_working_dir.return_value = tempfile.gettempdir()

        # Now attempt to clone but patch for Exception throw
        self.config.template = 'git+' + git_dir
        self.config._tpl = git_dir
        t = Template(self.config)
        t.copy_template()

        # Clean up
        rmtree(t.project_root)

        self.assertFalse(os.path.isdir(t.config.template))
        self.assertFalse(self.config.cli_opts.error.called)