diff options
author | codl <[email protected]> | 2017-11-27 16:30:35 +0100 |
---|---|---|
committer | codl <[email protected]> | 2017-11-27 16:30:35 +0100 |
commit | ee687510b0c00c28a6615044a61f0258e199bbac (patch) | |
tree | fa68483ca26fa3e640ed862e83783fe523585c94 /tests | |
parent | 96f6e26f597661bfa2cdc7257e740a1d2ff1c9a4 (diff) | |
download | mastodon.py-ee687510b0c00c28a6615044a61f0258e199bbac.tar.gz |
add tests for create_app
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_create_app.py | 47 |
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 @@ | |||
1 | from mastodon import Mastodon | ||
2 | import pytest | ||
3 | import requests | ||
4 | try: | ||
5 | from mock import Mock | ||
6 | except ImportError: | ||
7 | from unittest.mock import Mock | ||
8 | |||
9 | def 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 | |||
29 | def 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 | |||
39 | def 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 | |||
44 | def 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' | ||