# Path: openid/fetchers.py
# def setDefaultFetcher(fetcher, wrap_exceptions=True):
#     """Set the default fetcher
# 
#     @param fetcher: The fetcher to use as the default HTTP fetcher
#     @type fetcher: HTTPFetcher
# 
#     @param wrap_exceptions: Whether to wrap exceptions thrown by the
#         fetcher wil HTTPFetchingError so that they may be caught
#         easier. By default, exceptions will be wrapped. In general,
#         unwrapped fetchers are useful for debugging of fetching errors
#         or if your fetcher raises well-known exceptions that you would
#         like to catch.
#     @type wrap_exceptions: bool
#     """
#     global _default_fetcher
#     if fetcher is None or not wrap_exceptions:
#         _default_fetcher = fetcher
#     else:
#         _default_fetcher = ExceptionWrappingFetcher(fetcher)
# 
# class HTTPResponse(object):
#     """XXX document attributes
# 
#     @type body: six.binary_type
#     """
#     headers = None
#     status = None
#     body = None
#     final_url = None
# 
#     def __init__(self, final_url=None, status=None, headers=None, body=None):
#         self.final_url = final_url
#         self.status = status
#         self.headers = headers
#         self.body = body
# 
#     def __repr__(self):
#         return "<%s status %s for %s>" % (self.__class__.__name__,
#                                           self.status,
#                                           self.final_url)
# 
# Path: openid/yadis/constants.py
# YADIS_CONTENT_TYPE = 'application/xrds+xml'


import django
from django.test import TestCase
from openid.fetchers import setDefaultFetcher, HTTPResponse
from openid.yadis.constants import YADIS_CONTENT_TYPE

EXAMPLE_XRDS = b'''<?xml version="1.0" encoding="UTF-8"?>
<xrds:XRDS xmlns:xrds="xri://$xrds" xmlns="xri://$xrd*($v*2.0)">
  <XRD>
    <Service priority="0">
      <Type>http://specs.openid.net/auth/2.0/server</Type>
      <URI>http://example.com/</URI>
    </Service>
  </XRD>
</xrds:XRDS>'''


class FakeFetcher(object):
    """Fake fetcher for tests."""

    def __init__(self):
        self.response = None

    def fetch(self, *args, **kwargs):
        return self.response


class TestStartOpenID(TestCase):
    """Test 'startOpenID' view."""

    def setUp(self):
        self.fetcher = FakeFetcher()
        setDefaultFetcher(self.fetcher)

    def tearDown(self):

# Path: openid/fetchers.py
# def setDefaultFetcher(fetcher, wrap_exceptions=True):
#     """Set the default fetcher
# 
#     @param fetcher: The fetcher to use as the default HTTP fetcher
#     @type fetcher: HTTPFetcher
# 
#     @param wrap_exceptions: Whether to wrap exceptions thrown by the
#         fetcher wil HTTPFetchingError so that they may be caught
#         easier. By default, exceptions will be wrapped. In general,
#         unwrapped fetchers are useful for debugging of fetching errors
#         or if your fetcher raises well-known exceptions that you would
#         like to catch.
#     @type wrap_exceptions: bool
#     """
#     global _default_fetcher
#     if fetcher is None or not wrap_exceptions:
#         _default_fetcher = fetcher
#     else:
#         _default_fetcher = ExceptionWrappingFetcher(fetcher)
# 
# class HTTPResponse(object):
#     """XXX document attributes
# 
#     @type body: six.binary_type
#     """
#     headers = None
#     status = None
#     body = None
#     final_url = None
# 
#     def __init__(self, final_url=None, status=None, headers=None, body=None):
#         self.final_url = final_url
#         self.status = status
#         self.headers = headers
#         self.body = body
# 
#     def __repr__(self):
#         return "<%s status %s for %s>" % (self.__class__.__name__,
#                                           self.status,
#                                           self.final_url)
# 
# Path: openid/yadis/constants.py
# YADIS_CONTENT_TYPE = 'application/xrds+xml'


# Path: examples/djopenid/consumer/tests.py
import django
from django.test import TestCase
from openid.fetchers import setDefaultFetcher, HTTPResponse
from openid.yadis.constants import YADIS_CONTENT_TYPE


EXAMPLE_XRDS = b'''<?xml version="1.0" encoding="UTF-8"?>
<xrds:XRDS xmlns:xrds="xri://$xrds" xmlns="xri://$xrd*($v*2.0)">
  <XRD>
    <Service priority="0">
      <Type>http://specs.openid.net/auth/2.0/server</Type>
      <URI>http://example.com/</URI>
    </Service>
  </XRD>
</xrds:XRDS>'''


class FakeFetcher(object):
    """Fake fetcher for tests."""

    def __init__(self):
        self.response = None

    def fetch(self, *args, **kwargs):
        return self.response


class TestStartOpenID(TestCase):
    """Test 'startOpenID' view."""

    def setUp(self):
        self.fetcher = FakeFetcher()
        setDefaultFetcher(self.fetcher)

    def tearDown(self):

        setDefaultFetcher(None)