aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcodl <[email protected]>2017-11-27 16:30:35 +0100
committercodl <[email protected]>2017-11-27 16:30:35 +0100
commitee687510b0c00c28a6615044a61f0258e199bbac (patch)
treefa68483ca26fa3e640ed862e83783fe523585c94
parent96f6e26f597661bfa2cdc7257e740a1d2ff1c9a4 (diff)
downloadmastodon.py-ee687510b0c00c28a6615044a61f0258e199bbac.tar.gz
add tests for create_app
-rw-r--r--setup.py2
-rw-r--r--tests/test_create_app.py47
2 files changed, 48 insertions, 1 deletions
diff --git a/setup.py b/setup.py
index 56b2406..d2ab253 100644
--- a/setup.py
+++ b/setup.py
@@ -5,7 +5,7 @@ setup(name='Mastodon.py',
5 description='Python wrapper for the Mastodon API', 5 description='Python wrapper for the Mastodon API',
6 packages=['mastodon'], 6 packages=['mastodon'],
7 setup_requires=['pytest-runner'], 7 setup_requires=['pytest-runner'],
8 tests_require=['pytest', 'pytest-cov', 'vcrpy', 'pytest-vcr'], 8 tests_require=['pytest', 'pytest-cov', 'vcrpy', 'pytest-vcr', 'pytest-mock'],
9 install_requires=['requests', 'python-dateutil', 'six', 'pytz'], 9 install_requires=['requests', 'python-dateutil', 'six', 'pytz'],
10 url='https://github.com/halcy/Mastodon.py', 10 url='https://github.com/halcy/Mastodon.py',
11 author='Lorenz Diener', 11 author='Lorenz Diener',
diff --git a/tests/test_create_app.py b/tests/test_create_app.py
new file mode 100644
index 0000000..32f5994
--- /dev/null
+++ b/tests/test_create_app.py
@@ -0,0 +1,47 @@
1from mastodon import Mastodon
2import pytest
3import requests
4try:
5 from mock import Mock
6except ImportError:
7 from unittest.mock import Mock
8
9def test_create_app(mocker, to_file=None, redirect_uris=None, website=None):
10 # there is no easy way to delete an anonymously created app so
11 # instead we mock Requests
12 resp = Mock()
13 resp.json = Mock(return_value=dict(
14 client_id='foo',
15 client_secret='bar',
16 ))
17 mocker.patch('requests.post', return_value=resp)
18
19 app = Mastodon.create_app("Mastodon.py test suite",
20 api_base_url="example.com",
21 to_file=to_file,
22 redirect_uris=redirect_uris,
23 website=website
24 )
25
26 assert app == ('foo', 'bar')
27 assert requests.post.called
28
29def test_create_app_to_file(mocker):
30 import tempfile, os
31 (fd, filename) = tempfile.mkstemp(text=True)
32
33 test_create_app(mocker, to_file=filename)
34 with open(fd) as f:
35 assert f.read() == "foo\nbar\n"
36
37 os.remove(filename)
38
39def test_create_app_redirect_uris(mocker):
40 test_create_app(mocker, redirect_uris='http://example.net')
41 kwargs = requests.post.call_args[1]
42 assert kwargs['data']['redirect_uris'] == 'http://example.net'
43
44def test_create_app_website(mocker):
45 test_create_app(mocker, website='http://example.net')
46 kwargs = requests.post.call_args[1]
47 assert kwargs['data']['website'] == 'http://example.net'
Powered by cgit v1.2.3 (git 2.41.0)