Skip to content
Permalink
Browse files

test directories. fix #26

  • Loading branch information...
lepture committed Jul 10, 2013
1 parent 23ef4ea commit 0f747cf3511aa9d98750cd362613778f6a629bc1
@@ -0,0 +1,62 @@
# coding: utf-8

import os
import sys
import tempfile
import unittest

if sys.version_info[0] == 3:
python_version = 3
string_type = str
else:
python_version = 2
string_type = unicode


class BaseSuite(unittest.TestCase):
def setUp(self):
app = self.create_app()

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

self.setup_app(app)

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

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

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

@property
def database(self):
raise NotImplementedError

def create_app(self):
raise NotImplementedError

def setup_app(self, app):
raise NotImplementedError


def to_unicode(text):
if not isinstance(text, string_type):
text = text.decode('utf-8')
return text


def to_bytes(text):
if isinstance(text, string_type):
text = text.encode('utf-8')
return text
No changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -1,56 +1,44 @@
# coding: utf-8

import os
import time
import tempfile
import unittest
from nose.tools import raises
from flask import Flask
from flask_oauthlib.client import OAuth, OAuthException
from .oauth1_server import create_server, db
from .oauth1_client import create_client
from .server import create_server, db
from .client import create_client
from .._base import BaseSuite
try:
from urlparse import urlparse
except ImportError:
from urllib.parse import urlparse


class BaseSuite(unittest.TestCase):
def setUp(self):
class OAuthSuite(BaseSuite):
@property
def database(self):
return db

def create_app(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),
'OAUTH1_PROVIDER_REALMS': ['email', 'address'],
'SQLALCHEMY_DATABASE_URI': 'sqlite:///%s' % self.db_file
}
app.config.update(config)

app = create_server(app)
app = self.create_client(app)

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

def tearDown(self):
db.session.remove()
db.drop_all()
def setup_app(self, app):
self.create_server(app)
self.create_client(app)

os.close(self.db_fd)
os.unlink(self.db_file)
def create_server(self, app):
create_server(app)
return app

def create_client(self, app):
create_client(app)
return app


class TestWebAuth(BaseSuite):
class TestWebAuth(OAuthSuite):
def test_full_flow(self):
rv = self.client.get('/login')
assert 'oauth_token' in rv.location
@@ -126,7 +114,7 @@ def test_invalid_request_token(self):
}


class TestInvalid(BaseSuite):
class TestInvalid(OAuthSuite):
@raises(OAuthException)
def test_request(self):
rv = self.client.get('/login')
No changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,9 @@
{% extends "layout.html" %}

{% block body %}
<h2>Allow?</h2>
<form action="" method="post">
<button name="confirm" value="yes">Confirm</button>
<button name="confirm" value="no">Cancel</button>
</form>
{% endblock %}
@@ -0,0 +1 @@
{% extends "layout.html" %}
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Auth Provider</title>
</head>
<body>
{% if g.user %}
{{g.user.username}}
{% endif %}
{% block body %}{% endblock %}
</body>
</html>
@@ -1,52 +1,41 @@
# coding: utf-8

import os
import tempfile
import unittest
import json
from flask import Flask
from .oauth2_server import create_server, db, enable_log
from .oauth2_client import create_client
from .server import create_server, db
from .client import create_client
from .._base import BaseSuite
try:
from urlparse import urlparse
except ImportError:
from urllib.parse import urlparse


class BaseSuite(unittest.TestCase):
def setUp(self):
class OAuthSuite(BaseSuite):
@property
def database(self):
return db

def create_app(self):
app = Flask(__name__)
app.debug = True
app.testing = True
app.secret_key = 'development'

self.db_fd, self.db_file = tempfile.mkstemp()
config = {
'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)
def setup_app(self, app):
create_server(app)
create_client(app)
return app


authorize_url = (
'/oauth/authorize?response_type=code&client_id=dev'
'&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2Fauthorized&scope=email'
)

class TestWebAuth(BaseSuite):

class TestWebAuth(OAuthSuite):
def test_login(self):
rv = self.client.get('/login')
assert 'response_type=code' in rv.location
@@ -125,7 +114,7 @@ def test_invalid_response_type(self):
assert 'error' in rv.data


class TestPasswordAuth(BaseSuite):
class TestPasswordAuth(OAuthSuite):
def test_get_access_token(self):
auth_code = 'confidential:confidential'.encode('base64').strip()
url = ('/oauth/token?grant_type=password&state=foo'
@@ -137,7 +126,7 @@ def test_get_access_token(self):
assert 'state' in rv.data


class TestRefreshToken(BaseSuite):
class TestRefreshToken(OAuthSuite):
def test_refresh_token_in_password_grant(self):
auth_code = 'confidential:confidential'.encode('base64').strip()
url = ('/oauth/token?grant_type=password'
@@ -160,7 +149,7 @@ def test_refresh_token_in_password_grant(self):
assert 'access_token' in rv.data


class TestCredentialAuth(BaseSuite):
class TestCredentialAuth(OAuthSuite):
def test_get_access_token(self):
auth_code = 'confidential:confidential'.encode('base64').strip()
url = ('/oauth/token?grant_type=client_credentials'
@@ -2,7 +2,7 @@
from nose.tools import raises
from flask_oauthlib.client import encode_request_data, add_query
from flask_oauthlib.client import OAuthRemoteApp, OAuth
from .oauth2_client import create_client
from .oauth2.client import create_client


def test_encode_request_data():

0 comments on commit 0f747cf

Please sign in to comment.
You can’t perform that action at this time.