Skip to content

Instantly share code, notes, and snippets.

@Ivaylo-Bachvarov
Created August 22, 2014 20:04
Show Gist options
  • Save Ivaylo-Bachvarov/76afaf1281c5758cc0c7 to your computer and use it in GitHub Desktop.
Save Ivaylo-Bachvarov/76afaf1281c5758cc0c7 to your computer and use it in GitHub Desktop.
import unittest
import github
from mock import patch
from github import GithubException
def is_valid_repo(github_lib, user_name, repo_name):
github_client = github_lib("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
class Github_repo_mock:
def __init__(self):
pass
class Github_user_mock:
def __init__(self):
pass
def get_repo(self, repo_name):
return Github_repo_mock()
class Github_mock:
def __init__(self, token):
self.token = token
def get_user(self, user_name):
return Github_user_mock()
@patch('github.Github')
class Test(unittest.TestCase):
def test_is_valid_repo(self, Github_mock):
user_name = 'Ivaylo-Bachvarov'
repo_name = 'Telerik-Courses'
self.assertEqual(is_valid_repo(github.Github, user_name, repo_name), True)
if __name__ == '__main__':
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment