add tests for account methods

This commit is contained in:
codl 2017-11-30 00:56:35 +01:00
pare 7464315be7
commit f9a52029fc
No se encontró ninguna clave conocida en la base de datos para esta firma
ID de clave GPG: 6CD7C8891ED1233A
S'han modificat 10 arxius amb 416 adicions i 0 eliminacions

Veure arxiu

@ -0,0 +1,28 @@
interactions:
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Authorization: [Bearer __MASTODON_PY_TEST_ACCESS_TOKEN]
Connection: [keep-alive]
User-Agent: [python-requests/2.18.4]
method: GET
uri: http://localhost:3000/api/v1/accounts/1
response:
body: {string: '{"id":"1","username":"admin","acct":"admin","display_name":"codltest","locked":false,"created_at":"2017-07-01T17:09:15.621Z","note":"\u003cp\u003ehello
:)\u003c/p\u003e","url":"http://localhost:3000/@admin","avatar":"http://localhost:3000/system/accounts/avatars/000/000/001/original/99b4c443463de195.png","avatar_static":"http://localhost:3000/system/accounts/avatars/000/000/001/original/99b4c443463de195.png","header":"http://localhost:3000/headers/original/missing.png","header_static":"http://localhost:3000/headers/original/missing.png","followers_count":1,"following_count":0,"statuses_count":50}'}
headers:
Cache-Control: ['max-age=0, private, must-revalidate']
Content-Type: [application/json; charset=utf-8]
ETag: [W/"e9bdeb1ccc287b8c6a125f2e31149bc2"]
Transfer-Encoding: [chunked]
Vary: ['Accept-Encoding, Origin']
X-Content-Type-Options: [nosniff]
X-Frame-Options: [SAMEORIGIN]
X-Request-Id: [8131bec0-f48e-4786-8ead-21a2c0e5cf98]
X-Runtime: ['0.047639']
X-XSS-Protection: [1; mode=block]
content-length: ['603']
status: {code: 200, message: OK}
version: 1

Veure arxiu

@ -0,0 +1,54 @@
interactions:
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Authorization: [Bearer __MASTODON_PY_TEST_ACCESS_TOKEN]
Connection: [keep-alive]
Content-Length: ['0']
User-Agent: [python-requests/2.18.4]
method: POST
uri: http://localhost:3000/api/v1/accounts/1/block
response:
body: {string: '{"id":"1","following":false,"followed_by":false,"blocking":true,"muting":false,"requested":false,"domain_blocking":false}'}
headers:
Cache-Control: ['max-age=0, private, must-revalidate']
Content-Type: [application/json; charset=utf-8]
ETag: [W/"196f57518cd8daf5bce592dcd6f9e402"]
Transfer-Encoding: [chunked]
Vary: ['Accept-Encoding, Origin']
X-Content-Type-Options: [nosniff]
X-Frame-Options: [SAMEORIGIN]
X-Request-Id: [d2ead4fd-9233-404a-ac03-9cdab005b409]
X-Runtime: ['0.076978']
X-XSS-Protection: [1; mode=block]
content-length: ['121']
status: {code: 200, message: OK}
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Authorization: [Bearer __MASTODON_PY_TEST_ACCESS_TOKEN]
Connection: [keep-alive]
Content-Length: ['0']
User-Agent: [python-requests/2.18.4]
method: POST
uri: http://localhost:3000/api/v1/accounts/1/unblock
response:
body: {string: '{"id":"1","following":false,"followed_by":false,"blocking":false,"muting":false,"requested":false,"domain_blocking":false}'}
headers:
Cache-Control: ['max-age=0, private, must-revalidate']
Content-Type: [application/json; charset=utf-8]
ETag: [W/"05e46d89ddd4fee200b318b7343c32b4"]
Transfer-Encoding: [chunked]
Vary: ['Accept-Encoding, Origin']
X-Content-Type-Options: [nosniff]
X-Frame-Options: [SAMEORIGIN]
X-Request-Id: [0bfca911-f078-42b1-a476-00f9c6d3b13d]
X-Runtime: ['0.041180']
X-XSS-Protection: [1; mode=block]
content-length: ['122']
status: {code: 200, message: OK}
version: 1

Veure arxiu

@ -0,0 +1,54 @@
interactions:
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Authorization: [Bearer __MASTODON_PY_TEST_ACCESS_TOKEN]
Connection: [keep-alive]
Content-Length: ['0']
User-Agent: [python-requests/2.18.4]
method: POST
uri: http://localhost:3000/api/v1/accounts/1/follow
response:
body: {string: '{"id":"1","following":true,"followed_by":false,"blocking":false,"muting":false,"requested":false,"domain_blocking":false}'}
headers:
Cache-Control: ['max-age=0, private, must-revalidate']
Content-Type: [application/json; charset=utf-8]
ETag: [W/"54ee9a8f552ca13f2eb48913ddfa66b6"]
Transfer-Encoding: [chunked]
Vary: ['Accept-Encoding, Origin']
X-Content-Type-Options: [nosniff]
X-Frame-Options: [SAMEORIGIN]
X-Request-Id: [74b7ca00-cec6-4673-a6f7-00e340e5299f]
X-Runtime: ['0.155400']
X-XSS-Protection: [1; mode=block]
content-length: ['121']
status: {code: 200, message: OK}
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Authorization: [Bearer __MASTODON_PY_TEST_ACCESS_TOKEN]
Connection: [keep-alive]
Content-Length: ['0']
User-Agent: [python-requests/2.18.4]
method: POST
uri: http://localhost:3000/api/v1/accounts/1/unfollow
response:
body: {string: '{"id":"1","following":false,"followed_by":false,"blocking":false,"muting":false,"requested":false,"domain_blocking":false}'}
headers:
Cache-Control: ['max-age=0, private, must-revalidate']
Content-Type: [application/json; charset=utf-8]
ETag: [W/"0f18b5b45430f24d88fd4f352cdf3e0d"]
Transfer-Encoding: [chunked]
Vary: ['Accept-Encoding, Origin']
X-Content-Type-Options: [nosniff]
X-Frame-Options: [SAMEORIGIN]
X-Request-Id: [75185a80-e13e-4620-89c1-d368db67b22c]
X-Runtime: ['0.094960']
X-XSS-Protection: [1; mode=block]
content-length: ['122']
status: {code: 200, message: OK}
version: 1

Veure arxiu

@ -0,0 +1,28 @@
interactions:
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Authorization: [Bearer __MASTODON_PY_TEST_ACCESS_TOKEN]
Connection: [keep-alive]
User-Agent: [python-requests/2.18.4]
method: GET
uri: http://localhost:3000/api/v1/accounts/1/followers
response:
body: {string: '[{"id":"3","username":"codl","acct":"codl","display_name":"","locked":false,"created_at":"2017-11-14T11:40:31.289Z","note":"\u003cp\u003e\u003c/p\u003e","url":"http://localhost:3000/@codl","avatar":"http://localhost:3000/avatars/original/missing.png","avatar_static":"http://localhost:3000/avatars/original/missing.png","header":"http://localhost:3000/headers/original/missing.png","header_static":"http://localhost:3000/headers/original/missing.png","followers_count":0,"following_count":1,"statuses_count":3}]'}
headers:
Cache-Control: ['max-age=0, private, must-revalidate']
Content-Type: [application/json; charset=utf-8]
ETag: [W/"0fbc972d9b8f61435fef831aa4a846d3"]
Link: ['<http://localhost:3000/api/v1/accounts/1/followers?since_id=1>; rel="prev"']
Transfer-Encoding: [chunked]
Vary: ['Accept-Encoding, Origin']
X-Content-Type-Options: [nosniff]
X-Frame-Options: [SAMEORIGIN]
X-Request-Id: [c83243ad-be5c-4b16-acfc-5a18e80b7a88]
X-Runtime: ['0.039199']
X-XSS-Protection: [1; mode=block]
content-length: ['511']
status: {code: 200, message: OK}
version: 1

Veure arxiu

@ -0,0 +1,27 @@
interactions:
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Authorization: [Bearer __MASTODON_PY_TEST_ACCESS_TOKEN]
Connection: [keep-alive]
User-Agent: [python-requests/2.18.4]
method: GET
uri: http://localhost:3000/api/v1/accounts/1/following
response:
body: {string: '[]'}
headers:
Cache-Control: ['max-age=0, private, must-revalidate']
Content-Type: [application/json; charset=utf-8]
ETag: [W/"c52068b0fe39c86669dce2267d90925e"]
Transfer-Encoding: [chunked]
Vary: ['Accept-Encoding, Origin']
X-Content-Type-Options: [nosniff]
X-Frame-Options: [SAMEORIGIN]
X-Request-Id: [9df6a517-2e2e-499b-b0a5-0b1d6cea9f1a]
X-Runtime: ['0.037545']
X-XSS-Protection: [1; mode=block]
content-length: ['2']
status: {code: 200, message: OK}
version: 1

Veure arxiu

@ -0,0 +1,54 @@
interactions:
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Authorization: [Bearer __MASTODON_PY_TEST_ACCESS_TOKEN]
Connection: [keep-alive]
Content-Length: ['0']
User-Agent: [python-requests/2.18.4]
method: POST
uri: http://localhost:3000/api/v1/accounts/1/mute
response:
body: {string: '{"id":"1","following":false,"followed_by":false,"blocking":false,"muting":true,"requested":false,"domain_blocking":false}'}
headers:
Cache-Control: ['max-age=0, private, must-revalidate']
Content-Type: [application/json; charset=utf-8]
ETag: [W/"29202955a4020108196abe86f9cd0179"]
Transfer-Encoding: [chunked]
Vary: ['Accept-Encoding, Origin']
X-Content-Type-Options: [nosniff]
X-Frame-Options: [SAMEORIGIN]
X-Request-Id: [45f28867-e291-4323-85fb-3f7a6f787a84]
X-Runtime: ['0.056882']
X-XSS-Protection: [1; mode=block]
content-length: ['121']
status: {code: 200, message: OK}
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Authorization: [Bearer __MASTODON_PY_TEST_ACCESS_TOKEN]
Connection: [keep-alive]
Content-Length: ['0']
User-Agent: [python-requests/2.18.4]
method: POST
uri: http://localhost:3000/api/v1/accounts/1/unmute
response:
body: {string: '{"id":"1","following":false,"followed_by":false,"blocking":false,"muting":false,"requested":false,"domain_blocking":false}'}
headers:
Cache-Control: ['max-age=0, private, must-revalidate']
Content-Type: [application/json; charset=utf-8]
ETag: [W/"05e46d89ddd4fee200b318b7343c32b4"]
Transfer-Encoding: [chunked]
Vary: ['Accept-Encoding, Origin']
X-Content-Type-Options: [nosniff]
X-Frame-Options: [SAMEORIGIN]
X-Request-Id: [2e3c386a-0ec4-46d6-9473-e47d242f91ce]
X-Runtime: ['0.041201']
X-XSS-Protection: [1; mode=block]
content-length: ['122']
status: {code: 200, message: OK}
version: 1

Veure arxiu

@ -0,0 +1,27 @@
interactions:
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Authorization: [Bearer __MASTODON_PY_TEST_ACCESS_TOKEN]
Connection: [keep-alive]
User-Agent: [python-requests/2.18.4]
method: GET
uri: http://localhost:3000/api/v1/accounts/relationships?id=1
response:
body: {string: '[{"id":"1","following":false,"followed_by":false,"blocking":false,"muting":false,"requested":false,"domain_blocking":false}]'}
headers:
Cache-Control: ['max-age=0, private, must-revalidate']
Content-Type: [application/json; charset=utf-8]
ETag: [W/"62305384b0a973eadd31ca6bca1133e9"]
Transfer-Encoding: [chunked]
Vary: ['Accept-Encoding, Origin']
X-Content-Type-Options: [nosniff]
X-Frame-Options: [SAMEORIGIN]
X-Request-Id: [825f3691-e858-4048-9dda-065917a2798a]
X-Runtime: ['0.031853']
X-XSS-Protection: [1; mode=block]
content-length: ['124']
status: {code: 200, message: OK}
version: 1

Veure arxiu

@ -0,0 +1,28 @@
interactions:
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Authorization: [Bearer __MASTODON_PY_TEST_ACCESS_TOKEN]
Connection: [keep-alive]
User-Agent: [python-requests/2.18.4]
method: GET
uri: http://localhost:3000/api/v1/accounts/search?q=admin
response:
body: {string: '[{"id":"1","username":"admin","acct":"admin","display_name":"codltest","locked":false,"created_at":"2017-07-01T17:09:15.621Z","note":"\u003cp\u003ehello
:)\u003c/p\u003e","url":"http://localhost:3000/@admin","avatar":"http://localhost:3000/system/accounts/avatars/000/000/001/original/99b4c443463de195.png","avatar_static":"http://localhost:3000/system/accounts/avatars/000/000/001/original/99b4c443463de195.png","header":"http://localhost:3000/headers/original/missing.png","header_static":"http://localhost:3000/headers/original/missing.png","followers_count":1,"following_count":0,"statuses_count":50}]'}
headers:
Cache-Control: ['max-age=0, private, must-revalidate']
Content-Type: [application/json; charset=utf-8]
ETag: [W/"f257564844f554885596d31ac16d0607"]
Transfer-Encoding: [chunked]
Vary: ['Accept-Encoding, Origin']
X-Content-Type-Options: [nosniff]
X-Frame-Options: [SAMEORIGIN]
X-Request-Id: [efde9755-3e09-4e66-89d3-ad28026d0a0a]
X-Runtime: ['0.047304']
X-XSS-Protection: [1; mode=block]
content-length: ['605']
status: {code: 200, message: OK}
version: 1

Las diferiencias del archivo han sido suprimidas porque una o mas lineas son muy largas

84
tests/test_account.py Normal file
Veure arxiu

@ -0,0 +1,84 @@
import pytest
from mastodon.Mastodon import MastodonAPIError
@pytest.mark.vcr()
def test_account(api):
account = api.account(1)
assert account
@pytest.mark.vcr()
def test_account_following(api):
following = api.account_following(1)
assert isinstance(following, list)
@pytest.mark.vcr()
def test_account_followers(api):
followers = api.account_followers(1)
assert isinstance(followers, list)
@pytest.mark.vcr()
def test_account_relationships(api):
relationships = api.account_relationships(1)
assert isinstance(relationships, list)
assert len(relationships) == 1
@pytest.mark.vcr()
def test_account_search(api):
results = api.account_search('admin')
assert isinstance(results, list)
@pytest.mark.vcr()
def test_account_follow_unfollow(api):
relationship = api.account_follow(1)
try:
assert relationship
assert relationship['following']
finally:
relationship = api.account_unfollow(1)
assert relationship
assert not relationship['following']
@pytest.mark.vcr()
def test_account_block_unblock(api):
relationship = api.account_block(1)
try:
assert relationship
assert relationship['blocking']
finally:
relationship = api.account_unblock(1)
assert relationship
assert not relationship['blocking']
@pytest.mark.vcr()
def test_account_mute_unmute(api):
relationship = api.account_mute(1)
try:
assert relationship
assert relationship['muting']
finally:
relationship = api.account_unmute(1)
assert relationship
assert not relationship['muting']
@pytest.mark.vcr()
def test_account_update_credentials(api):
import base64
with open('tests/image.jpg', 'rb') as f:
image = f.read()
b64_image = base64.b64encode(image)
data_uri = b'data:image/jpeg;base64,' + b64_image
account = api.account_update_credentials(
display_name='John Lennon',
note='I walk funny',
avatar = data_uri,
header = data_uri)
assert account