slackpy 2.2.1__tar.gz → 3.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
slackpy-3.0.0/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014-2017 Takahiro Ikeuchi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
slackpy-3.0.0/PKG-INFO ADDED
@@ -0,0 +1,169 @@
1
+ Metadata-Version: 2.4
2
+ Name: slackpy
3
+ Version: 3.0.0
4
+ Summary: A Simple and Human Friendly Slack Client for Logging.
5
+ Author-email: Takahiro Ikeuchi <takahiro.ikeuchi@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/iktakahiro/slackpy
8
+ Keywords: Slack,Slack Client
9
+ Classifier: Programming Language :: Python :: 3.11
10
+ Classifier: Programming Language :: Python :: 3.12
11
+ Classifier: Programming Language :: Python :: 3.13
12
+ Classifier: Programming Language :: Python :: 3.14
13
+ Classifier: Programming Language :: Python :: 3.15
14
+ Classifier: Topic :: System :: Logging
15
+ Classifier: Topic :: Communications :: Chat
16
+ Requires-Python: >=3.11
17
+ Description-Content-Type: text/x-rst
18
+ License-File: LICENSE
19
+ Requires-Dist: requests>=2.32.5
20
+ Requires-Dist: certifi>=2026.10.19
21
+ Requires-Dist: retrying
22
+ Provides-Extra: test
23
+ Requires-Dist: pytest; extra == "test"
24
+ Dynamic: license-file
25
+
26
+ .. image:: https://img.shields.io/pypi/v/slackpy.svg
27
+ :target: https://pypi.python.org/pypi/slackpy
28
+
29
+ .. image:: https://img.shields.io/pypi/dm/slackpy.svg
30
+ :target: https://pypi.python.org/pypi/slackpy
31
+
32
+ slackpy
33
+ =======
34
+
35
+ A Simple and Human Friendly `Slack`_ Client for Logging.
36
+
37
+ Use Case
38
+ --------
39
+
40
+ - Web Application
41
+ - NEW! `AWS Lambda`_
42
+ - Bash Script
43
+
44
+ Install
45
+ -------
46
+
47
+ Requires Python 3.11 or newer.
48
+
49
+ .. code:: sh
50
+
51
+ pip install slackpy
52
+
53
+ Dependencies
54
+ ------------
55
+
56
+ - requests>=2.32.5
57
+ - certifi>=2026.10.19
58
+ - retrying
59
+
60
+ Sample Code
61
+ -----------
62
+
63
+ .. code:: python
64
+
65
+ import slackpy
66
+
67
+ INCOMING_WEB_HOOK = 'your_web_hook_url'
68
+ CHANNEL = '#general'
69
+ USER_NAME = 'Logger'
70
+ ICON_URL = 'http://lorempixel.com/48/48'
71
+
72
+ # Create a new instance.
73
+ logging = slackpy.SlackLogger(INCOMING_WEB_HOOK, CHANNEL, USER_NAME, ICON_URL)
74
+
75
+ # You can set a log level. The default level is INFO.
76
+ logging.set_log_level(slackpy.LogLv.DEBUG) # Or logging.set_log_level(10)
77
+
78
+ ## Minimum Parameter
79
+ ## logging = slackpy.SlackLogger(INCOMING_WEB_HOOK)
80
+
81
+ # Simple Usage
82
+ logging.info('INFO Message')
83
+
84
+ # LogLevel's only required parameter is "message", all others are optional.
85
+
86
+ # LogLevel: DEBUG
87
+ logging.debug(message='DEBUG Message', title='DEBUG Title', fields='')
88
+
89
+ # LogLevel: INFO
90
+ logging.info(message='INFO Message', title='INFO Title', fields='')
91
+
92
+ # LogLevel: WARN
93
+ logging.warn(message='WARN Message', title='WARN Title', fields='')
94
+
95
+ # LogLevel: ERROR
96
+ logging.error(message='ERROR Message', title='ERROR Title', fields='')
97
+
98
+ # LogLevel: CUSTOM
99
+ logging.message(message='CUSTOM Message', title='CUSTOM Title', color='good',
100
+ fields=[{"title": "CUSTOM", "value": "test", "short": True}],
101
+ log_level=40)
102
+
103
+ # Title Link (New v2.1.0)
104
+ logging.info(message='INFO Message', title='slackpy Repository here',
105
+ title_link='https://github.com/iktakahiro/slackpy')
106
+
107
+
108
+ +-----------+----------------+------------------------+
109
+ | Method | LogLevel | Color |
110
+ +===========+================+========================+
111
+ | debug() | DEBUG (10) | #03A9F4 (Light Blue) |
112
+ +-----------+----------------+------------------------+
113
+ | info() | INFO (20) | good (green) |
114
+ +-----------+----------------+------------------------+
115
+ | warn() | WARNING (30) | warning (orange) |
116
+ +-----------+----------------+------------------------+
117
+ | error() | ERROR (40) | danger (red) |
118
+ +-----------+----------------+------------------------+
119
+
120
+ The definition of the log level is based on the standard library.
121
+ (https://docs.python.org/3/library/logging.html#levels)
122
+
123
+ Command line
124
+ ------------
125
+
126
+ .. code:: sh
127
+
128
+ export SLACK_INCOMING_WEB_HOOK='your_web_hook_url'
129
+
130
+ # LogLevel: DEBUG
131
+ slackpy -c '#your_channel' -m 'DEBUG Message' -l 10
132
+
133
+ # LogLevel: INFO
134
+ slackpy -c '#your_channel' -m 'INFO Message' -l 20
135
+
136
+ # LogLevel: WARN
137
+ slackpy -c '#your_channel' -m 'WARN Message' -l 30
138
+
139
+ # LogLevel: ERROR
140
+ slackpy -c '#your_channel' -m 'ERROR Message' -l 40
141
+
142
+ # LogLevel: DEBUG (without specifying #channel)
143
+ slackpy -m 'DEBUG Message' -l 10
144
+
145
+ # LogLevel: INFO (with Message Title)
146
+ slackpy -c '#your_channel' -t 'INFO Message Title' -m 'INFO Message' -l 20
147
+
148
+ For AWS Lamdba
149
+ --------------
150
+
151
+ .. code:: sh
152
+
153
+ # First, pip install to top of project directory.
154
+ pip install slackpy -t .
155
+
156
+ # Second, archive your source code and dependency packages.
157
+ zip -r src.zip lambda_function.py slackpy requests certifi charset_normalizer idna urllib3 retrying
158
+
159
+ # Finally, upload src.zip
160
+
161
+ About Versioning
162
+ ----------------
163
+
164
+ slackpy is following `Semantic Versioning 2.0.0 <http://semver.org/spec/v2.0.0.html>`_.
165
+
166
+ .. _Slack: https://slack.com
167
+
168
+ .. _AWS Lambda: https://aws.amazon.com/lambda/
169
+
@@ -4,13 +4,10 @@
4
4
  .. image:: https://img.shields.io/pypi/dm/slackpy.svg
5
5
  :target: https://pypi.python.org/pypi/slackpy
6
6
 
7
- .. image:: https://travis-ci.org/iktakahiro/slackpy.svg?branch=master
8
- :target: https://travis-ci.org/iktakahiro/slackpy
9
-
10
7
  slackpy
11
8
  =======
12
9
 
13
- slackpy is simple and useful `Slack`_ client library for logging.
10
+ A Simple and Human Friendly `Slack`_ Client for Logging.
14
11
 
15
12
  Use Case
16
13
  --------
@@ -22,6 +19,8 @@ Use Case
22
19
  Install
23
20
  -------
24
21
 
22
+ Requires Python 3.11 or newer.
23
+
25
24
  .. code:: sh
26
25
 
27
26
  pip install slackpy
@@ -29,7 +28,9 @@ Install
29
28
  Dependencies
30
29
  ------------
31
30
 
32
- - requests
31
+ - requests>=2.32.5
32
+ - certifi>=2026.10.19
33
+ - retrying
33
34
 
34
35
  Sample Code
35
36
  -----------
@@ -46,7 +47,7 @@ Sample Code
46
47
  # Create a new instance.
47
48
  logging = slackpy.SlackLogger(INCOMING_WEB_HOOK, CHANNEL, USER_NAME, ICON_URL)
48
49
 
49
- # You can set a log level. Default level is INFO.
50
+ # You can set a log level. The default level is INFO.
50
51
  logging.set_log_level(slackpy.LogLv.DEBUG) # Or logging.set_log_level(10)
51
52
 
52
53
  ## Minimum Parameter
@@ -78,8 +79,6 @@ Sample Code
78
79
  logging.info(message='INFO Message', title='slackpy Repository here',
79
80
  title_link='https://github.com/iktakahiro/slackpy')
80
81
 
81
- Correspondence table
82
- ~~~~~~~~~~~~~~~~~~~~
83
82
 
84
83
  +-----------+----------------+------------------------+
85
84
  | Method | LogLevel | Color |
@@ -93,8 +92,8 @@ Correspondence table
93
92
  | error() | ERROR (40) | danger (red) |
94
93
  +-----------+----------------+------------------------+
95
94
 
96
- LogLevel based on logging standard library
97
- (https://docs.python.org/3.4/library/logging.html#levels)
95
+ The definition of the log level is based on the standard library.
96
+ (https://docs.python.org/3/library/logging.html#levels)
98
97
 
99
98
  Command line
100
99
  ------------
@@ -129,10 +128,10 @@ For AWS Lamdba
129
128
  # First, pip install to top of project directory.
130
129
  pip install slackpy -t .
131
130
 
132
- # Second, Archive your source code and dependency packages.
133
- zip -r src.zip lambda_function.py slackpy enum requests
131
+ # Second, archive your source code and dependency packages.
132
+ zip -r src.zip lambda_function.py slackpy requests certifi charset_normalizer idna urllib3 retrying
134
133
 
135
- # Finally, Upload your src.zip
134
+ # Finally, upload src.zip
136
135
 
137
136
  About Versioning
138
137
  ----------------
@@ -0,0 +1,36 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "slackpy"
7
+ version = "3.0.0"
8
+ description = "A Simple and Human Friendly Slack Client for Logging."
9
+ readme = "README.rst"
10
+ requires-python = ">=3.11"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ authors = [{name = "Takahiro Ikeuchi", email = "takahiro.ikeuchi@gmail.com"}]
14
+ keywords = ["Slack", "Slack Client"]
15
+ classifiers = [
16
+ "Programming Language :: Python :: 3.11",
17
+ "Programming Language :: Python :: 3.12",
18
+ "Programming Language :: Python :: 3.13",
19
+ "Programming Language :: Python :: 3.14",
20
+ "Programming Language :: Python :: 3.15",
21
+ "Topic :: System :: Logging",
22
+ "Topic :: Communications :: Chat",
23
+ ]
24
+ dependencies = ["requests>=2.32.5", "certifi>=2026.10.19", "retrying"]
25
+
26
+ [project.optional-dependencies]
27
+ test = ["pytest"]
28
+
29
+ [project.urls]
30
+ Homepage = "https://github.com/iktakahiro/slackpy"
31
+
32
+ [project.scripts]
33
+ slackpy = "slackpy.commandline:main"
34
+
35
+ [tool.setuptools]
36
+ packages = ["slackpy"]
@@ -1,5 +1,4 @@
1
1
  [egg_info]
2
2
  tag_build =
3
3
  tag_date = 0
4
- tag_svn_revision = 0
5
4
 
@@ -0,0 +1,3 @@
1
+ __author__ = 'Takahiro Ikeuchi'
2
+
3
+ from .slackpy import SlackLogger, LogLv, LOG_LEVELS
@@ -1,6 +1,3 @@
1
- #!/usr/bin/env python
2
- # -*- coding: utf-8 -*-
3
-
4
1
  import os
5
2
  from slackpy import SlackLogger, LogLv, LOG_LEVELS
6
3
  from argparse import ArgumentParser
@@ -14,17 +11,17 @@ def main():
14
11
  '--message',
15
12
  type=str,
16
13
  required=True,
17
- help='Text of the message to send.')
14
+ help='Message body.')
18
15
  parser.add_argument('-c',
19
16
  '--channel',
20
17
  required=False,
21
- help='Slack Channel. The channel must be started with # or @',
18
+ help='Slack Channel. channel must be started with # or @',
22
19
  default=None)
23
20
  parser.add_argument('-t',
24
21
  '--title',
25
22
  type=str,
26
23
  required=False,
27
- help='Title of the message to send.',
24
+ help='Message title.',
28
25
  default='Slack Notification')
29
26
  parser.add_argument('-n',
30
27
  '--name',
@@ -40,9 +37,10 @@ def main():
40
37
  '--level',
41
38
  type=int,
42
39
  default=20,
43
- choices=LOG_LEVELS.append([1, 2, 3]))
40
+ choices=LOG_LEVELS + [1, 2, 3])
44
41
 
45
42
  args = parser.parse_args()
43
+ args.level = {1: LogLv.INFO, 2: LogLv.WARN, 3: LogLv.ERROR}.get(args.level, args.level)
46
44
 
47
45
  try:
48
46
  web_hook_url = os.environ["SLACK_INCOMING_WEB_HOOK"]
@@ -1,7 +1,3 @@
1
- #!/usr/bin/env python
2
- # -*- coding: utf-8 -*-
3
-
4
- from __future__ import print_function
5
1
  import json
6
2
  import traceback
7
3
  import requests
@@ -91,14 +87,14 @@ class SlackLogger:
91
87
  fields='', log_level=LogLv.INFO):
92
88
  """Send a message to a channel.
93
89
  Args:
94
- title: A message title.
95
- title: A link of the message title.
96
- message: The message body.
97
- color: Can either be one of 'good', 'warning', 'danger',
98
- or any hex color code.
90
+ title: Message title.
91
+ title_link: Link of the message title.
92
+ message: Message body.
93
+ color: Message line color on Slack. This parameter should be one of the following values: 'good', 'warning',
94
+ 'danger' or any hex color code.
99
95
 
100
96
  Returns:
101
- response: A Response of Slack API.
97
+ response: Response of Slack API.
102
98
 
103
99
  Raises:
104
100
  Exception:
@@ -0,0 +1,169 @@
1
+ Metadata-Version: 2.4
2
+ Name: slackpy
3
+ Version: 3.0.0
4
+ Summary: A Simple and Human Friendly Slack Client for Logging.
5
+ Author-email: Takahiro Ikeuchi <takahiro.ikeuchi@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/iktakahiro/slackpy
8
+ Keywords: Slack,Slack Client
9
+ Classifier: Programming Language :: Python :: 3.11
10
+ Classifier: Programming Language :: Python :: 3.12
11
+ Classifier: Programming Language :: Python :: 3.13
12
+ Classifier: Programming Language :: Python :: 3.14
13
+ Classifier: Programming Language :: Python :: 3.15
14
+ Classifier: Topic :: System :: Logging
15
+ Classifier: Topic :: Communications :: Chat
16
+ Requires-Python: >=3.11
17
+ Description-Content-Type: text/x-rst
18
+ License-File: LICENSE
19
+ Requires-Dist: requests>=2.32.5
20
+ Requires-Dist: certifi>=2026.10.19
21
+ Requires-Dist: retrying
22
+ Provides-Extra: test
23
+ Requires-Dist: pytest; extra == "test"
24
+ Dynamic: license-file
25
+
26
+ .. image:: https://img.shields.io/pypi/v/slackpy.svg
27
+ :target: https://pypi.python.org/pypi/slackpy
28
+
29
+ .. image:: https://img.shields.io/pypi/dm/slackpy.svg
30
+ :target: https://pypi.python.org/pypi/slackpy
31
+
32
+ slackpy
33
+ =======
34
+
35
+ A Simple and Human Friendly `Slack`_ Client for Logging.
36
+
37
+ Use Case
38
+ --------
39
+
40
+ - Web Application
41
+ - NEW! `AWS Lambda`_
42
+ - Bash Script
43
+
44
+ Install
45
+ -------
46
+
47
+ Requires Python 3.11 or newer.
48
+
49
+ .. code:: sh
50
+
51
+ pip install slackpy
52
+
53
+ Dependencies
54
+ ------------
55
+
56
+ - requests>=2.32.5
57
+ - certifi>=2026.10.19
58
+ - retrying
59
+
60
+ Sample Code
61
+ -----------
62
+
63
+ .. code:: python
64
+
65
+ import slackpy
66
+
67
+ INCOMING_WEB_HOOK = 'your_web_hook_url'
68
+ CHANNEL = '#general'
69
+ USER_NAME = 'Logger'
70
+ ICON_URL = 'http://lorempixel.com/48/48'
71
+
72
+ # Create a new instance.
73
+ logging = slackpy.SlackLogger(INCOMING_WEB_HOOK, CHANNEL, USER_NAME, ICON_URL)
74
+
75
+ # You can set a log level. The default level is INFO.
76
+ logging.set_log_level(slackpy.LogLv.DEBUG) # Or logging.set_log_level(10)
77
+
78
+ ## Minimum Parameter
79
+ ## logging = slackpy.SlackLogger(INCOMING_WEB_HOOK)
80
+
81
+ # Simple Usage
82
+ logging.info('INFO Message')
83
+
84
+ # LogLevel's only required parameter is "message", all others are optional.
85
+
86
+ # LogLevel: DEBUG
87
+ logging.debug(message='DEBUG Message', title='DEBUG Title', fields='')
88
+
89
+ # LogLevel: INFO
90
+ logging.info(message='INFO Message', title='INFO Title', fields='')
91
+
92
+ # LogLevel: WARN
93
+ logging.warn(message='WARN Message', title='WARN Title', fields='')
94
+
95
+ # LogLevel: ERROR
96
+ logging.error(message='ERROR Message', title='ERROR Title', fields='')
97
+
98
+ # LogLevel: CUSTOM
99
+ logging.message(message='CUSTOM Message', title='CUSTOM Title', color='good',
100
+ fields=[{"title": "CUSTOM", "value": "test", "short": True}],
101
+ log_level=40)
102
+
103
+ # Title Link (New v2.1.0)
104
+ logging.info(message='INFO Message', title='slackpy Repository here',
105
+ title_link='https://github.com/iktakahiro/slackpy')
106
+
107
+
108
+ +-----------+----------------+------------------------+
109
+ | Method | LogLevel | Color |
110
+ +===========+================+========================+
111
+ | debug() | DEBUG (10) | #03A9F4 (Light Blue) |
112
+ +-----------+----------------+------------------------+
113
+ | info() | INFO (20) | good (green) |
114
+ +-----------+----------------+------------------------+
115
+ | warn() | WARNING (30) | warning (orange) |
116
+ +-----------+----------------+------------------------+
117
+ | error() | ERROR (40) | danger (red) |
118
+ +-----------+----------------+------------------------+
119
+
120
+ The definition of the log level is based on the standard library.
121
+ (https://docs.python.org/3/library/logging.html#levels)
122
+
123
+ Command line
124
+ ------------
125
+
126
+ .. code:: sh
127
+
128
+ export SLACK_INCOMING_WEB_HOOK='your_web_hook_url'
129
+
130
+ # LogLevel: DEBUG
131
+ slackpy -c '#your_channel' -m 'DEBUG Message' -l 10
132
+
133
+ # LogLevel: INFO
134
+ slackpy -c '#your_channel' -m 'INFO Message' -l 20
135
+
136
+ # LogLevel: WARN
137
+ slackpy -c '#your_channel' -m 'WARN Message' -l 30
138
+
139
+ # LogLevel: ERROR
140
+ slackpy -c '#your_channel' -m 'ERROR Message' -l 40
141
+
142
+ # LogLevel: DEBUG (without specifying #channel)
143
+ slackpy -m 'DEBUG Message' -l 10
144
+
145
+ # LogLevel: INFO (with Message Title)
146
+ slackpy -c '#your_channel' -t 'INFO Message Title' -m 'INFO Message' -l 20
147
+
148
+ For AWS Lamdba
149
+ --------------
150
+
151
+ .. code:: sh
152
+
153
+ # First, pip install to top of project directory.
154
+ pip install slackpy -t .
155
+
156
+ # Second, archive your source code and dependency packages.
157
+ zip -r src.zip lambda_function.py slackpy requests certifi charset_normalizer idna urllib3 retrying
158
+
159
+ # Finally, upload src.zip
160
+
161
+ About Versioning
162
+ ----------------
163
+
164
+ slackpy is following `Semantic Versioning 2.0.0 <http://semver.org/spec/v2.0.0.html>`_.
165
+
166
+ .. _Slack: https://slack.com
167
+
168
+ .. _AWS Lambda: https://aws.amazon.com/lambda/
169
+
@@ -1,7 +1,6 @@
1
- MANIFEST.in
1
+ LICENSE
2
2
  README.rst
3
- requirements.txt
4
- setup.py
3
+ pyproject.toml
5
4
  slackpy/__init__.py
6
5
  slackpy/commandline.py
7
6
  slackpy/slackpy.py
@@ -10,4 +9,6 @@ slackpy.egg-info/SOURCES.txt
10
9
  slackpy.egg-info/dependency_links.txt
11
10
  slackpy.egg-info/entry_points.txt
12
11
  slackpy.egg-info/requires.txt
13
- slackpy.egg-info/top_level.txt
12
+ slackpy.egg-info/top_level.txt
13
+ tests/test_commandline.py
14
+ tests/test_slackpy.py
@@ -1,3 +1,2 @@
1
1
  [console_scripts]
2
2
  slackpy = slackpy.commandline:main
3
-
@@ -0,0 +1,6 @@
1
+ requests>=2.32.5
2
+ certifi>=2026.10.19
3
+ retrying
4
+
5
+ [test]
6
+ pytest
@@ -0,0 +1,33 @@
1
+ import sys
2
+ from types import SimpleNamespace
3
+ from unittest.mock import Mock
4
+
5
+ import pytest
6
+
7
+ from slackpy import LOG_LEVELS
8
+ from slackpy.commandline import main
9
+
10
+
11
+ @pytest.mark.parametrize(('level', 'method'), [
12
+ (10, 'debug'), (20, 'info'), (30, 'warn'), (40, 'error'),
13
+ (1, 'info'), (2, 'warn'), (3, 'error'),
14
+ ])
15
+ def test_cli_levels(level, method, monkeypatch, capsys):
16
+ client = Mock()
17
+ getattr(client, method).return_value = SimpleNamespace(status_code=200)
18
+ monkeypatch.setattr('slackpy.commandline.SlackLogger', Mock(return_value=client))
19
+ monkeypatch.setenv('SLACK_INCOMING_WEB_HOOK', 'https://example.com/webhook')
20
+ monkeypatch.setattr(sys, 'argv', ['slackpy', '-m', 'hello', '-l', str(level)])
21
+
22
+ main()
23
+
24
+ getattr(client, method).assert_called_once_with('hello', 'Slack Notification')
25
+ assert capsys.readouterr().out == 'True\n'
26
+ assert LOG_LEVELS == [10, 20, 30, 40]
27
+
28
+
29
+ def test_cli_rejects_invalid_level(monkeypatch):
30
+ monkeypatch.setattr(sys, 'argv', ['slackpy', '-m', 'hello', '-l', '99'])
31
+ with pytest.raises(SystemExit) as exc:
32
+ main()
33
+ assert exc.value.code == 2
@@ -0,0 +1,228 @@
1
+ import os
2
+ import time
3
+ import pytest
4
+ from slackpy.slackpy import SlackLogger, LOG_LEVELS, LogLv
5
+
6
+ __author__ = 'Takahiro Ikeuchi'
7
+
8
+ DUMMY_WEB_HOOK = 'http://dummy_url'
9
+
10
+ VALID_WEB_HOOK = os.environ.get('SLACK_INCOMING_TEST_WEB_HOOK')
11
+ requires_webhook = pytest.mark.skipif(
12
+ not VALID_WEB_HOOK, reason='SLACK_INCOMING_TEST_WEB_HOOK is not configured'
13
+ )
14
+
15
+
16
+ class TestSlackLogger:
17
+ def test_channel_value_error(self):
18
+ with pytest.raises(ValueError):
19
+ SlackLogger(DUMMY_WEB_HOOK, 'dummy_channel', 'Test User', 'http://example.com/example.png')
20
+
21
+ def test_build_payload_with_all_parameters(self):
22
+ logger = SlackLogger(DUMMY_WEB_HOOK, '#dummy_channel', 'Test User', 'http://example.com/example.png')
23
+ actual = logger._SlackLogger__build_payload('test_build_payload_with_all_parameters',
24
+ 'Test Title',
25
+ 'https://github.com/iktakahiro/slackpy',
26
+ 'Color Name',
27
+ '')
28
+
29
+ expected = {
30
+ 'channel': '#dummy_channel',
31
+ 'username': 'Test User',
32
+ 'icon_url': 'http://example.com/example.png',
33
+ 'attachments': [
34
+ {'color': 'Color Name',
35
+ 'text': 'test_build_payload_with_all_parameters',
36
+ 'title': 'Test Title',
37
+ 'title_link': 'https://github.com/iktakahiro/slackpy',
38
+ 'mrkdwn_in': ['text', 'fields', 'title'],
39
+ 'fields': '',
40
+ }]
41
+ }
42
+
43
+ assert expected == actual
44
+
45
+ def test_build_payload_without_specifying_optional_parameters(self):
46
+ logger = SlackLogger(DUMMY_WEB_HOOK)
47
+ actual = logger._SlackLogger__build_payload('test_build_payload_without_specifying_optional_parameters',
48
+ 'Test Title',
49
+ 'https://github.com/iktakahiro/slackpy',
50
+ 'Color Name',
51
+ '')
52
+
53
+ expected = {
54
+ 'channel': None,
55
+ 'username': 'Logger',
56
+ 'icon_url': None,
57
+ 'attachments': [
58
+ {'color': 'Color Name',
59
+ 'text': 'test_build_payload_without_specifying_optional_parameters',
60
+ 'title': 'Test Title',
61
+ 'title_link': 'https://github.com/iktakahiro/slackpy',
62
+ 'mrkdwn_in': ['text', 'fields', 'title'],
63
+ 'fields': '',
64
+ }]
65
+ }
66
+
67
+ assert expected == actual
68
+
69
+ def test_build_payload_with_custom_fields(self):
70
+ logger = SlackLogger(DUMMY_WEB_HOOK, '#dummy_channel', 'Test User')
71
+
72
+ test_fields = list()
73
+ test_fields.append({
74
+ 'title': 'Project',
75
+ 'value': 'Test Project',
76
+ 'short': True
77
+ })
78
+ test_fields.append({
79
+ 'title': 'Environment',
80
+ 'value': 'Test',
81
+ 'short': True
82
+ })
83
+
84
+ actual = logger._SlackLogger__build_payload('test_build_payload_with_custom_fields',
85
+ 'Test Title',
86
+ 'https://github.com/iktakahiro/slackpy',
87
+ 'Color Name',
88
+ test_fields)
89
+
90
+ expected = {
91
+ 'channel': '#dummy_channel',
92
+ 'username': 'Test User',
93
+ 'icon_url': None,
94
+ 'attachments': [
95
+ {'color': 'Color Name',
96
+ 'text': 'test_build_payload_with_custom_fields',
97
+ 'title': 'Test Title',
98
+ 'title_link': 'https://github.com/iktakahiro/slackpy',
99
+ 'mrkdwn_in': ['text', 'fields', 'title'],
100
+ 'fields': [
101
+ {
102
+ 'title': 'Project',
103
+ 'value': 'Test Project',
104
+ 'short': True
105
+ }, {
106
+ 'title': 'Environment',
107
+ 'value': 'Test',
108
+ 'short': True
109
+ }
110
+ ],
111
+ }]
112
+ }
113
+
114
+ assert expected == actual
115
+
116
+ def test_default_log_level(self):
117
+ logger = SlackLogger(DUMMY_WEB_HOOK)
118
+ assert logger.log_level == 20
119
+
120
+ def test_values_in_log_levels(self):
121
+ assert LOG_LEVELS == [10, 20, 30, 40]
122
+
123
+ def test_to_set_valid_value_log_level(self):
124
+ logger = SlackLogger(DUMMY_WEB_HOOK)
125
+
126
+ for lv in [10, 20, 30, 40]:
127
+ logger.set_log_level(lv)
128
+ assert logger.log_level == lv
129
+
130
+ def test_to_set_invalid_value_log_level(self):
131
+ logger = SlackLogger(DUMMY_WEB_HOOK)
132
+
133
+ for lv in [0, 50, 99, 'INFO']:
134
+ with pytest.raises(ValueError):
135
+ logger.set_log_level(lv)
136
+
137
+ with pytest.raises(TypeError):
138
+ logger.set_log_level()
139
+
140
+ def test_log_level_threshold(self):
141
+ logger = SlackLogger(DUMMY_WEB_HOOK)
142
+
143
+ actual = logger.debug('TEST')
144
+ assert actual is None
145
+
146
+ logger.set_log_level(LogLv.WARN)
147
+
148
+ actual = logger.info('TEST')
149
+ assert actual is None
150
+
151
+ logger.set_log_level(LogLv.ERROR)
152
+
153
+ actual = logger.warn('TEST')
154
+ assert actual is None
155
+
156
+ @requires_webhook
157
+ def test_post_to_valid_web_hook(self):
158
+ logger = SlackLogger(VALID_WEB_HOOK, icon_url="http://lorempixel.com/48/48")
159
+ logger.set_log_level(LogLv.DEBUG)
160
+
161
+ fields = [{
162
+ 'title': 'Project',
163
+ 'value': 'Test Project',
164
+ 'short': True
165
+ }, {
166
+ 'title': 'Environment',
167
+ 'value': 'Test',
168
+ 'short': True
169
+ }
170
+ ]
171
+
172
+ time.sleep(2)
173
+ response = logger.debug('DEBUG', 'test_post_to_valid_web_hook', fields=fields)
174
+ assert response.status_code == 200
175
+
176
+ time.sleep(2)
177
+ response = logger.info('INFO', 'test_post_to_valid_web_hook', fields=fields)
178
+ assert response.status_code == 200
179
+
180
+ time.sleep(2)
181
+ response = logger.warn('WARN', 'test_post_to_valid_web_hook', fields=fields)
182
+ assert response.status_code == 200
183
+
184
+ time.sleep(2)
185
+ response = logger.error('ERROR', 'test_post_to_valid_web_hook', fields=fields)
186
+ assert response.status_code == 200
187
+
188
+ time.sleep(2)
189
+ response = logger.message('CUSTOM', 'test_post_to_valid_web_hook',
190
+ title_link='https://github.com/iktakahiro/slackpy',
191
+ fields=fields, color='warning', log_level=20)
192
+ assert response.status_code == 200
193
+
194
+ def test_post_to_invalid_web_hook(self, monkeypatch):
195
+ def fail_post(*args, **kwargs):
196
+ raise ConnectionError('Failed to connect')
197
+
198
+ monkeypatch.setattr('slackpy.slackpy.requests.post', fail_post)
199
+ # Exercise exception propagation without retry delays or network access.
200
+ logger = SlackLogger(DUMMY_WEB_HOOK)
201
+ monkeypatch.setattr(logger, '_SlackLogger__post',
202
+ lambda payload: SlackLogger._SlackLogger__post.__wrapped__(logger, payload))
203
+ with pytest.raises(Exception, match='Failed to connect'):
204
+ logger.error('Test Message', 'Test Title')
205
+
206
+ @requires_webhook
207
+ def test_title_link(self):
208
+ logger = SlackLogger(VALID_WEB_HOOK)
209
+
210
+ time.sleep(2)
211
+ response = logger.info('test_title_link', 'slackpy repository', 'https://github.com/iktakahiro/slackpy')
212
+ assert response.status_code == 200
213
+
214
+ @requires_webhook
215
+ def test_omit_title_link(self):
216
+ logger = SlackLogger(VALID_WEB_HOOK)
217
+
218
+ time.sleep(2)
219
+ response = logger.info('test_omit_title_link', 'slackpy repository')
220
+ assert response.status_code == 200
221
+
222
+ @requires_webhook
223
+ def test_minimum_post_to_valid_web_hook(self):
224
+ logger = SlackLogger(VALID_WEB_HOOK)
225
+
226
+ time.sleep(2)
227
+ response = logger.info('test_minimum_post_to_valid_web_hook')
228
+ assert response.status_code == 200
slackpy-2.2.1/MANIFEST.in DELETED
@@ -1 +0,0 @@
1
- include requirements.txt
slackpy-2.2.1/PKG-INFO DELETED
@@ -1,162 +0,0 @@
1
- Metadata-Version: 1.1
2
- Name: slackpy
3
- Version: 2.2.1
4
- Summary: Simple and Useful Slack client library
5
- Home-page: https://github.com/iktakahiro/slackpy
6
- Author: Takahiro Ikeuchi
7
- Author-email: takahiro.ikeuchi@gmail.com
8
- License: MIT
9
- Description: .. image:: https://img.shields.io/pypi/v/slackpy.svg
10
- :target: https://pypi.python.org/pypi/slackpy
11
-
12
- .. image:: https://img.shields.io/pypi/dm/slackpy.svg
13
- :target: https://pypi.python.org/pypi/slackpy
14
-
15
- .. image:: https://travis-ci.org/iktakahiro/slackpy.svg?branch=master
16
- :target: https://travis-ci.org/iktakahiro/slackpy
17
-
18
- slackpy
19
- =======
20
-
21
- slackpy is simple and useful `Slack`_ client library for logging.
22
-
23
- Use Case
24
- --------
25
-
26
- - Web Application
27
- - NEW! `AWS Lambda`_
28
- - Bash Script
29
-
30
- Install
31
- -------
32
-
33
- .. code:: sh
34
-
35
- pip install slackpy
36
-
37
- Dependencies
38
- ------------
39
-
40
- - requests
41
-
42
- Sample Code
43
- -----------
44
-
45
- .. code:: python
46
-
47
- import slackpy
48
-
49
- INCOMING_WEB_HOOK = 'your_web_hook_url'
50
- CHANNEL = '#general'
51
- USER_NAME = 'Logger'
52
- ICON_URL = 'http://lorempixel.com/48/48'
53
-
54
- # Create a new instance.
55
- logging = slackpy.SlackLogger(INCOMING_WEB_HOOK, CHANNEL, USER_NAME, ICON_URL)
56
-
57
- # You can set a log level. Default level is INFO.
58
- logging.set_log_level(slackpy.LogLv.DEBUG) # Or logging.set_log_level(10)
59
-
60
- ## Minimum Parameter
61
- ## logging = slackpy.SlackLogger(INCOMING_WEB_HOOK)
62
-
63
- # Simple Usage
64
- logging.info('INFO Message')
65
-
66
- # LogLevel's only required parameter is "message", all others are optional.
67
-
68
- # LogLevel: DEBUG
69
- logging.debug(message='DEBUG Message', title='DEBUG Title', fields='')
70
-
71
- # LogLevel: INFO
72
- logging.info(message='INFO Message', title='INFO Title', fields='')
73
-
74
- # LogLevel: WARN
75
- logging.warn(message='WARN Message', title='WARN Title', fields='')
76
-
77
- # LogLevel: ERROR
78
- logging.error(message='ERROR Message', title='ERROR Title', fields='')
79
-
80
- # LogLevel: CUSTOM
81
- logging.message(message='CUSTOM Message', title='CUSTOM Title', color='good',
82
- fields=[{"title": "CUSTOM", "value": "test", "short": True}],
83
- log_level=40)
84
-
85
- # Title Link (New v2.1.0)
86
- logging.info(message='INFO Message', title='slackpy Repository here',
87
- title_link='https://github.com/iktakahiro/slackpy')
88
-
89
- Correspondence table
90
- ~~~~~~~~~~~~~~~~~~~~
91
-
92
- +-----------+----------------+------------------------+
93
- | Method | LogLevel | Color |
94
- +===========+================+========================+
95
- | debug() | DEBUG (10) | #03A9F4 (Light Blue) |
96
- +-----------+----------------+------------------------+
97
- | info() | INFO (20) | good (green) |
98
- +-----------+----------------+------------------------+
99
- | warn() | WARNING (30) | warning (orange) |
100
- +-----------+----------------+------------------------+
101
- | error() | ERROR (40) | danger (red) |
102
- +-----------+----------------+------------------------+
103
-
104
- LogLevel based on logging standard library
105
- (https://docs.python.org/3.4/library/logging.html#levels)
106
-
107
- Command line
108
- ------------
109
-
110
- .. code:: sh
111
-
112
- export SLACK_INCOMING_WEB_HOOK='your_web_hook_url'
113
-
114
- # LogLevel: DEBUG
115
- slackpy -c '#your_channel' -m 'DEBUG Message' -l 10
116
-
117
- # LogLevel: INFO
118
- slackpy -c '#your_channel' -m 'INFO Message' -l 20
119
-
120
- # LogLevel: WARN
121
- slackpy -c '#your_channel' -m 'WARN Message' -l 30
122
-
123
- # LogLevel: ERROR
124
- slackpy -c '#your_channel' -m 'ERROR Message' -l 40
125
-
126
- # LogLevel: DEBUG (without specifying #channel)
127
- slackpy -m 'DEBUG Message' -l 10
128
-
129
- # LogLevel: INFO (with Message Title)
130
- slackpy -c '#your_channel' -t 'INFO Message Title' -m 'INFO Message' -l 20
131
-
132
- For AWS Lamdba
133
- --------------
134
-
135
- .. code:: sh
136
-
137
- # First, pip install to top of project directory.
138
- pip install slackpy -t .
139
-
140
- # Second, Archive your source code and dependency packages.
141
- zip -r src.zip lambda_function.py slackpy enum requests
142
-
143
- # Finally, Upload your src.zip
144
-
145
- About Versioning
146
- ----------------
147
-
148
- slackpy is following `Semantic Versioning 2.0.0 <http://semver.org/spec/v2.0.0.html>`_.
149
-
150
- .. _Slack: https://slack.com
151
-
152
- .. _AWS Lambda: https://aws.amazon.com/lambda/
153
-
154
-
155
- Keywords: Slack,Slack Client
156
- Platform: UNKNOWN
157
- Classifier: License :: OSI Approved :: MIT License
158
- Classifier: Programming Language :: Python :: 3.5
159
- Classifier: Programming Language :: Python :: 3.4
160
- Classifier: Programming Language :: Python :: 2.7
161
- Classifier: Topic :: System :: Logging
162
- Classifier: Topic :: Communications :: Chat
@@ -1,4 +0,0 @@
1
- requests
2
- retrying
3
- enum34 ; python_version < '3.4'
4
-
slackpy-2.2.1/setup.py DELETED
@@ -1,41 +0,0 @@
1
- #!/usr/bin/env python
2
- # -*- coding: utf-8 -*-
3
-
4
- from setuptools import setup
5
-
6
- __author__ = 'Takahiro Ikeuchi'
7
-
8
- requires = ['requests', 'retrying']
9
- tests_requires = ['requests', 'retrying', 'pytest']
10
- extras_requires = {
11
- ':python_version<"3.4"': ["enum34"],
12
- }
13
-
14
- setup(
15
- name="slackpy",
16
- version="2.2.1",
17
- packages=['slackpy'],
18
- install_requires=requires,
19
- extras_require=extras_requires,
20
- description="Simple and Useful Slack client library",
21
- long_description=open('README.rst').read(),
22
- author='Takahiro Ikeuchi',
23
- author_email='takahiro.ikeuchi@gmail.com',
24
- url='https://github.com/iktakahiro/slackpy',
25
- keywords=["Slack", "Slack Client"],
26
- license='MIT',
27
- classifiers=[
28
- "License :: OSI Approved :: MIT License",
29
- "Programming Language :: Python :: 3.5",
30
- "Programming Language :: Python :: 3.4",
31
- "Programming Language :: Python :: 2.7",
32
- "Topic :: System :: Logging",
33
- "Topic :: Communications :: Chat"
34
- ],
35
- entry_points={
36
- "console_scripts": [
37
- "slackpy=slackpy.commandline:main",
38
- ],
39
- },
40
- tests_require=tests_requires
41
- )
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env python
2
- # -*- coding: utf-8 -*-
3
-
4
- __author__ = 'Takahiro Ikeuchi'
5
-
6
- from .slackpy import SlackLogger, LogLv
@@ -1,162 +0,0 @@
1
- Metadata-Version: 1.1
2
- Name: slackpy
3
- Version: 2.2.1
4
- Summary: Simple and Useful Slack client library
5
- Home-page: https://github.com/iktakahiro/slackpy
6
- Author: Takahiro Ikeuchi
7
- Author-email: takahiro.ikeuchi@gmail.com
8
- License: MIT
9
- Description: .. image:: https://img.shields.io/pypi/v/slackpy.svg
10
- :target: https://pypi.python.org/pypi/slackpy
11
-
12
- .. image:: https://img.shields.io/pypi/dm/slackpy.svg
13
- :target: https://pypi.python.org/pypi/slackpy
14
-
15
- .. image:: https://travis-ci.org/iktakahiro/slackpy.svg?branch=master
16
- :target: https://travis-ci.org/iktakahiro/slackpy
17
-
18
- slackpy
19
- =======
20
-
21
- slackpy is simple and useful `Slack`_ client library for logging.
22
-
23
- Use Case
24
- --------
25
-
26
- - Web Application
27
- - NEW! `AWS Lambda`_
28
- - Bash Script
29
-
30
- Install
31
- -------
32
-
33
- .. code:: sh
34
-
35
- pip install slackpy
36
-
37
- Dependencies
38
- ------------
39
-
40
- - requests
41
-
42
- Sample Code
43
- -----------
44
-
45
- .. code:: python
46
-
47
- import slackpy
48
-
49
- INCOMING_WEB_HOOK = 'your_web_hook_url'
50
- CHANNEL = '#general'
51
- USER_NAME = 'Logger'
52
- ICON_URL = 'http://lorempixel.com/48/48'
53
-
54
- # Create a new instance.
55
- logging = slackpy.SlackLogger(INCOMING_WEB_HOOK, CHANNEL, USER_NAME, ICON_URL)
56
-
57
- # You can set a log level. Default level is INFO.
58
- logging.set_log_level(slackpy.LogLv.DEBUG) # Or logging.set_log_level(10)
59
-
60
- ## Minimum Parameter
61
- ## logging = slackpy.SlackLogger(INCOMING_WEB_HOOK)
62
-
63
- # Simple Usage
64
- logging.info('INFO Message')
65
-
66
- # LogLevel's only required parameter is "message", all others are optional.
67
-
68
- # LogLevel: DEBUG
69
- logging.debug(message='DEBUG Message', title='DEBUG Title', fields='')
70
-
71
- # LogLevel: INFO
72
- logging.info(message='INFO Message', title='INFO Title', fields='')
73
-
74
- # LogLevel: WARN
75
- logging.warn(message='WARN Message', title='WARN Title', fields='')
76
-
77
- # LogLevel: ERROR
78
- logging.error(message='ERROR Message', title='ERROR Title', fields='')
79
-
80
- # LogLevel: CUSTOM
81
- logging.message(message='CUSTOM Message', title='CUSTOM Title', color='good',
82
- fields=[{"title": "CUSTOM", "value": "test", "short": True}],
83
- log_level=40)
84
-
85
- # Title Link (New v2.1.0)
86
- logging.info(message='INFO Message', title='slackpy Repository here',
87
- title_link='https://github.com/iktakahiro/slackpy')
88
-
89
- Correspondence table
90
- ~~~~~~~~~~~~~~~~~~~~
91
-
92
- +-----------+----------------+------------------------+
93
- | Method | LogLevel | Color |
94
- +===========+================+========================+
95
- | debug() | DEBUG (10) | #03A9F4 (Light Blue) |
96
- +-----------+----------------+------------------------+
97
- | info() | INFO (20) | good (green) |
98
- +-----------+----------------+------------------------+
99
- | warn() | WARNING (30) | warning (orange) |
100
- +-----------+----------------+------------------------+
101
- | error() | ERROR (40) | danger (red) |
102
- +-----------+----------------+------------------------+
103
-
104
- LogLevel based on logging standard library
105
- (https://docs.python.org/3.4/library/logging.html#levels)
106
-
107
- Command line
108
- ------------
109
-
110
- .. code:: sh
111
-
112
- export SLACK_INCOMING_WEB_HOOK='your_web_hook_url'
113
-
114
- # LogLevel: DEBUG
115
- slackpy -c '#your_channel' -m 'DEBUG Message' -l 10
116
-
117
- # LogLevel: INFO
118
- slackpy -c '#your_channel' -m 'INFO Message' -l 20
119
-
120
- # LogLevel: WARN
121
- slackpy -c '#your_channel' -m 'WARN Message' -l 30
122
-
123
- # LogLevel: ERROR
124
- slackpy -c '#your_channel' -m 'ERROR Message' -l 40
125
-
126
- # LogLevel: DEBUG (without specifying #channel)
127
- slackpy -m 'DEBUG Message' -l 10
128
-
129
- # LogLevel: INFO (with Message Title)
130
- slackpy -c '#your_channel' -t 'INFO Message Title' -m 'INFO Message' -l 20
131
-
132
- For AWS Lamdba
133
- --------------
134
-
135
- .. code:: sh
136
-
137
- # First, pip install to top of project directory.
138
- pip install slackpy -t .
139
-
140
- # Second, Archive your source code and dependency packages.
141
- zip -r src.zip lambda_function.py slackpy enum requests
142
-
143
- # Finally, Upload your src.zip
144
-
145
- About Versioning
146
- ----------------
147
-
148
- slackpy is following `Semantic Versioning 2.0.0 <http://semver.org/spec/v2.0.0.html>`_.
149
-
150
- .. _Slack: https://slack.com
151
-
152
- .. _AWS Lambda: https://aws.amazon.com/lambda/
153
-
154
-
155
- Keywords: Slack,Slack Client
156
- Platform: UNKNOWN
157
- Classifier: License :: OSI Approved :: MIT License
158
- Classifier: Programming Language :: Python :: 3.5
159
- Classifier: Programming Language :: Python :: 3.4
160
- Classifier: Programming Language :: Python :: 2.7
161
- Classifier: Topic :: System :: Logging
162
- Classifier: Topic :: Communications :: Chat
@@ -1,5 +0,0 @@
1
- requests
2
- retrying
3
-
4
- [:python_version<"3.4"]
5
- enum34