aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/index.rst1
-rw-r--r--mastodon/Mastodon.py30
-rw-r--r--tests/cassettes/test_nodeinfo.yaml81
-rw-r--r--tests/test_instance.py7
4 files changed, 118 insertions, 1 deletions
diff --git a/docs/index.rst b/docs/index.rst
index f65fe1e..0ec0f75 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -844,6 +844,7 @@ current instance.
844.. automethod:: Mastodon.instance_activity 844.. automethod:: Mastodon.instance_activity
845.. automethod:: Mastodon.instance_peers 845.. automethod:: Mastodon.instance_peers
846.. automethod:: Mastodon.instance_health 846.. automethod:: Mastodon.instance_health
847.. automethod:: Mastodon.instance_nodeinfo
847 848
848Reading data: Timelines 849Reading data: Timelines
849----------------------- 850-----------------------
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py
index f0063e5..1561fa1 100644
--- a/mastodon/Mastodon.py
+++ b/mastodon/Mastodon.py
@@ -660,7 +660,35 @@ class Mastodon:
660 Basic health check. Returns True if healthy, False if not. 660 Basic health check. Returns True if healthy, False if not.
661 """ 661 """
662 return self.__api_request('GET', '/health', parse=False).decode("utf-8") == "success" 662 return self.__api_request('GET', '/health', parse=False).decode("utf-8") == "success"
663 663
664 @api_version("3.0.0", "3.0.0", "3.0.0")
665 def instance_nodeinfo(self, schema = "http://nodeinfo.diaspora.software/ns/schema/2.0"):
666 """
667 Retrieves the instances nodeinfo information.
668
669 For information on what the nodeinfo can contain, see the nodeinfo
670 specification: https://github.com/jhass/nodeinfo . By default,
671 Mastodon.py will try to retrieve the version 2.0 schema nodeinfo.
672
673 To override the schema, specify the desired schema with the `schema`
674 parameter.
675 """
676 links = self.__api_request('GET', '/.well-known/nodeinfo')["links"]
677
678 schema_url = None
679 for available_schema in links:
680 if available_schema.rel == schema:
681 schema_url = available_schema.href
682
683 if schema_url is None:
684 raise MastodonIllegalArgumentError("Requested nodeinfo schema is not available.")
685
686 try:
687 return self.__api_request('GET', schema_url, base_url_override="")
688 except MastodonNotFoundError:
689 parse = urlparse(schema_url)
690 return self.__api_request('GET', parse.path + parse.params + parse.query + parse.fragment)
691
664 ### 692 ###
665 # Reading data: Timelines 693 # Reading data: Timelines
666 ## 694 ##
diff --git a/tests/cassettes/test_nodeinfo.yaml b/tests/cassettes/test_nodeinfo.yaml
new file mode 100644
index 0000000..38f8d01
--- /dev/null
+++ b/tests/cassettes/test_nodeinfo.yaml
@@ -0,0 +1,81 @@
1interactions:
2- request:
3 body: null
4 headers:
5 Accept: ['*/*']
6 Accept-Encoding: ['gzip, deflate']
7 Authorization: [Bearer __MASTODON_PY_TEST_ACCESS_TOKEN]
8 Connection: [keep-alive]
9 User-Agent: [python-requests/2.18.4]
10 method: GET
11 uri: http://localhost:3000/.well-known/nodeinfo
12 response:
13 body: {string: '{"links":[{"rel":"http://nodeinfo.diaspora.software/ns/schema/2.0","href":"http://localhost/nodeinfo/2.0"}]}'}
14 headers:
15 Cache-Control: ['max-age=259200, public']
16 Content-Type: [application/json; charset=utf-8]
17 Date: ['Sat, 12 Oct 2019 18:50:31 GMT']
18 ETag: [W/"e1fd8a5cbe12d2ef42c3146d5319c8af"]
19 Referrer-Policy: [strict-origin-when-cross-origin]
20 Transfer-Encoding: [chunked]
21 Vary: ['Accept, Accept-Encoding, Origin']
22 X-Content-Type-Options: [nosniff]
23 X-Download-Options: [noopen]
24 X-Frame-Options: [SAMEORIGIN]
25 X-Permitted-Cross-Domain-Policies: [none]
26 X-Request-Id: [38a2a5fc-0a7e-44f1-bf4d-85c90c39b2bb]
27 X-Runtime: ['0.026451']
28 X-XSS-Protection: [1; mode=block]
29 content-length: ['108']
30 status: {code: 200, message: OK}
31- request:
32 body: null
33 headers:
34 Accept: ['*/*']
35 Accept-Encoding: ['gzip, deflate']
36 Authorization: [Bearer __MASTODON_PY_TEST_ACCESS_TOKEN]
37 Connection: [keep-alive]
38 User-Agent: [python-requests/2.18.4]
39 method: GET
40 uri: http://localhost/nodeinfo/2.0
41 response:
42 body: {string: "<html>\r\n<head><title>404 Not Found</title></head>\r\n<body bgcolor=\"white\">\r\n<center><h1>404
43 Not Found</h1></center>\r\n<hr><center>nginx/1.14.0 (Ubuntu)</center>\r\n</body>\r\n</html>\r\n"}
44 headers:
45 Connection: [keep-alive]
46 Content-Type: [text/html]
47 Date: ['Sat, 12 Oct 2019 18:50:31 GMT']
48 Server: [nginx/1.14.0 (Ubuntu)]
49 Transfer-Encoding: [chunked]
50 content-length: ['178']
51 status: {code: 404, message: Not Found}
52- request:
53 body: null
54 headers:
55 Accept: ['*/*']
56 Accept-Encoding: ['gzip, deflate']
57 Authorization: [Bearer __MASTODON_PY_TEST_ACCESS_TOKEN]
58 Connection: [keep-alive]
59 User-Agent: [python-requests/2.18.4]
60 method: GET
61 uri: http://localhost:3000/nodeinfo/2.0
62 response:
63 body: {string: '{"version":"2.0","software":{"name":"mastodon","version":"3.0.1"},"protocols":["activitypub"],"usage":{"users":{"total":3,"activeMonth":3,"activeHalfyear":3},"localPosts":32},"openRegistrations":true}'}
64 headers:
65 Cache-Control: ['max-age=1800, public']
66 Content-Type: [application/json; charset=utf-8]
67 Date: ['Sat, 12 Oct 2019 18:50:31 GMT']
68 ETag: [W/"a09a04c6f9dc121c4b70f446e88a2686"]
69 Referrer-Policy: [strict-origin-when-cross-origin]
70 Transfer-Encoding: [chunked]
71 Vary: ['Accept,Accept-Encoding']
72 X-Content-Type-Options: [nosniff]
73 X-Download-Options: [noopen]
74 X-Frame-Options: [SAMEORIGIN]
75 X-Permitted-Cross-Domain-Policies: [none]
76 X-Request-Id: [5d4c66c1-efad-4b9f-85b0-d67755adb967]
77 X-Runtime: ['0.020737']
78 X-XSS-Protection: [1; mode=block]
79 content-length: ['200']
80 status: {code: 200, message: OK}
81version: 1
diff --git a/tests/test_instance.py b/tests/test_instance.py
index a304585..343af18 100644
--- a/tests/test_instance.py
+++ b/tests/test_instance.py
@@ -36,3 +36,10 @@ def test_emoji(api):
36@pytest.mark.vcr() 36@pytest.mark.vcr()
37def test_health(api): 37def test_health(api):
38 assert api.instance_health() == True 38 assert api.instance_health() == True
39
40@pytest.mark.vcr()
41def test_nodeinfo(api):
42 nodeinfo = api.instance_nodeinfo()
43 assert nodeinfo
44 assert nodeinfo.version == '2.0'
45
Powered by cgit v1.2.3 (git 2.41.0)