# Path: bakery/cookies/exceptions.py
# class InvalidRepositoryError(ValueError):
#     pass
# 
# Path: bakery/utils/test.py
# def read(base, *paths):
#     fp = join(dirname(base), *paths)
#     with open(fp, 'r') as f:
#         return f.read()
# 
# Path: bakery/utils/vcs/gh.py
# def _github_setup():
#     """
#     Sets up the server-wide Github authentication for the project and returns
#     an authorized `Github object from PyGithub
#     <http://jacquev6.github.io/PyGithub/github.html>`_ which can be used to
#     list users, repos, etc.
#     """
# 
#     credentials = getattr(settings, 'GITHUB_CREDENTIALS', None)
# 
#     if credentials is None:
#         raise ImproperlyConfigured('No GITHUB_CREDENTIALS set')
# 
#     # Verify that only allowed keys are passed
#     allowed_keys = set(['login_or_token', 'password', 'client_id', 'client_secret'])
#     given_keys = set(credentials.keys())
#     forbidden_keys = given_keys - allowed_keys
#     if given_keys - allowed_keys:
#         raise ImproperlyConfigured('Invalid keys in GITHUB_CREDENTIALS: '
#                                    '{0}'.format(','.join(forbidden_keys)))
# 
#     if 'password' in credentials and not 'login_or_token' in credentials:
#         raise ImproperlyConfigured('You need to define the login_or_token to '
#                                    'use password authentiaction in GITHUB_CREDENTIALS')
# 
#     if 'client_secret' in credentials and not 'client_id' in credentials:
#         raise ImproperlyConfigured('You need to define the client_id to '
#                                    'use client_secret authentiaction in GITHUB_CREDENTIALS')
# 
#     if 'client_id' in credentials and not 'client_secret' in credentials:
#         raise ImproperlyConfigured('You need to define the client_secret to '
#                                    'use client_id authentiaction in GITHUB_CREDENTIALS')
# 
#     return Github(**credentials)
# 
# def get_repo_from_url(url, gh_setup=github_setup):
#     """
#     Given an URL like (ssh://)git@github.com/user/repo.git or any other url
#     that defines the root of a repository, this function returns the PyGithub
#     resource describing that object.
# 
#     One can use :func:`get_cookie_data_from_repo` or
#     :func:`get_mapping_file_from_repo` to get further information about that
#     repository such as the content of the ``cookiecutter.json`` file.
# 
#     :param str url: The root URL to a github repository
#     :param gh_setup: If not the server-wide authentiaction :data:`github_setup`
#         should be used, this parameter can be set to another, e.g. user
#         authenticated PyGithub object
#     :return: Returns an instance of a ``PyGithub.Repository``.
#     :raises: ``InvalidRepositoryError`` if the given URL does not match a known
#         GitHub URL.
#     """
#     if 'git@github.com' in url:
#         identifier = 'git@github.com'
#     elif 'https://github.com/' in url:
#         identifier = 'https://github.com'
#     else:
#         raise InvalidRepositoryError('{0} is not a valid GitHub URL'.format(url))
#     index = url.index(identifier)
#     length = len(identifier)
#     start = length + index + 1  # +1 for separator after identifier
#     full_name = url[start:]
#     if full_name.endswith('.git'):
#         full_name = full_name[:-4]  # strip .git
#     return get_repo_from_full_name(full_name, gh_setup)


import httpretty
from django.core.exceptions import ImproperlyConfigured
from django.test.utils import override_settings
from django.utils.unittest import TestCase
from bakery.cookies.exceptions import InvalidRepositoryError
from bakery.utils.test import read
from bakery.utils.vcs.gh import _github_setup, get_repo_from_url
# -*- coding: utf-8 -*-





class TestGithub(TestCase):

    @override_settings(GITHUB_CREDENTIALS=None)
    def test_github_credentials_none(self):
        self.assertRaises(ImproperlyConfigured, _github_setup)

    @override_settings(GITHUB_CREDENTIALS={'something': 'value'})
    def test_github_credentials_invalid_key(self):
        self.assertRaises(ImproperlyConfigured, _github_setup)

    @override_settings(GITHUB_CREDENTIALS={'something': 'value', 'password': 'foo'})
    def test_github_credentials_invalid_key2(self):
        self.assertRaises(ImproperlyConfigured, _github_setup)

    @override_settings(GITHUB_CREDENTIALS={'password': 'foo'})
    def test_github_credentials_missing_login(self):
        self.assertRaises(ImproperlyConfigured, _github_setup)

    @override_settings(GITHUB_CREDENTIALS={'client_id': 'foo'})
    def test_github_credentials_missing_client_secret(self):
        self.assertRaises(ImproperlyConfigured, _github_setup)

    @override_settings(GITHUB_CREDENTIALS={'client_secret': 'foo'})
    def test_github_credentials_missing_client_id(self):

# Path: bakery/cookies/exceptions.py
# class InvalidRepositoryError(ValueError):
#     pass
# 
# Path: bakery/utils/test.py
# def read(base, *paths):
#     fp = join(dirname(base), *paths)
#     with open(fp, 'r') as f:
#         return f.read()
# 
# Path: bakery/utils/vcs/gh.py
# def _github_setup():
#     """
#     Sets up the server-wide Github authentication for the project and returns
#     an authorized `Github object from PyGithub
#     <http://jacquev6.github.io/PyGithub/github.html>`_ which can be used to
#     list users, repos, etc.
#     """
# 
#     credentials = getattr(settings, 'GITHUB_CREDENTIALS', None)
# 
#     if credentials is None:
#         raise ImproperlyConfigured('No GITHUB_CREDENTIALS set')
# 
#     # Verify that only allowed keys are passed
#     allowed_keys = set(['login_or_token', 'password', 'client_id', 'client_secret'])
#     given_keys = set(credentials.keys())
#     forbidden_keys = given_keys - allowed_keys
#     if given_keys - allowed_keys:
#         raise ImproperlyConfigured('Invalid keys in GITHUB_CREDENTIALS: '
#                                    '{0}'.format(','.join(forbidden_keys)))
# 
#     if 'password' in credentials and not 'login_or_token' in credentials:
#         raise ImproperlyConfigured('You need to define the login_or_token to '
#                                    'use password authentiaction in GITHUB_CREDENTIALS')
# 
#     if 'client_secret' in credentials and not 'client_id' in credentials:
#         raise ImproperlyConfigured('You need to define the client_id to '
#                                    'use client_secret authentiaction in GITHUB_CREDENTIALS')
# 
#     if 'client_id' in credentials and not 'client_secret' in credentials:
#         raise ImproperlyConfigured('You need to define the client_secret to '
#                                    'use client_id authentiaction in GITHUB_CREDENTIALS')
# 
#     return Github(**credentials)
# 
# def get_repo_from_url(url, gh_setup=github_setup):
#     """
#     Given an URL like (ssh://)git@github.com/user/repo.git or any other url
#     that defines the root of a repository, this function returns the PyGithub
#     resource describing that object.
# 
#     One can use :func:`get_cookie_data_from_repo` or
#     :func:`get_mapping_file_from_repo` to get further information about that
#     repository such as the content of the ``cookiecutter.json`` file.
# 
#     :param str url: The root URL to a github repository
#     :param gh_setup: If not the server-wide authentiaction :data:`github_setup`
#         should be used, this parameter can be set to another, e.g. user
#         authenticated PyGithub object
#     :return: Returns an instance of a ``PyGithub.Repository``.
#     :raises: ``InvalidRepositoryError`` if the given URL does not match a known
#         GitHub URL.
#     """
#     if 'git@github.com' in url:
#         identifier = 'git@github.com'
#     elif 'https://github.com/' in url:
#         identifier = 'https://github.com'
#     else:
#         raise InvalidRepositoryError('{0} is not a valid GitHub URL'.format(url))
#     index = url.index(identifier)
#     length = len(identifier)
#     start = length + index + 1  # +1 for separator after identifier
#     full_name = url[start:]
#     if full_name.endswith('.git'):
#         full_name = full_name[:-4]  # strip .git
#     return get_repo_from_full_name(full_name, gh_setup)


# Path: tests/utils/test_vcs_gh.py
import httpretty
from django.core.exceptions import ImproperlyConfigured
from django.test.utils import override_settings
from django.utils.unittest import TestCase
from bakery.cookies.exceptions import InvalidRepositoryError
from bakery.utils.test import read
from bakery.utils.vcs.gh import _github_setup, get_repo_from_url

# -*- coding: utf-8 -*-





class TestGithub(TestCase):

    @override_settings(GITHUB_CREDENTIALS=None)
    def test_github_credentials_none(self):
        self.assertRaises(ImproperlyConfigured, _github_setup)

    @override_settings(GITHUB_CREDENTIALS={'something': 'value'})
    def test_github_credentials_invalid_key(self):
        self.assertRaises(ImproperlyConfigured, _github_setup)

    @override_settings(GITHUB_CREDENTIALS={'something': 'value', 'password': 'foo'})
    def test_github_credentials_invalid_key2(self):
        self.assertRaises(ImproperlyConfigured, _github_setup)

    @override_settings(GITHUB_CREDENTIALS={'password': 'foo'})
    def test_github_credentials_missing_login(self):
        self.assertRaises(ImproperlyConfigured, _github_setup)

    @override_settings(GITHUB_CREDENTIALS={'client_id': 'foo'})
    def test_github_credentials_missing_client_secret(self):
        self.assertRaises(ImproperlyConfigured, _github_setup)

    @override_settings(GITHUB_CREDENTIALS={'client_secret': 'foo'})
    def test_github_credentials_missing_client_id(self):

        self.assertRaises(ImproperlyConfigured, _github_setup)