aboutsummaryrefslogtreecommitdiff
blob: d3dab8d5b1d693ab9d31481c4133e5099febfc64 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import pytest
import time
import vcr

@pytest.mark.vcr()
def test_filter_create(api):
    with vcr.use_cassette('test_filter_create.yaml', cassette_library_dir='tests/cassettes_pre_4_0_0', record_mode='none'):
        keyword_filter = api.filter_create("anime", ['notifications'], irreversible = False, whole_word = True, expires_in = None)
        try:
            assert keyword_filter
            
            all_filters = api.filters()
            assert keyword_filter in all_filters
            assert keyword_filter.irreversible is False
            assert keyword_filter.whole_word is True
            
            keyword_filter_2 = api.filter(keyword_filter.id)
            assert(keyword_filter == keyword_filter_2)
        finally:
            api.filter_delete(keyword_filter)
    
    
        keyword_filter = api.filter_create("anime", ['notifications'], irreversible = False, whole_word = False, expires_in = None)
        try:
            assert keyword_filter
            assert keyword_filter.irreversible is False
            assert keyword_filter.whole_word is False
            
            all_filters = api.filters()
            assert(keyword_filter in all_filters)
            
            keyword_filter_2 = api.filter(keyword_filter.id)
            assert(keyword_filter == keyword_filter_2)
        finally:
            api.filter_delete(keyword_filter)
        time.sleep(2)
    
@pytest.mark.vcr()
def test_filter_update(api):
    with vcr.use_cassette('test_filter_update.yaml', cassette_library_dir='tests/cassettes_pre_4_0_0', record_mode='none'):
        keyword_filter = api.filter_create("anime", ['notifications'], irreversible = False, whole_word = True, expires_in = None)
        keyword_filter_2 = api.filter_update(keyword_filter, phrase = "japanimation")
        keyword_filter = api.filter(keyword_filter.id)
        assert(keyword_filter.phrase == "japanimation")

@pytest.mark.vcr()
def test_filter_serverside(api, api2):
    with vcr.use_cassette('test_filter_serverside.yaml', cassette_library_dir='tests/cassettes_pre_4_0_0', record_mode='none'):
        api.account_follow(api2.account_verify_credentials())
        keyword_filter_1 = api.filter_create("anime", ['home'], irreversible = True, whole_word = False, expires_in = None)
        keyword_filter_2 = api.filter_create("girugamesh", ['home'], irreversible = True, whole_word = True, expires_in = None)
        keyword_filter_3 = api.filter_create("japanimation", ['notifications'], irreversible = True, whole_word = True, expires_in = None)
        time.sleep(2)
        status_1 = api2.toot("I love animes")
        status_2 = api2.toot("Girugamesh!")
        status_3 = api2.toot("Girugameshnetworking!")
        status_4 = api2.toot("I love japanimation!")
        time.sleep(2)
        tl = api.timeline_home()
        try:
            assert not status_1['id'] in map(lambda st: st['id'], tl)
            assert not status_2['id'] in map(lambda st: st['id'], tl)
            assert status_3['id'] in map(lambda st: st['id'], tl)
            assert status_4['id'] in map(lambda st: st['id'], tl)
        finally:
            api.filter_delete(keyword_filter_1)
            api.filter_delete(keyword_filter_2)
            api.filter_delete(keyword_filter_3)
            api2.status_delete(status_1)
            api2.status_delete(status_2)
            api2.status_delete(status_3)
            api2.status_delete(status_4)
        time.sleep(2)
        
@pytest.mark.vcr()
def test_filter_clientside(api, api2):
    with vcr.use_cassette('test_filter_clientside.yaml', cassette_library_dir='tests/cassettes_pre_4_0_0', record_mode='none'):
        # Make sure no filters are left over from some previous run
        # Unclean, but neccesary
        all_filters = api.filters()
        for mastodon_filter in all_filters:
            api.filter_delete(mastodon_filter)
        
        time.sleep(2)
        api.account_follow(api2.account_verify_credentials())
        keyword_filter_1 = api.filter_create("anime", ['home'], irreversible = False, whole_word = False, expires_in = None)
        keyword_filter_2 = api.filter_create("girugamesh", ['home'], irreversible = False, whole_word = True, expires_in = None)
        keyword_filter_3 = api.filter_create("japanimation", ['notifications'], irreversible = False, whole_word = True, expires_in = None)
        status_1 = api2.toot("I love animes")
        status_2 = api2.toot("Girugamesh!")
        status_3 = api2.toot("Girugameshnetworking!")
        status_4 = api2.toot("I love japanimation!")
        time.sleep(2)
        
        tl = api.timeline_home()
        try:
            assert status_1['id'] in map(lambda st: st['id'], tl)
            assert status_2['id'] in map(lambda st: st['id'], tl)
            assert status_3['id'] in map(lambda st: st['id'], tl)
            assert status_4['id'] in map(lambda st: st['id'], tl)
            
            filtered = api.filters_apply(tl, [keyword_filter_1, keyword_filter_2, keyword_filter_3], 'home')
            assert not status_1['id'] in map(lambda st: st['id'], filtered)
            assert not status_2['id'] in map(lambda st: st['id'], filtered)
            assert status_3['id'] in map(lambda st: st['id'], filtered)
            assert status_4['id'] in map(lambda st: st['id'], filtered)
        finally:
            api.filter_delete(keyword_filter_1)
            api.filter_delete(keyword_filter_2)
            api.filter_delete(keyword_filter_3)
            api2.status_delete(status_1)
            api2.status_delete(status_2)
            api2.status_delete(status_3)
            api2.status_delete(status_4)
Powered by cgit v1.2.3 (git 2.41.0)