def test_get_commit_author(self): """Ensure the behavior of `get_commit_author()` : - `git.Actor` use the pk of the bot account when no one is connected - `git.Actor` use the pk (and the email) of the connected account when available (Implementation of `git.Actor` is there : https://github.com/gitpython-developers/GitPython/blob/master/git/util.py#L312) """ # 1. With user connected self.assertEqual( self.client.login(username=self.user_author.username, password='******'), True) # go to whatever page, if not, `get_current_user()` does not work at all result = self.client.get(reverse('zds.pages.views.index')) self.assertEqual(result.status_code, 200) actor = get_commit_author() self.assertEqual(actor['committer'].name, str(self.user_author.pk)) self.assertEqual(actor['author'].name, str(self.user_author.pk)) self.assertEqual(actor['committer'].email, self.user_author.email) self.assertEqual(actor['author'].email, self.user_author.email) # 2. Without connected user self.client.logout() # as above ... result = self.client.get(reverse('zds.pages.views.index')) self.assertEqual(result.status_code, 200) actor = get_commit_author() self.assertEqual(actor['committer'].name, str(self.mas.pk)) self.assertEqual(actor['author'].name, str(self.mas.pk))
def test_get_commit_author_not_auth(self): result = self.client.get(reverse('pages-index')) self.assertEqual(result.status_code, 200) actor = get_commit_author() self.assertEqual(actor['committer'].name, str(self.mas.pk)) self.assertEqual(actor['author'].name, str(self.mas.pk))
def copy_and_clean_repo(path_from, path_to): """Try to clean the repository from old errors made in the past by previous code, then clone it to the new location :param path_from: old repository :param path_to: new repository :return: sha of the commit if a clean up has been done, `None` otherwise """ old_repo = Repo(path_from) # look for files that are still in git but deleted in "real life" to_delete = [] for entry in old_repo.index.entries: rel_path = entry[0] abs_path = os.path.join(path_from, rel_path) if not os.path.exists(abs_path): to_delete.append(rel_path) # clean up sha = None if len(to_delete) != 0: old_repo.index.remove(to_delete) sha = old_repo.index.commit('Nettoyage pré-migratoire', **get_commit_author()) # then clone it to new repo old_repo.clone(path_to) return sha
def test_get_commit_author(self): """Ensure the behavior of `get_commit_author()` : - `git.Actor` use the pk of the bot account when no one is connected - `git.Actor` use the pk (and the email) of the connected account when available (Implementation of `git.Actor` is there : https://github.com/gitpython-developers/GitPython/blob/master/git/util.py#L312) """ # 1. With user connected self.assertEqual( self.client.login( username=self.user_author.username, password='******'), True) # go to whatever page, if not, `get_current_user()` does not work at all result = self.client.get(reverse('pages-index')) self.assertEqual(result.status_code, 200) actor = get_commit_author() self.assertEqual(actor['committer'].name, str(self.user_author.pk)) self.assertEqual(actor['author'].name, str(self.user_author.pk)) self.assertEqual(actor['committer'].email, self.user_author.email) self.assertEqual(actor['author'].email, self.user_author.email)
def commit_changes(self, commit_message): """Commit change made to the repository :param commit_message: The message that will appear in content history :return: commit sha :rtype: str """ cm = self.repository.index.commit(commit_message, **get_commit_author()) self.sha_draft = cm.hexsha self.current_version = cm.hexsha return cm.hexsha
def test_get_commit_author(self): """Ensure the behavior of `get_commit_author()` : - `git.Actor` use the pk of the bot account when no one is connected - `git.Actor` use the pk (and the email) of the connected account when available (Implementation of `git.Actor` is there : https://github.com/gitpython-developers/GitPython/blob/master/git/util.py#L312) """ # 1. With user connected self.client.force_login(self.user_author) # go to whatever page, if not, `get_current_user()` does not work at all result = self.client.get(reverse("pages-index")) self.assertEqual(result.status_code, 200) actor = get_commit_author() self.assertEqual(actor["committer"].name, str(self.user_author.pk)) self.assertEqual(actor["author"].name, str(self.user_author.pk)) self.assertEqual(actor["committer"].email, self.user_author.email) self.assertEqual(actor["author"].email, self.user_author.email)