add tests for log_in

This commit is contained in:
codl 2017-11-27 20:43:27 +01:00
pare 508d1d2ddd
commit eed6f8f0a4
No se encontró ninguna clave conocida en la base de datos para esta firma
ID de clave GPG: 6CD7C8891ED1233A
S'han modificat 4 arxius amb 153 adicions i 1 eliminacions

Veure arxiu

@ -0,0 +1,27 @@
interactions:
- request:
body: redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&password=mastodonadmin&username=admin%40localhost%3A3000&grant_type=password&client_id=__MASTODON_PY_TEST_ID&client_secret=__MASTODON_PY_TEST_SECRET&scope=read+write+follow
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive]
Content-Length: ['221']
Content-Type: [application/x-www-form-urlencoded]
User-Agent: [python-requests/2.18.4]
method: POST
uri: http://localhost:3000/oauth/token
response:
body: {string: '{"access_token":"__MASTODON_PY_TEST_TOKEN","token_type":"bearer","scope":"read
write follow","created_at":1511814180}'}
headers:
Cache-Control: [no-store]
Content-Type: [application/json; charset=utf-8]
ETag: [W/"f6a22ef91276cdcde8f09c8186d2d41d"]
Pragma: [no-cache]
Transfer-Encoding: [chunked]
Vary: ['Accept-Encoding, Origin']
X-Request-Id: [85cb59f1-b92a-4ff8-8a49-c09bed55eb98]
X-Runtime: ['0.077197']
content-length: ['117']
status: {code: 200, message: OK}
version: 1

Veure arxiu

@ -0,0 +1,31 @@
interactions:
- request:
body: redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&password=hunter2&username=admin%40localhost%3A3000&grant_type=password&client_id=__MASTODON_PY_TEST_ID&client_secret=__MASTODON_PY_TEST_SECRET&scope=read+write+follow
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive]
Content-Length: ['215']
Content-Type: [application/x-www-form-urlencoded]
User-Agent: [python-requests/2.18.4]
method: POST
uri: http://localhost:3000/oauth/token
response:
body: {string: '{"error":"invalid_grant","error_description":"The provided authorization
grant is invalid, expired, revoked, does not match the redirection URI used
in the authorization request, or was issued to another client."}'}
headers:
Cache-Control: [no-store]
Content-Type: [application/json; charset=utf-8]
Pragma: [no-cache]
Transfer-Encoding: [chunked]
Vary: ['Accept-Encoding, Origin']
WWW-Authenticate: ['Bearer realm="Doorkeeper", error="invalid_grant", error_description="The
provided authorization grant is invalid, expired, revoked, does not match
the redirection URI used in the authorization request, or was issued to
another client."']
X-Request-Id: [ece30cd8-c6c1-4bc7-af1a-19bbd997745e]
X-Runtime: ['0.077864']
content-length: ['213']
status: {code: 401, message: Unauthorized}
version: 1

Veure arxiu

@ -0,0 +1,52 @@
interactions:
- request:
body: redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&password=mastodonadmin&username=admin%40localhost%3A3000&grant_type=password&client_id=__MASTODON_PY_TEST_ID&client_secret=__MASTODON_PY_TEST_SECRET&scope=read+write+follow
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive]
Content-Length: ['221']
Content-Type: [application/x-www-form-urlencoded]
User-Agent: [python-requests/2.18.4]
method: POST
uri: http://localhost:3000/oauth/token
response:
body: {string: '{"access_token":"__MASTODON_PY_TEST_TOKEN","token_type":"bearer","scope":"read
write follow","created_at":1511814180}'}
headers:
Cache-Control: [no-store]
Content-Type: [application/json; charset=utf-8]
ETag: [W/"f77400f50590c94b55a861fb6d432464"]
Pragma: [no-cache]
Transfer-Encoding: [chunked]
Vary: ['Accept-Encoding, Origin']
X-Request-Id: [b6168343-dd9e-4a0f-9ec4-69a1de8f879a]
X-Runtime: ['0.080069']
content-length: ['117']
status: {code: 200, message: OK}
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Authorization: [Bearer __MASTODON_PY_TEST_TOKEN]
Connection: [keep-alive]
User-Agent: [python-requests/2.18.4]
method: GET
uri: http://localhost:3000/api/v1/accounts/verify_credentials
response:
body: {string: '{"id":"1","username":"admin","acct":"admin","display_name":"admin","locked":false,"created_at":"2017-08-02T04:15:27.248Z","note":"\u003cp\u003e\u003c/p\u003e","url":"http://localhost:3000/@admin","avatar":"http://localhost:3000/system/accounts/avatars/000/000/001/original/69910b47243ddb47.png","avatar_static":"http://localhost:3000/system/accounts/avatars/000/000/001/original/69910b47243ddb47.png","header":"http://localhost:3000/headers/original/missing.png","header_static":"http://localhost:3000/headers/original/missing.png","followers_count":2,"following_count":1,"statuses_count":16,"source":{"privacy":"public","sensitive":false,"note":""}}'}
headers:
Cache-Control: ['max-age=0, private, must-revalidate']
Content-Type: [application/json; charset=utf-8]
ETag: [W/"622f72a29f8398775e2abff7cd51dbac"]
Transfer-Encoding: [chunked]
Vary: ['Accept-Encoding, Origin']
X-Content-Type-Options: [nosniff]
X-Frame-Options: [SAMEORIGIN]
X-Request-Id: [3852d894-50be-4342-a0e6-f9df2ddf5926]
X-Runtime: ['0.029510']
X-XSS-Protection: [1; mode=block]
content-length: ['650']
status: {code: 200, message: OK}
version: 1

Veure arxiu

@ -1,8 +1,12 @@
import pytest
from mastodon.Mastodon import MastodonIllegalArgumentError
from mastodon import Mastodon
try: try:
from urllib.parse import urlparse, parse_qs from urllib.parse import urlparse, parse_qs
except ImportError: except ImportError:
from urlparse import urlparse, parse_qs from urlparse import urlparse, parse_qs
def test_auth_request_url(api): def test_auth_request_url(api):
url = api.auth_request_url() url = api.auth_request_url()
parse = urlparse(url) parse = urlparse(url)
@ -14,3 +18,41 @@ def test_auth_request_url(api):
assert set(query['scope'][0].split()) == set(('read', 'write', 'follow')) assert set(query['scope'][0].split()) == set(('read', 'write', 'follow'))
@pytest.mark.vcr()
def test_log_in_password(api_anonymous):
token = api_anonymous.log_in(
username='admin@localhost:3000',
password='mastodonadmin')
assert token
@pytest.mark.vcr()
def test_log_in_password_incorrect(api_anonymous):
with pytest.raises(MastodonIllegalArgumentError):
api_anonymous.log_in(
username='admin@localhost:3000',
password='hunter2')
@pytest.mark.vcr()
def test_log_in_password_to_file(api_anonymous, tmpdir):
filepath = tmpdir.join('token')
api_anonymous.log_in(
username='admin@localhost:3000',
password='mastodonadmin',
to_file=str(filepath))
token = filepath.read_text('UTF-8').rstrip()
assert token
api = api_anonymous
api.access_token = token
assert api.account_verify_credentials()
@pytest.mark.skip(reason="Not sure how to test this without setting up selenium or a similar browser automation suite to click on the allow button")
def test_log_in_code(api_anonymous):
pass
@pytest.mark.skip(reason="Not supported by Mastodon 😬 (yet?)")
def test_log_in_refresh(api_anonymous):
pass