aboutsummaryrefslogtreecommitdiff
blob: d937ed868b9f3abcdef524fcbebe59c76c6fa7e5 (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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import pytest
import time
from datetime import datetime, timedelta
from mastodon import MastodonIllegalArgumentError

@pytest.mark.vcr()
def test_admin_accounts(api2):
    accounts = api2.admin_accounts()
    
    assert accounts
    assert len(accounts) > 0
    
    account_self = api2.account_verify_credentials()
    account_admin = api2.admin_account(account_self)
    
    assert(account_admin)
    assert(account_admin.id == account_self.id)

@pytest.mark.vcr(match_on=['path'])
def test_admin_moderation(api, api2):
    account_initial = api.account_verify_credentials()
    account = account_initial
    
    try: 
        api2.admin_account_moderate(account, "disable")
        account = api2.admin_account(account_initial)
        assert(account.disabled)
        
        account = api2.admin_account_enable(account)
        assert(not account.disabled)
        
        api2.admin_account_moderate(account, "silence")
        account = api2.admin_account(account_initial)
        assert(account.silenced)
        
        account = api2.admin_account_unsilence(account)
        assert(not account.silenced)
        
        api2.admin_account_moderate(account, "sensitive")
        account = api2.admin_account(account_initial)
        image = api.media_post('tests/image.jpg')
        assert image
        status = api.status_post("oh no!", media_ids=image, sensitive=False)
        assert status
        status = api2.status(status)
        assert status.sensitive
        api.status_delete(status)

        account = api2.admin_account_unsensitive(account)
        image = api.media_post('tests/image.jpg')
        assert image
        status = api.status_post("oh no!", media_ids=image, sensitive=False)
        assert status
        status = api2.status(status)
        assert not status.sensitive
        api.status_delete(status)

        api2.admin_account_moderate(account, "suspend")
        account = api2.admin_account(account_initial)
        assert(account.suspended)
        
        account = api2.admin_account_unsuspend(account)
        assert(not account.suspended)
    finally:
        try:
            api2.admin_account_unsuspend(account)
        except:
            pass
        try:
            api2.admin_account_enable(account)
        except:
            pass
        try:
            api2.admin_account_unsilence(account)
        except:
            pass
        try:
            api.status_delete(status)
        except:
            pass

@pytest.mark.vcr()
def test_admin_reports(api, api2, status):
    account = api.account_verify_credentials()
    account2 = api2.account_verify_credentials()
    report = api2.report(account, status, "api crimes")
    assert(report)
    assert(not report.action_taken)
    
    report_list = api2.admin_reports()
    assert(report.id in [x.id for x in report_list])
    
    report = api2.admin_report_resolve(report)
    report_list = api2.admin_reports()
    assert(report.action_taken)
    assert(report.action_taken_by_account.id == account2.id)
    assert(not report.id in [x.id for x in report_list])
    
    report = api2.admin_report_reopen(report)
    report_list = api2.admin_reports()
    assert(not report.action_taken)
    assert(report.id in [x.id for x in report_list])
    
    report = api2.admin_report_assign(report)
    assert(report.assigned_account.id == account2.id)
    
    report = api2.admin_report_unassign(report)
    assert(report.assigned_account is None)
    
    report2 = api2.admin_report(report)
    assert(report2)
    assert(report2.id == report.id)     

@pytest.mark.vcr()
def test_admin_trends(api2):
    assert isinstance(api2.admin_trending_tags(), list)
    assert isinstance(api2.admin_trending_statuses(), list)
    assert isinstance(api2.admin_trending_links(), list)
    assert isinstance(api2.admin_trending_tags(limit=5), list)

@pytest.mark.skip(reason="reject / accept of account requests isn't really testable without modifying instance settings. anyone want to fumble those into the DB setup and write this test, please do.")
def test_admin_accountrequests(api2):
    pass

@pytest.mark.vcr()
def test_admin_domain_blocks(api2):
    block = api2.admin_create_domain_block(domain = "https://chitter.xyz/", public_comment="sicko behaviour", severity="suspend")
    assert isinstance(api2.admin_domain_blocks(), list)
    block2 = api2.admin_domain_blocks(block)
    assert block.severity == "suspend"
    assert block.public_comment == "sicko behaviour"
    assert block.severity == block2.severity
    block3 = api2.admin_update_domain_block(block, severity="silence", private_comment="jk ilu <3")
    assert block3.severity == "silence"
    assert block3.public_comment == "sicko behaviour"
    assert block3.private_comment == "jk ilu <3"
    api2.admin_delete_domain_block(block2)
    assert not block3.id in map(lambda x: x.id, api2.admin_domain_blocks())

@pytest.mark.vcr(match_on=['path'])
def test_admin_stats(api2):
    assert api2.admin_measures(
        datetime(2020, 10, 10) - timedelta(hours=24*5), 
        datetime(2020, 10, 10), 
        active_users=True,
        new_users=True,
        opened_reports=True,
        resolved_reports=True,
        instance_accounts="chitter.xyz",
        instance_media_attachments="chitter.xyz",
        instance_reports="http://chitter.xyz/",
        instance_statuses="chitter.xyz",
        instance_follows="http://chitter.xyz",
        instance_followers="chitter.xyz",
        #tag_accounts=0,
        #tag_uses=0,
        #tag_servers=0,
    )

    assert api2.admin_dimensions(
        datetime(2020, 10, 10) - timedelta(hours=24*5), 
        datetime(2020, 10, 10),
        limit=3,
        languages=True,
        sources=True,
        servers=True,
        space_usage=True,
        #tag_servers=0,
        #tag_languages=0,
        instance_accounts="chitter.xyz",
        instance_languages="https://chitter.xyz"
    )

    api2.admin_retention(
        datetime(2020, 10, 10) - timedelta(days=10), 
        datetime(2020, 10, 10)
    )

    with pytest.raises(MastodonIllegalArgumentError):
        api2.admin_retention(
            datetime(2020, 10, 10) - timedelta(days=10), 
            datetime(2020, 10, 10),
            frequency="dayz"
        )
Powered by cgit v1.2.3 (git 2.41.0)