# coding: utf-8

import os
import tempfile
import unittest
from flask import Flask
from .oauth1_server import create_server, db
from .oauth1_client import create_client


class BaseSuite(unittest.TestCase):
    def setUp(self):
        app = Flask(__name__)
        app.debug = True
        app.testing = True
        app.secret_key = 'development'

        self.db_fd, self.db_file = tempfile.mkstemp()
        config = {
            'OAUTH1_PROVIDER_ENFORCE_SSL': False,
            'OAUTH1_PROVIDER_KEY_LENGTH': (3, 30),
            'SQLALCHEMY_DATABASE_URI': 'sqlite:///%s' % self.db_file
        }
        app.config.update(config)

        app = create_server(app)
        app = create_client(app)

        self.app = app
        self.client = app.test_client()
        return app

    def tearDown(self):
        db.session.remove()
        db.drop_all()

        os.close(self.db_fd)
        os.unlink(self.db_file)


class TestWebAuth(BaseSuite):
    def test_login(self):
        rv = self.client.get('/login')
        assert 'oauth_token' in rv.location

@@ -52,16 +52,46 @@
 nittest%0A
+from urlparse import urlparse%0A
 from fla
@@ -992,20 +992,27 @@
 ef test_
-logi
+access_toke
 n(self):
@@ -1095,8 +1095,488 @@
 ocation%0A
+%0A        auth_url = clean_url(rv.location)%0A        rv = self.client.get(auth_url)%0A        assert '%3C/form%3E' in rv.data%0A%0A        rv = self.client.post(auth_url, data=%7B%0A            'confirm': 'yes'%0A        %7D)%0A        assert 'oauth_token' in rv.location%0A%0A        token_url = clean_url(rv.location)%0A        rv = self.client.get(token_url)%0A        assert 'oauth_token_secret' in rv.data%0A%0A%0Adef clean_url(location):%0A    ret = urlparse(location)%0A    return '%25s?%25s' %25 (ret.path, ret.query)%0A

test case for get access token