add tests for create_app

This commit is contained in:
codl 2017-11-27 16:30:35 +01:00
pare 96f6e26f59
commit ee687510b0
No se encontró ninguna clave conocida en la base de datos para esta firma
ID de clave GPG: 6CD7C8891ED1233A
S'han modificat 2 arxius amb 48 adicions i 1 eliminacions

Veure arxiu

@ -5,7 +5,7 @@ setup(name='Mastodon.py',
description='Python wrapper for the Mastodon API', description='Python wrapper for the Mastodon API',
packages=['mastodon'], packages=['mastodon'],
setup_requires=['pytest-runner'], setup_requires=['pytest-runner'],
tests_require=['pytest', 'pytest-cov', 'vcrpy', 'pytest-vcr'], tests_require=['pytest', 'pytest-cov', 'vcrpy', 'pytest-vcr', 'pytest-mock'],
install_requires=['requests', 'python-dateutil', 'six', 'pytz'], install_requires=['requests', 'python-dateutil', 'six', 'pytz'],
url='https://github.com/halcy/Mastodon.py', url='https://github.com/halcy/Mastodon.py',
author='Lorenz Diener', author='Lorenz Diener',

47
tests/test_create_app.py Normal file
Veure arxiu

@ -0,0 +1,47 @@
from mastodon import Mastodon
import pytest
import requests
try:
from mock import Mock
except ImportError:
from unittest.mock import Mock
def test_create_app(mocker, to_file=None, redirect_uris=None, website=None):
# there is no easy way to delete an anonymously created app so
# instead we mock Requests
resp = Mock()
resp.json = Mock(return_value=dict(
client_id='foo',
client_secret='bar',
))
mocker.patch('requests.post', return_value=resp)
app = Mastodon.create_app("Mastodon.py test suite",
api_base_url="example.com",
to_file=to_file,
redirect_uris=redirect_uris,
website=website
)
assert app == ('foo', 'bar')
assert requests.post.called
def test_create_app_to_file(mocker):
import tempfile, os
(fd, filename) = tempfile.mkstemp(text=True)
test_create_app(mocker, to_file=filename)
with open(fd) as f:
assert f.read() == "foo\nbar\n"
os.remove(filename)
def test_create_app_redirect_uris(mocker):
test_create_app(mocker, redirect_uris='http://example.net')
kwargs = requests.post.call_args[1]
assert kwargs['data']['redirect_uris'] == 'http://example.net'
def test_create_app_website(mocker):
test_create_app(mocker, website='http://example.net')
kwargs = requests.post.call_args[1]
assert kwargs['data']['website'] == 'http://example.net'