Commit 02c9078e authored by Mark Steadman's avatar Mark Steadman

Initial commit

parents
Pipeline #3838 passed with stages
in 1 minute and 17 seconds
# http://editorconfig.org
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
[*.{py,rst,ini}]
indent_style = space
indent_size = 4
[*.{html,css,scss,json,yml}]
indent_style = space
indent_size = 2
[*.md]
trim_trailing_whitespace = false
[Makefile]
indent_style = tab
*.py[cod]
__pycache__
.env
# C extensions
*.so
# Packages
*.egg
*.egg-info
dist
build
eggs
parts
bin
include
var
sdist
develop-eggs
.installed.cfg
lib
lib64
# Installer logs
pip-log.txt
# Unit test / coverage reports
.coverage
.tox
nosetests.xml
htmlcov
# Translations
*.mo
# Mr Developer
.mr.developer.cfg
.project
.pydevproject
# Pycharm/Intellij
.idea
# Complexity
output/*.html
output/*/index.html
# Sphinx
docs/_build
stages:
- qa
- test
- build
flake8:
stage: qa
image: python:3.6.3
before_script:
- pip install -e git+https://gitlab.com/pycqa/flake8@9631dac5#egg=flake8
script:
- flake8 ./webhooks
test_django1:
stage: test
image: python:3.6.3
before_script:
- pip install -qr requirements.txt
- pip install -q "Django<2.0" coverage mock
script:
- coverage run --source webhooks runtests.py && coverage report
test_django2:
stage: test
image: python:3.6.3
before_script:
- pip install -qr requirements.txt
- pip install -q django coverage mock
script:
- coverage run --source webhooks runtests.py && coverage report
build:
stage: build
image: python:3.6.3
before_script:
- pip install -qU twine setuptools wheel
script:
- python setup.py sdist
- twine upload dist/* -u ${PYPI_USERNAME} -p ${PYPI_PASSWORD} --skip-existing
MIT License
Copyright (c) 2018, Mark Steadman
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
include AUTHORS.rst
include CONTRIBUTING.rst
include HISTORY.rst
include LICENSE
include README.md
recursive-include webhooks *.html *.png *.gif *js *.css *jpg *jpeg *svg *py
Podiant webhooks
================
![Build](https://git.steadman.io/podiant/webhooks/badges/master/build.svg)
![Coverage](https://git.steadman.io/podiant/webhooks/badges/master/coverage.svg)
A super-simple, arbitrary webhook client
## Quickstart
Install Webhooks:
```sh
pip install podiant-webhooks
```
Add it to your `INSTALLED_APPS`:
```python
INSTALLED_APPS = (
...
'webhooks',
...
)
```
## Running tests
Does the code actually work?
```
coverage run --source webhooks runtests.py
```
## Credits
Tools used in rendering this package:
- [Cookiecutter](https://github.com/audreyr/cookiecutter)
- [`cookiecutter-djangopackage`](https://github.com/pydanny/cookiecutter-djangopackage)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, absolute_import
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tests.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
{"last_check":"2018-10-10T16:08:00Z","pypi_version":"18.1"}
\ No newline at end of file
home = /usr/local/Cellar/python/3.7.0/libexec/bin
include-system-site-packages = false
version = 3.7.0
requests==2.18.4
# Additional requirements go here
#!/usr/bin/env python
# -*- coding: utf-8
from __future__ import unicode_literals, absolute_import
import os
import sys
import django
from django.conf import settings
from django.test.utils import get_runner
def run_tests(*test_args):
if not test_args:
test_args = ['tests']
os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
django.setup()
TestRunner = get_runner(settings)
test_runner = TestRunner()
failures = test_runner.run_tests(test_args)
sys.exit(bool(failures))
if __name__ == '__main__':
run_tests(*sys.argv[1:])
[bumpversion]
current_version = 0.1.0
commit = True
tag = True
[bumpversion:file:webhooks/__init__.py]
[wheel]
universal = 1
[flake8]
ignore = D203
exclude =
webhooks/migrations,
.git,
.tox,
docs/conf.py,
build,
dist
max-line-length = 119
[coverage:report]
omit=*/management/commands/*.py,*/migrations/*.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import re
import sys
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
def get_version(*file_paths):
"""Retrieves the version from webhooks/__init__.py"""
filename = os.path.join(os.path.dirname(__file__), *file_paths)
version_file = open(filename).read()
version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]",
version_file, re.M)
if version_match:
return version_match.group(1)
raise RuntimeError('Unable to find version string.')
version = get_version("webhooks", "__init__.py")
if sys.argv[-1] == 'publish':
try:
import wheel
print("Wheel version: ", wheel.__version__)
except ImportError:
print('Wheel library missing. Please run "pip install wheel"')
sys.exit()
os.system('python setup.py sdist upload')
os.system('python setup.py bdist_wheel upload')
sys.exit()
if sys.argv[-1] == 'tag':
print("Tagging the version on git:")
os.system("git tag -a %s -m 'version %s'" % (version, version))
os.system("git push --tags")
sys.exit()
readme = open('README.md').read()
setup(
name='podiant-webhooks',
version=version,
description='A super-simple, arbitrary webhook client',
long_description=readme,
long_description_content_type='text/markdown',
author='Mark Steadman',
author_email='mark@podiant.co',
url='https://git.steadman.io/podiant/webhooks',
packages=['webhooks'],
include_package_data=True,
install_requires=[
'requests'
],
license="MIT",
zip_safe=False,
keywords='podiant-webhooks',
classifiers=[
'Development Status :: 3 - Alpha',
'Framework :: Django :: 1.11',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Natural Language :: English',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6'
]
)
# -*- coding: utf-8
from __future__ import unicode_literals, absolute_import
import os
DEBUG = True
USE_TZ = True
BASE_DIR = os.path.dirname(__file__)
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'uoiyd)o$0)pauxb-b%d732h2qwuknn0)#qrhcbx*b^*w6nquwb'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
}
}
ROOT_URLCONF = 'tests.urls'
INSTALLED_APPS = [
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sites',
'django.contrib.admin',
'webhooks'
]
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(BASE_DIR, 'templates')
],
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth'
],
'loaders': [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader'
],
'debug': DEBUG
}
}
]
SITE_ID = 1
MIDDLEWARE = ()
from django.test import TestCase
from mock import patch
from webhooks import send
from webhooks.models import Webhook
class SendTests(TestCase):
def setUp(self):
Webhook.objects.create(
url='http://example.com/wh',
name='example_webhook'
)
def test_send(self):
loc = {
'posted': False
}
def post(url, json):
loc['posted'] = True
with patch('requests.post', post):
send('example_webhook', {'foo': 'bar'})
self.assertTrue(loc['posted'])
from django.test import TestCase
from mock import patch
from webhooks.models import Webhook
class ModelTest(TestCase):
def test_str(self):
obj = Webhook(
url='http://example.com/wh',
name='example_webhook'
)
self.assertEqual(
str(obj),
'Example webhook'
)
def test_send(self):
obj = Webhook(
url='http://example.com/wh',
name='example_webhook'
)
loc = {
'posted': False
}
def post(url, json):
loc['posted'] = True
with patch('requests.post', post):
obj.send({'foo': 'bar'})
self.assertTrue(loc['posted'])
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, absolute_import
from django.conf.urls import url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls)
]
__version__ = '0.1.0'
def send(name, data):
from .models import Webhook
for webhook in Webhook.objects.filter(name=name):
webhook.send(data)
from django.contrib import admin
from .models import Webhook
@admin.register(Webhook)
class WebhookAdmin(admin.ModelAdmin):
list_display = ('name', '__str__', 'url')
# -*- coding: utf-8 -*-
# Generated by Django 1.11.8 on 2018-05-08 17:02
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Webhook',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.SlugField(max_length=100, unique=True)),
('url', models.URLField(max_length=511)),
],
),
]
from django.db import models
import requests
class Webhook(models.Model):
name = models.SlugField(max_length=100, unique=True)
url = models.URLField(max_length=511)
def __str__(self):
return self.name.replace('-', ' ').replace('_', ' ').capitalize()
def send(self, data):
requests.post(self.url, json=data)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment