Debian Codegraph @

tests/test_plugin_lark.py

raw
1 # Disable logging for a cleaner testing output
2 import logging
3
4 from helpers import AppriseURLTester
5 import requests
6
7 from apprise.exception import AppriseImproperlyConfigured
8 from apprise.plugins.lark import NotifyLark
9
10 logging.disable(logging.CRITICAL)
11
12 # Our Testing URLs
13 apprise_url_tests = (
14 (
15 "lark://",
16 {
17 # Teams Token missing
18 "instance": AppriseImproperlyConfigured,
19 },
20 ),
21 (
22 "lark://:@/",
23 {
24 # We don't have strict host checking on for lark, so this URL
25 # actually becomes parseable and :@ becomes a hostname.
26 # The below errors because a second token wasn't found
27 "instance": AppriseImproperlyConfigured,
28 },
29 ),
30 (
31 "lark://{}".format("abcd-1234"),
32 {
33 # token provided - we're good
34 "instance": NotifyLark,
35 # Our expected url(privacy=True) startswith() response:
36 "privacy_url": "lark://****/",
37 },
38 ),
39 (
40 "lark://{}".format("abcd-1234"),
41 {
42 # token provided - we're good
43 "instance": NotifyLark,
44 # Our expected url(privacy=True) startswith() response:
45 "privacy_url": "lark://****/",
46 },
47 ),
48 (
49 "lark://?token={}".format("abcd-1234"),
50 {
51 # token provided - we're good
52 "instance": NotifyLark,
53 # Our expected url(privacy=True) startswith() response:
54 "privacy_url": "lark://****/",
55 },
56 ),
57 # Support Native URLs with arguments
58 (
59 "https://open.larksuite.com/open-apis/bot/v2/hook/{}".format(
60 "abcd-1234"
61 ),
62 {
63 # token provided - we're good
64 "instance": NotifyLark,
65 },
66 ),
67 (
68 "lark://{}".format("abcd-1234"),
69 {
70 "instance": NotifyLark,
71 # force a failure
72 "response": False,
73 "requests_response_code": requests.codes.internal_server_error,
74 },
75 ),
76 (
77 "lark://{}".format("abcd-1234"),
78 {
79 "instance": NotifyLark,
80 # throw a bizarre code forcing us to fail to look it up
81 "response": False,
82 "requests_response_code": 999,
83 },
84 ),
85 (
86 "lark://{}".format("a" * 80),
87 {
88 "instance": NotifyLark,
89 # Throws a series of i/o exceptions with this flag
90 # is set and tests that we gracefully handle them
91 "test_requests_exceptions": True,
92 },
93 ),
94 )
95
96
97 def test_plugin_lark_urls():
98 """NotifyLark() Apprise URLs."""
99
100 # Run our general tests
101 AppriseURLTester(tests=apprise_url_tests).run_all()