diff options
-rw-r--r-- | TODO.md | 2 | ||||
-rw-r--r-- | mastodon/Mastodon.py | 12 | ||||
-rw-r--r-- | tests/cassettes/test_instance_rules.yaml | 60 | ||||
-rw-r--r-- | tests/test_instance.py | 4 |
4 files changed, 74 insertions, 4 deletions
@@ -29,7 +29,7 @@ Refer to mastodon changelog and API docs for details when implementing, add or m | |||
29 | 29 | ||
30 | 3.4.0 | 30 | 3.4.0 |
31 | ----- | 31 | ----- |
32 | * [ ] Add server rules | 32 | * [x] Add server rules |
33 | * [ ] Add POST /api/v1/emails/confirmations to REST API | 33 | * [ ] Add POST /api/v1/emails/confirmations to REST API |
34 | * [ ] Add GET /api/v1/accounts/lookup to REST API | 34 | * [ ] Add GET /api/v1/accounts/lookup to REST API |
35 | * [ ] Add policy param to POST /api/v1/push/subscriptions in REST API | 35 | * [ ] Add policy param to POST /api/v1/push/subscriptions in REST API |
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 4462253..14cf174 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py | |||
@@ -774,8 +774,7 @@ class Mastodon: | |||
774 | """ | 774 | """ |
775 | Basic health check. Returns True if healthy, False if not. | 775 | Basic health check. Returns True if healthy, False if not. |
776 | """ | 776 | """ |
777 | status = self.__api_request( | 777 | status = self.__api_request('GET', '/health', parse=False).decode("utf-8") |
778 | 'GET', '/health', parse=False).decode("utf-8") | ||
779 | return status in ["OK", "success"] | 778 | return status in ["OK", "success"] |
780 | 779 | ||
781 | @api_version("3.0.0", "3.0.0", "3.0.0") | 780 | @api_version("3.0.0", "3.0.0", "3.0.0") |
@@ -807,6 +806,15 @@ class Mastodon: | |||
807 | parse = urlparse(schema_url) | 806 | parse = urlparse(schema_url) |
808 | return self.__api_request('GET', parse.path + parse.params + parse.query + parse.fragment) | 807 | return self.__api_request('GET', parse.path + parse.params + parse.query + parse.fragment) |
809 | 808 | ||
809 | @api_version("3.4.0", "3.4.0", __DICT_VERSION_INSTANCE) | ||
810 | def instance_rules(self): | ||
811 | """ | ||
812 | Retrieve instance rules. | ||
813 | |||
814 | Returns a list of `id` + `text` dicts, same as the `rules` field in the `instance dicts`_. | ||
815 | """ | ||
816 | return self.__api_request('GET', '/api/v1/instance/rules') | ||
817 | |||
810 | ### | 818 | ### |
811 | # Reading data: Timelines | 819 | # Reading data: Timelines |
812 | ## | 820 | ## |
diff --git a/tests/cassettes/test_instance_rules.yaml b/tests/cassettes/test_instance_rules.yaml new file mode 100644 index 0000000..6e144b6 --- /dev/null +++ b/tests/cassettes/test_instance_rules.yaml | |||
@@ -0,0 +1,60 @@ | |||
1 | interactions: | ||
2 | - request: | ||
3 | body: null | ||
4 | headers: | ||
5 | Accept: | ||
6 | - '*/*' | ||
7 | Accept-Encoding: | ||
8 | - gzip, deflate | ||
9 | Authorization: | ||
10 | - Bearer __MASTODON_PY_TEST_ACCESS_TOKEN | ||
11 | Connection: | ||
12 | - keep-alive | ||
13 | User-Agent: | ||
14 | - tests/v311 | ||
15 | method: GET | ||
16 | uri: http://localhost:3000/api/v1/instance/rules | ||
17 | response: | ||
18 | body: | ||
19 | string: '[]' | ||
20 | headers: | ||
21 | Cache-Control: | ||
22 | - no-store | ||
23 | Content-Security-Policy: | ||
24 | - 'base-uri ''none''; default-src ''none''; frame-ancestors ''none''; font-src | ||
25 | ''self'' http://localhost:3000; img-src ''self'' https: data: blob: http://localhost:3000; | ||
26 | style-src ''self'' http://localhost:3000 ''nonce-VfLfKge8CLCQB9dJyA6/cA==''; | ||
27 | media-src ''self'' https: data: http://localhost:3000; frame-src ''self'' | ||
28 | https:; manifest-src ''self'' http://localhost:3000; connect-src ''self'' | ||
29 | data: blob: http://localhost:3000 http://localhost:3000 ws://localhost:4000 | ||
30 | ws://localhost:3035 http://localhost:3035; script-src ''self'' ''unsafe-inline'' | ||
31 | ''unsafe-eval'' http://localhost:3000; child-src ''self'' blob: http://localhost:3000; | ||
32 | worker-src ''self'' blob: http://localhost:3000' | ||
33 | Content-Type: | ||
34 | - application/json; charset=utf-8 | ||
35 | ETag: | ||
36 | - W/"4f53cda18c2baa0c0354bb5f9a3ecbe5" | ||
37 | Referrer-Policy: | ||
38 | - strict-origin-when-cross-origin | ||
39 | Transfer-Encoding: | ||
40 | - chunked | ||
41 | Vary: | ||
42 | - Accept, Origin | ||
43 | X-Content-Type-Options: | ||
44 | - nosniff | ||
45 | X-Download-Options: | ||
46 | - noopen | ||
47 | X-Frame-Options: | ||
48 | - SAMEORIGIN | ||
49 | X-Permitted-Cross-Domain-Policies: | ||
50 | - none | ||
51 | X-Request-Id: | ||
52 | - 48fd3107-1ed2-4db1-8ae6-a62ac4897b98 | ||
53 | X-Runtime: | ||
54 | - '0.036615' | ||
55 | X-XSS-Protection: | ||
56 | - 1; mode=block | ||
57 | status: | ||
58 | code: 200 | ||
59 | message: OK | ||
60 | version: 1 | ||
diff --git a/tests/test_instance.py b/tests/test_instance.py index 3b42c3e..5f451c7 100644 --- a/tests/test_instance.py +++ b/tests/test_instance.py | |||
@@ -72,4 +72,6 @@ def test_directory(api): | |||
72 | assert isinstance(directory, list) | 72 | assert isinstance(directory, list) |
73 | assert len(directory) > 0 | 73 | assert len(directory) > 0 |
74 | 74 | ||
75 | 75 | @pytest.mark.vcr() | |
76 | def test_instance_rules(api): | ||
77 | assert isinstance(api.instance_rules(), list) | ||