-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
pguimon
committed
Jun 5, 2024
1 parent
2becac3
commit b1d49f6
Showing
2 changed files
with
49 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import unittest | ||
import requests | ||
from helpers.GitHelper import GitHelper | ||
from unittest import mock | ||
|
||
# ------------------------------------------------------------------------------------------- | ||
# Mocks used in the below unit test class | ||
# ------------------------------------------------------------------------------------------- | ||
def mocked_pull_request_failure(*args, **kwargs): | ||
""" | ||
Mock function to mimic a failure to create a pull request | ||
""" | ||
raise requests.exceptions.HTTPError | ||
|
||
# ------------------------------------------------------------------------------------------- | ||
# Unit test class | ||
# ------------------------------------------------------------------------------------------- | ||
class TestGitHelper(unittest.TestCase): | ||
|
||
# Mock some methods. The mock object is passed in to our test case method. | ||
@mock.patch('helpers.GitHelper.requests.post', side_effect=mocked_pull_request_failure) | ||
def test_create_pull_request_ko(self, mock_requests_post): | ||
git_helper = GitHelper() | ||
repository = "repository" | ||
title = "title" | ||
description = "description" | ||
head_branch = "head_branch" | ||
base_branch = "base_branch" | ||
git_token = "git_token" | ||
self.assertRaises(requests.exceptions.HTTPError, | ||
lambda: git_helper.create_pull_request(repository, title, description, head_branch, | ||
base_branch, git_token)) | ||
|
||
# ------------------------------------------------------------------------------------------- | ||
# Main | ||
# ------------------------------------------------------------------------------------------- | ||
if __name__ == "__main__": | ||
unittest.main() |