Skip to content

Commit

Permalink
Start on example unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TimSC committed Jan 25, 2018
1 parent d89e2ec commit be85a4b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ You can run tests using the following at the command line:
This code was originally forked from [Leah Culver and Andy Smith's oauth.py code](http://github.com/leah/python-oauth/). Some of the tests come from a [fork by Vic Fryzel](http://github.com/shellsage/python-oauth), while a revamped Request class and more tests were merged in from [Mark Paschal's fork](http://github.com/markpasc/python-oauth). Forked again from [joestump's python-oauth2](https://github.com/joestump/python-oauth2) which seems to be unmaintained. A number of notable differences exist between this code and its forefathers:

* Nearly 100% unit test coverage.
* The <code>DataStore</code> object has been completely ripped out. While creating unit tests for the library I found several substantial bugs with the implementation and confirmed with Andy Smith that it was never fully baked.
* Classes are no longer prefixed with <code>OAuth</code>.
* The <code>Request</code> class now extends from <code>dict</code>.
* The library is likely no longer compatible with Python 2.3.
Expand Down
Empty file added example/__init__.py
Empty file.
9 changes: 7 additions & 2 deletions example/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@
THE SOFTWARE.
"""

from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
import sys
PY3 = sys.version_info >= (3,)

if PY3:
from http.server import BaseHTTPRequestHandler, HTTPServer
else:
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
import urllib
import os
import sys

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__),'..')))

Expand Down
27 changes: 27 additions & 0 deletions tests/test_oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import random
import time
import unittest
import os

import httplib2
import mock
Expand All @@ -42,6 +43,8 @@
from oauth10a._compat import u

import oauth10a as oauth
print(sys.path)
from example import server as exampleserver

_UEMPTY = u('')
_UBLANK = u(' ')
Expand Down Expand Up @@ -1787,6 +1790,30 @@ def test_form_encoded_post_with_charset_in_content_type(self):
headers=headers, body='param1=test1&param2=test2')
self.assertEqual(int(resp['status']), 200)

class TestDataStore(unittest.TestCase):
def test_lookup_consumer(self):
data_store = exampleserver.MockOAuthDataStore()

consumer = data_store.lookup_consumer('key')
self.assertTrue(isinstance(consumer, oauth.Consumer))

consumer2 = data_store.lookup_consumer('invalid-key')
self.assertEqual(consumer2, None)

def test_lookup_token(self):
data_store = exampleserver.MockOAuthDataStore()

request = data_store.lookup_token('request', 'requestkey')
self.assertTrue(isinstance(request, oauth.Token))

request = data_store.lookup_token('request', 'invalid-key')
self.assertEqual(request, None)

access = data_store.lookup_token('access', 'accesskey')
self.assertTrue(isinstance(access, oauth.Token))

access = data_store.lookup_token('access', 'invalid-key')
self.assertEqual(access, None)

if __name__ == "__main__":
import os
Expand Down

0 comments on commit be85a4b

Please sign in to comment.