aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/index.rst1
-rw-r--r--mastodon/Mastodon.py7
-rw-r--r--tests/cassettes/test_health.yaml30
-rw-r--r--tests/test_instance.py4
4 files changed, 42 insertions, 0 deletions
diff --git a/docs/index.rst b/docs/index.rst
index 6e234d0..f65fe1e 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -843,6 +843,7 @@ current instance.
843.. automethod:: Mastodon.instance 843.. automethod:: Mastodon.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 847
847Reading data: Timelines 848Reading data: Timelines
848----------------------- 849-----------------------
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py
index 308c428..f0063e5 100644
--- a/mastodon/Mastodon.py
+++ b/mastodon/Mastodon.py
@@ -654,6 +654,13 @@ class Mastodon:
654 """ 654 """
655 return self.__api_request('GET', '/api/v1/instance/peers') 655 return self.__api_request('GET', '/api/v1/instance/peers')
656 656
657 @api_version("3.0.0", "3.0.0", "3.0.0")
658 def instance_health(self):
659 """
660 Basic health check. Returns True if healthy, False if not.
661 """
662 return self.__api_request('GET', '/health', parse=False).decode("utf-8") == "success"
663
657 ### 664 ###
658 # Reading data: Timelines 665 # Reading data: Timelines
659 ## 666 ##
diff --git a/tests/cassettes/test_health.yaml b/tests/cassettes/test_health.yaml
new file mode 100644
index 0000000..ff8e97d
--- /dev/null
+++ b/tests/cassettes/test_health.yaml
@@ -0,0 +1,30 @@
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/health
12 response:
13 body: {string: success}
14 headers:
15 Cache-Control: ['max-age=0, private, must-revalidate']
16 Content-Type: [text/plain; charset=utf-8]
17 Last-Modified: ['Sat, 12 Oct 2019 18:23:49 GMT']
18 Referrer-Policy: [strict-origin-when-cross-origin]
19 Transfer-Encoding: [chunked]
20 Vary: [Accept-Encoding]
21 X-Content-Type-Options: [nosniff]
22 X-Download-Options: [noopen]
23 X-Frame-Options: [SAMEORIGIN]
24 X-Permitted-Cross-Domain-Policies: [none]
25 X-Request-Id: [13fff315-deaa-47c3-9138-d61d02c5063e]
26 X-Runtime: ['0.311003']
27 X-XSS-Protection: [1; mode=block]
28 content-length: ['7']
29 status: {code: 200, message: OK}
30version: 1
diff --git a/tests/test_instance.py b/tests/test_instance.py
index 0eebc57..a304585 100644
--- a/tests/test_instance.py
+++ b/tests/test_instance.py
@@ -32,3 +32,7 @@ def test_low_version(api_low_version):
32@pytest.mark.vcr() 32@pytest.mark.vcr()
33def test_emoji(api): 33def test_emoji(api):
34 assert len(api.custom_emojis()) == 0 34 assert len(api.custom_emojis()) == 0
35
36@pytest.mark.vcr()
37def test_health(api):
38 assert api.instance_health() == True
Powered by cgit v1.2.3 (git 2.41.0)