From cfc9c1ce0c6440506d3a88397c65ad47bdd2d662 Mon Sep 17 00:00:00 2001 From: codl Date: Mon, 27 Nov 2017 14:19:21 +0100 Subject: add timeline tests --- tests/test_timeline.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/test_timeline.py (limited to 'tests/test_timeline.py') diff --git a/tests/test_timeline.py b/tests/test_timeline.py new file mode 100644 index 0000000..0306391 --- /dev/null +++ b/tests/test_timeline.py @@ -0,0 +1,30 @@ +import pytest + +@pytest.mark.vcr() +def test_public_tl_anonymous(mastodon_anonymous, status): + tl = mastodon_anonymous.timeline_public() + assert status['id'] in map(lambda st: st['id'], tl) + # although tempting, we can't do + # assert status in tl + # because the statuses returned in the tl have additional + # pagination-related attributes + +@pytest.mark.vcr() +def test_public_tl(mastodon, status): + tl = mastodon.timeline_public() + print(tl[0]) + assert status['id'] in map(lambda st: st['id'], tl) + +@pytest.mark.vcr() +def test_home_tl(mastodon, status): + tl = mastodon.timeline_home() + assert status['id'] in map(lambda st: st['id'], tl) + +@pytest.mark.vcr() +def test_hashtag_tl(mastodon): + status = mastodon.status_post('#hoot (hashtag toot)') + tl = mastodon.timeline_hashtag('hoot') + try: + assert status['id'] in map(lambda st: st['id'], tl) + finally: + mastodon.status_delete(status['id']) -- cgit v1.2.3 From 304145f4420180b23e0836a6d11fc0cec0e341bd Mon Sep 17 00:00:00 2001 From: codl Date: Mon, 27 Nov 2017 14:35:02 +0100 Subject: rename mastodon and mastodon_anonymous fixtures to api, api_anonymous it was starting to get confusing --- tests/test_timeline.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'tests/test_timeline.py') diff --git a/tests/test_timeline.py b/tests/test_timeline.py index 0306391..492d0c7 100644 --- a/tests/test_timeline.py +++ b/tests/test_timeline.py @@ -1,8 +1,8 @@ import pytest @pytest.mark.vcr() -def test_public_tl_anonymous(mastodon_anonymous, status): - tl = mastodon_anonymous.timeline_public() +def test_public_tl_anonymous(api_anonymous, status): + tl = api_anonymous.timeline_public() assert status['id'] in map(lambda st: st['id'], tl) # although tempting, we can't do # assert status in tl @@ -10,21 +10,21 @@ def test_public_tl_anonymous(mastodon_anonymous, status): # pagination-related attributes @pytest.mark.vcr() -def test_public_tl(mastodon, status): - tl = mastodon.timeline_public() +def test_public_tl(api, status): + tl = api.timeline_public() print(tl[0]) assert status['id'] in map(lambda st: st['id'], tl) @pytest.mark.vcr() -def test_home_tl(mastodon, status): - tl = mastodon.timeline_home() +def test_home_tl(api, status): + tl = api.timeline_home() assert status['id'] in map(lambda st: st['id'], tl) @pytest.mark.vcr() -def test_hashtag_tl(mastodon): - status = mastodon.status_post('#hoot (hashtag toot)') - tl = mastodon.timeline_hashtag('hoot') +def test_hashtag_tl(api): + status = api.status_post('#hoot (hashtag toot)') + tl = api.timeline_hashtag('hoot') try: assert status['id'] in map(lambda st: st['id'], tl) finally: - mastodon.status_delete(status['id']) + api.status_delete(status['id']) -- cgit v1.2.3 From adc75c469774ebbe0bece90a5abed07f6562dfaf Mon Sep 17 00:00:00 2001 From: codl Date: Mon, 27 Nov 2017 14:35:56 +0100 Subject: add a test for accessing a tl that one does not have access to --- tests/test_timeline.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tests/test_timeline.py') diff --git a/tests/test_timeline.py b/tests/test_timeline.py index 492d0c7..eae0e80 100644 --- a/tests/test_timeline.py +++ b/tests/test_timeline.py @@ -28,3 +28,9 @@ def test_hashtag_tl(api): assert status['id'] in map(lambda st: st['id'], tl) finally: api.status_delete(status['id']) + +@pytest.mark.vcr() +def test_home_tl_anonymous_throws(api_anonymous): + from mastodon.Mastodon import MastodonAPIError + with pytest.raises(MastodonAPIError): + tl = api_anonymous.timeline_home() -- cgit v1.2.3 From 96f6e26f597661bfa2cdc7257e740a1d2ff1c9a4 Mon Sep 17 00:00:00 2001 From: codl Date: Mon, 27 Nov 2017 15:26:20 +0100 Subject: update public tl test to also test local tl --- tests/test_timeline.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'tests/test_timeline.py') diff --git a/tests/test_timeline.py b/tests/test_timeline.py index eae0e80..d713fca 100644 --- a/tests/test_timeline.py +++ b/tests/test_timeline.py @@ -11,9 +11,10 @@ def test_public_tl_anonymous(api_anonymous, status): @pytest.mark.vcr() def test_public_tl(api, status): - tl = api.timeline_public() - print(tl[0]) - assert status['id'] in map(lambda st: st['id'], tl) + public = api.timeline_public() + local = api.timeline_local() + assert status['id'] in map(lambda st: st['id'], public) + assert status['id'] in map(lambda st: st['id'], local) @pytest.mark.vcr() def test_home_tl(api, status): -- cgit v1.2.3