Debian Codegraph @

tests/test_plugin_lark.py

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