# Path: oauth_provider/models.py
# class Nonce(models.Model):
# class Consumer(models.Model):
# class Token(models.Model):
#     def __unicode__(self):
#     def __unicode__(self):
#     def generate_random_codes(self):
#     def generate_rsa_key(self):
#     def resource(self):
#     def resource(self, value):
#     def __unicode__(self):
#     def to_string(self, only_key=False):
#     def generate_random_codes(self):
#     def get_callback_url(self, args=None):
#     def set_callback(self, callback):
#     def scope_to_list(self):
#     def timestamp_asdatetime(self):
#     def key_partial(self):
#     REQUEST = 1
#     ACCESS = 2
#     TOKEN_TYPES = ((REQUEST, 'Request'), (ACCESS, 'Access'))
# 
# Path: oauth_provider/compat.py
# AUTH_USER_MODEL = settings.AUTH_USER_MODEL
# class UnsafeRedirect(HttpResponse):
#     def __init__(self, target_url, *args, **kwargs):


import time
import urllib.request, urllib.parse, urllib.error
import re
import oauth2
from urllib.parse import parse_qs, urlparse
from django.test import TestCase, Client
from oauth_provider.models import Scope, Consumer, Token
from oauth_provider.compat import get_user_model
            'oauth_signature': '%s&' % self.CONSUMER_SECRET,
            'oauth_timestamp': str(int(time.time())),
            'oauth_nonce': 'requestnonce',
            'oauth_version': '1.0',
            'oauth_callback': self.callback,
            # 'scope': self.scope.name,  # custom argument to specify Protected Resource
        }
        parameters.update(parameters_overriden)

        if method == METHOD_AUTHORIZATION_HEADER:
            header = self._get_http_authorization_header(parameters)
            response = self.c.get("/oauth/request_token/",
                                  HTTP_AUTHORIZATION=header)
        elif method == METHOD_URL_QUERY:
            response = self.c.get("/oauth/request_token/", parameters)
        elif method == METHOD_POST_REQUEST_BODY:
            body = urllib.parse.urlencode(parameters)
            response = self.c.post(
                "/oauth/request_token/", body, content_type="application/x-www-form-urlencoded")
        else:
            raise NotImplementedError

        if response.status_code != 200:
            print(response)
        self.assertEqual(response.status_code, 200)

        self.assertTrue(
            re.match(r'oauth_token_secret=[^&]+&oauth_token=[^&]+&oauth_callback_confirmed=true', response.content
                     ))


# Path: oauth_provider/models.py
# class Nonce(models.Model):
# class Consumer(models.Model):
# class Token(models.Model):
#     def __unicode__(self):
#     def __unicode__(self):
#     def generate_random_codes(self):
#     def generate_rsa_key(self):
#     def resource(self):
#     def resource(self, value):
#     def __unicode__(self):
#     def to_string(self, only_key=False):
#     def generate_random_codes(self):
#     def get_callback_url(self, args=None):
#     def set_callback(self, callback):
#     def scope_to_list(self):
#     def timestamp_asdatetime(self):
#     def key_partial(self):
#     REQUEST = 1
#     ACCESS = 2
#     TOKEN_TYPES = ((REQUEST, 'Request'), (ACCESS, 'Access'))
# 
# Path: oauth_provider/compat.py
# AUTH_USER_MODEL = settings.AUTH_USER_MODEL
# class UnsafeRedirect(HttpResponse):
#     def __init__(self, target_url, *args, **kwargs):


# Path: oauth_provider/tests/auth.py
import time
import urllib.request, urllib.parse, urllib.error
import re
import oauth2
from urllib.parse import parse_qs, urlparse
from django.test import TestCase, Client
from oauth_provider.models import Scope, Consumer, Token
from oauth_provider.compat import get_user_model

            'oauth_signature': '%s&' % self.CONSUMER_SECRET,
            'oauth_timestamp': str(int(time.time())),
            'oauth_nonce': 'requestnonce',
            'oauth_version': '1.0',
            'oauth_callback': self.callback,
            # 'scope': self.scope.name,  # custom argument to specify Protected Resource
        }
        parameters.update(parameters_overriden)

        if method == METHOD_AUTHORIZATION_HEADER:
            header = self._get_http_authorization_header(parameters)
            response = self.c.get("/oauth/request_token/",
                                  HTTP_AUTHORIZATION=header)
        elif method == METHOD_URL_QUERY:
            response = self.c.get("/oauth/request_token/", parameters)
        elif method == METHOD_POST_REQUEST_BODY:
            body = urllib.parse.urlencode(parameters)
            response = self.c.post(
                "/oauth/request_token/", body, content_type="application/x-www-form-urlencoded")
        else:
            raise NotImplementedError

        if response.status_code != 200:
            print(response)
        self.assertEqual(response.status_code, 200)

        self.assertTrue(
            re.match(r'oauth_token_secret=[^&]+&oauth_token=[^&]+&oauth_callback_confirmed=true', response.content
                     ))


        token = self.request_token = list(Token.objects.all())[-1]