Skip to content

Commit

Permalink
Better Topic Message Support. (#3)
Browse files Browse the repository at this point in the history
- `uids` is NOT required parameter for `send_message` now.
- `flake8` and its extensions compatibility.
- `setuptools_scm` for version.
- `pipenv` for dependencies management.
  • Loading branch information
huxuan authored Feb 17, 2020
1 parent a4ba4e5 commit 1713c37
Show file tree
Hide file tree
Showing 19 changed files with 139 additions and 78 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,6 @@ dmypy.json
.pyre/

# Custom
.vscode
Pipfile.lock
config.py
3 changes: 0 additions & 3 deletions MANIFEST.in

This file was deleted.

21 changes: 9 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
.PHONY: clean install dev lint pycodestyle pyflakes pylint test dist upload
.PHONY: clean install lint flake8 pylint test dist upload

PIPENV := $(shell command -v pipenv > /dev/null && echo env)
PIPRUN := $(shell command -v pipenv > /dev/null && echo pipenv run)

clean:
find . -name '*.pyc' -print0 | xargs -0 rm -f
Expand All @@ -9,21 +12,15 @@ clean:
-rm -rf .tox .coverage

install:
pip install .

dev:
pip install .[dev]

lint: pycodestyle pyflakes pylint
pip$(PIPENV) install .

pycodestyle:
-pycodestyle setup.py wxpusher
lint: flake8 pylint

pyflakes:
-pyflakes setup.py wxpusher
flake8:
${PIPRUN} flake8 setup.py wxpusher

pylint:
-pylint setup.py wxpusher
${PIPRUN} pylint setup.py wxpusher

test:
tox
Expand Down
18 changes: 18 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
flake8 = "*"
flake8-commas = "*"
flake8-docstrings = "*"
flake8-import-order = "*"
pep8-naming = "*"
pylint = "*"

[packages]
wxpusher = {editable = true,path = "."}

[requires]
python_version = "3"
5 changes: 4 additions & 1 deletion README-en.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ pip install -U wxpusher

```python
from wxpusher import WxPusher
WxPusher.send_message('<content>', '<uids>', '<appToken>')
WxPusher.send_message('<content>',
uids='<uids>',
topic_ids='<topic_ids>',
token='<appToken>')
WxPusher.query_message('<messageId>')
WxPusher.create_qrcode('<extra>', '<validTime>', '<appToken>')
WxPusher.query_user('<page>', '<page_size>', '<appToken>')
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ pip install -U wxpusher

```python
from wxpusher import WxPusher
WxPusher.send_message('<content>', '<uids>', '<appToken>')
WxPusher.send_message('<content>',
uids='<uids>',
topic_ids='<topic_ids>',
token='<appToken>')
WxPusher.query_message('<messageId>')
WxPusher.create_qrcode('<extra>', '<validTime>', '<appToken>')
WxPusher.query_user('<page>', '<page_size>', '<appToken>')
Expand Down
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

55 changes: 29 additions & 26 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,52 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Python packaging for wxpusher.
File: setup.py
Author: huxuan
Email: i(at)huxuan.org
Description: Python packaging for wxpusher.
"""
from pkg_resources import DistributionNotFound
from pkg_resources import get_distribution

from setuptools import setup

NAME = 'wxpusher'

CLASSIFIERS = [
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'License :: OSI Approved :: Apache Software License',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3 :: Only',
'Topic :: Utilities'
'Topic :: Utilities',
]

INSTALL_REQUIRES = [
'requests'
'requests',
]

DEV_REQUIRES = [
'pycodestyle',
'pyflakes',
'pylint'
]

TEST_REQUIRES = [
'coverage',
'nose'
]

EXTRAS_REQUIRE = {
'dev': DEV_REQUIRES,
'test': TEST_REQUIRES
}

DESCRIPTION = (
'WxPusher Python SDK.'
)

VERSION = open('VERSION').read().strip()
KEYWORDS = [
'wxpusher',
'wechat',
'weixin',
'notification',
'push-notification',
'python-sdk',
]

try:
VERSION = f'v{get_distribution(NAME).version}'
except DistributionNotFound:
VERSION = 'master'

PROJECT_URL = 'https://github.com/wxpusher/wxpusher-sdk-python'
BASE_URL = f'{PROJECT_URL}/blob/v{VERSION}'
BASE_URL = f'{PROJECT_URL}/blob/{VERSION}'


def readme():
Expand All @@ -54,19 +57,19 @@ def readme():
return content


setup(name='wxpusher',
version=VERSION,
setup(name=NAME,
description=DESCRIPTION,
long_description=readme(),
long_description_content_type='text/markdown',
classifiers=CLASSIFIERS,
keywords='wxpusher wechat push-notification',
url='https://github.com/wxpusher/wxpusher-sdk-python',
keywords=' '.join(KEYWORDS),
url=PROJECT_URL,
author='Xuan (Sean) Hu',
author_email='i+wxpusher@huxuan.org',
license='Apache License 2.0',
packages=['wxpusher'],
use_scm_version=True,
setup_requires=['setuptools_scm'],
install_requires=INSTALL_REQUIRES,
extras_require=EXTRAS_REQUIRE,
python_requires='>=3',
include_package_data=True)
15 changes: 13 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,21 @@
# and then run "tox" from this directory.

[tox]
envlist = py3
envlist = py3, lint-py3

[testenv]
deps =
.[test]
coverage
nose
pipenv
commands =
pipenv install --skip-lock
nosetests --with-coverage --cover-erase --cover-package=wxpusher

[testenv:lint-py3]
basepython = python3
deps =
pipenv
commands=
pipenv install --skip-lock --dev
pipenv run make lint
9 changes: 4 additions & 5 deletions wxpusher/__init__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Init for WxPusher.
File: __init__.py
Author: huxuan
Email: i(at)huxuan.org
Description: init for WxPusher.
"""
from .wxpusher import WxPusher
from .exceptions import WxPusherException
from .exceptions import WxPusherNoneTokenException
from .wxpusher import WxPusher

__all__ = [
'WxPusher',
'WxPusherException',
'WxPusherNoneTokenException'
'WxPusherNoneTokenException',
]

__version__ = open('VERSION').read().strip()
3 changes: 2 additions & 1 deletion wxpusher/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
WxPusher Exceptions.
File: exceptions.py
Author: huxuan
Email: i(at)huxuan.org
Description: WxPusher Exceptions.
"""


Expand Down
3 changes: 2 additions & 1 deletion wxpusher/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Init for unittest.
File: __init__.py
Author: huxuan
Email: i(at)huxuan.org
Description: Init for unittest.
"""
from . import exceptions

Expand Down
10 changes: 8 additions & 2 deletions wxpusher/tests/config.sample.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Unittest configuration sample.
File: config.sample.py
Author: huxuan
Email: i(at)huxuan.org
Description: Unittest configuration sample.
"""
# the `appToken` for test.
TOKEN = ''

# the `uids` for test, note that it should be a list.
UIDS = [
''
'',
]

# the `topic_ids` for test, note that it should be a list.
TOPIC_IDS = [
'',
]
3 changes: 2 additions & 1 deletion wxpusher/tests/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Custom exceptions for unittest.
File: exceptions.py
Author: huxuan
Email: i(at)huxuan.org
Description: Custom exceptions for unittest.
"""
from wxpusher import WxPusherException

Expand Down
6 changes: 4 additions & 2 deletions wxpusher/tests/test_create_qrcode.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Unittest for creating qrcode.
File: test_create_qrcode.py
Author: huxuan
Email: i(at)huxuan.org
Description: Unittest for creating qrcode.
"""
import unittest

Expand All @@ -18,12 +19,13 @@ class TestCreateQRCode(unittest.TestCase):

@classmethod
def setUpClass(cls):
"""Set up for class."""
WxPusher.default_token = config.TOKEN

def test_create_qrcode(self):
"""Positive case for creating qrcode."""
res = WxPusher.create_qrcode(
self.test_create_qrcode.__doc__
self.test_create_qrcode.__doc__,
)
self.assertIsInstance(res, dict)
self.assertIn('code', res)
Expand Down
5 changes: 3 additions & 2 deletions wxpusher/tests/test_query_message.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Unittest for querying message.
File: test_send_message.py
Author: huxuan
Email: i(at)huxuan.org
Description: Unittest for querying message.
"""
import unittest
import random
import unittest

from wxpusher import WxPusher

Expand Down
6 changes: 4 additions & 2 deletions wxpusher/tests/test_query_user.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Unittest for querying user.
File: test_send_message.py
Author: huxuan
Email: i(at)huxuan.org
Description: Unittest for querying user.
"""
import random
import unittest
Expand All @@ -19,12 +20,13 @@ class TestSendMessage(unittest.TestCase):

@classmethod
def setUpClass(cls):
"""Set up for class."""
WxPusher.default_token = config.TOKEN

def test_query_user(self):
"""Positive case for querying user."""
res = WxPusher.query_user(
1, random.randint(1, 99)
1, random.randint(1, 99),
)
self.assertIsInstance(res, dict)
self.assertIn('code', res)
Expand Down
Loading

0 comments on commit 1713c37

Please sign in to comment.