Last active
August 29, 2015 14:05
-
-
Save Ivaylo-Bachvarov/1af0a50ef7b4c2f20e64 to your computer and use it in GitHub Desktop.
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
import unittest | |
import github | |
from mock import patch, Mock | |
from github import Github, GithubException | |
def is_valid_repo(user_name, repo_name): | |
github_client = Github("TOKEN_HERE") | |
try: | |
api_user = github_client.get_user(user_name) | |
api_repo = api_user.get_repo(repo_name) | |
return True | |
except GithubException: | |
return False | |
@patch('github.Github') | |
class Test(unittest.TestCase): | |
def test_is_valid_repo(self, Github): | |
user_name = 'Ivaylo-Bachvarov' | |
repo_name = 'Telerik-Courses' | |
api_repo = Mock() | |
api_repo.get_repo = Mock(side_effect=GithubException('status', 'data')) | |
# I have no idea what is status and data. It just requres them. | |
github_client = Mock() | |
github_client.get_user = Mock(return_value=api_repo) | |
Github.return_value = github_client | |
self.assertEqual(is_valid_repo(user_name, repo_name), False) | |
if __name__ == '__main__': | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment