aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_create_app.py47
1 files changed, 47 insertions, 0 deletions
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)