From e2be8825bdea0079a0e61a46a878aff1b981aabb Mon Sep 17 00:00:00 2001 From: Kyle Mahan Date: Fri, 18 Mar 2016 12:26:28 -0700 Subject: [PATCH] add a simple unit test and tox.ini --- tests/__init__.py | 0 tests/test_micropub_client.py | 52 +++++++++++++++++++++++++++++++++++ tox.ini | 6 ++++ 3 files changed, 58 insertions(+) create mode 100644 tests/__init__.py create mode 100644 tests/test_micropub_client.py create mode 100644 tox.ini diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_micropub_client.py b/tests/test_micropub_client.py new file mode 100644 index 0000000..d432e4b --- /dev/null +++ b/tests/test_micropub_client.py @@ -0,0 +1,52 @@ +# coding=utf-8 +from __future__ import unicode_literals, print_function + +import collections +import json +import os +import unittest +import requests + +import flask_micropub + +try: + from unittest import mock +except: + import mock + + +class MicropubClientTest(unittest.TestCase): + + def setUp(self): + self.client = flask_micropub.MicropubClient() + + @mock.patch('requests.get') + def test_discover_endpoints_from_http_header(self, get_method): + r = requests.Response() + r.headers['Link'] = ';rel=authorization_endpoint, ;rel=token_endpoint, ;rel=micropub' + r.status_code = 200 + get_method.return_value = r + result = self.client._discover_endpoints('http://foo.bar/') + get_method.assert_called_once_with('http://foo.bar/') + self.assertEqual(('http://foo.bar/auth', 'http://baz.bux/token', 'http://do.re/micropub'), result) + + @mock.patch('requests.get') + def test_discover_endpoints_from_html(self, get_method): + r = requests.Response() + r._content = """ + + + + + + + + + + +""".encode('utf-8') + r.status_code = 200 + get_method.return_value = r + result = self.client._discover_endpoints('http://foo.bar/') + get_method.assert_called_once_with('http://foo.bar/') + self.assertEqual(('http://foo.bar/auth', 'http://baz.bux/token', 'http://do.re/micropub'), result) diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..be4714f --- /dev/null +++ b/tox.ini @@ -0,0 +1,6 @@ +# content of: tox.ini , put in same dir as setup.py +[tox] +envlist = py26,py27,py33,py34,py35 +[testenv] +deps=mock +commands=python -m unittest discover