Skip to content

Commit 95d80c0

Browse files
authored
Merge pull request #70 from abhishek-ram/abhishek-use-github-actions
Multiple changs for a new release
2 parents a83590e + d2851e3 commit 95d80c0

File tree

16 files changed

+181
-74
lines changed

16 files changed

+181
-74
lines changed

.github/workflows/run-tests.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Run Tests
2+
on:
3+
push:
4+
branches:
5+
- "master"
6+
pull_request:
7+
branches:
8+
- "master"
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
python-version: [3.7, 3.8, 3.9, "3.10"]
15+
steps:
16+
- uses: actions/checkout@v2
17+
- name: Set up Python ${{ matrix.python-version }}
18+
uses: actions/setup-python@v2
19+
with:
20+
python-version: ${{ matrix.python-version }}
21+
- name: Install dependencies
22+
run: |
23+
python -m pip install --upgrade pip
24+
pip install -e ".[tests]"
25+
- name: Run Tests
26+
run: |
27+
pytest --cov-report term --cov-config .coveragerc --cov=pyas2 --black --pylama pyas2
28+
- name: Generate CodeCov Report
29+
run: |
30+
pip install codecov
31+
codecov

.travis.yml

Lines changed: 0 additions & 14 deletions
This file was deleted.

AUTHORS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
* Abhishek Ram <abhishek.ram@me.com> @abhishek-ram
1+
* Abhishek Ram <abhishek.ram@me.com> @abhishek-ram
2+
* Wassilios Lytras @chadgates

README.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ django-pyAS2
1111
.. image:: https://travis-ci.org/abhishek-ram/django-pyas2.svg?branch=master
1212
:target: https://travis-ci.org/abhishek-ram/django-pyas2
1313

14+
.. image:: https://github.com/abhishek-ram/django-pyas2/actions/workflows/run-tests.yml/badge.svg?branch=master&event=push
15+
:target: https://github.com/abhishek-ram/django-pyas2/actions/workflows/run-tests.yml?query=branch%3Amaster++
16+
1417
.. image:: https://codecov.io/gh/abhishek-ram/django-pyas2/branch/master/graph/badge.svg
1518
:target: https://codecov.io/gh/abhishek-ram/django-pyas2
1619

example/settings.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,6 @@
116116

117117
USE_I18N = True
118118

119-
USE_L10N = True
120-
121119
USE_TZ = True
122120

123121

pyas2/admin.py

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@
1919

2020
@admin.register(PrivateKey)
2121
class PrivateKeyAdmin(admin.ModelAdmin):
22+
"""Admin class for the PrivateKey model."""
23+
2224
form = PrivateKeyForm
2325
list_display = ("name", "valid_from", "valid_to", "serial_number", "download_key")
2426

25-
def download_key(self, obj):
27+
@staticmethod
28+
def download_key(obj):
29+
"""Return the url to download the private key."""
2630
download_url = reverse_lazy("download-file", args=["private_key", obj.id])
2731
return format_html(
2832
'<a href="{}" class="button">Click to Download</a>', download_url
@@ -34,10 +38,14 @@ def download_key(self, obj):
3438

3539
@admin.register(PublicCertificate)
3640
class PublicCertificateAdmin(admin.ModelAdmin):
41+
"""Admin class for the PublicCertificate model."""
42+
3743
form = PublicCertificateForm
3844
list_display = ("name", "valid_from", "valid_to", "serial_number", "download_cert")
3945

40-
def download_cert(self, obj):
46+
@staticmethod
47+
def download_cert(obj):
48+
"""Return the url to download the public cert."""
4149
download_url = reverse_lazy("download-file", args=["public_cert", obj.id])
4250
return format_html(
4351
'<a href="{}" class="button">Click to Download</a>', download_url
@@ -49,6 +57,8 @@ def download_cert(self, obj):
4957

5058
@admin.register(Partner)
5159
class PartnerAdmin(admin.ModelAdmin):
60+
"""Admin class for the Partner model."""
61+
5262
form = PartnerForm
5363
list_display = [
5464
"name",
@@ -119,7 +129,8 @@ class PartnerAdmin(admin.ModelAdmin):
119129
)
120130
actions = ["send_message"]
121131

122-
def send_message(self, request, queryset):
132+
def send_message(self, request, queryset): # pylint: disable=W0613,R0201
133+
"""Send the message to the first partner chosen by the user."""
123134
partner = queryset.first()
124135
return HttpResponseRedirect(
125136
reverse_lazy("as2-send") + "?partner_id=%s" % partner.as2_name
@@ -130,14 +141,15 @@ def send_message(self, request, queryset):
130141

131142
@admin.register(Organization)
132143
class OrganizationAdmin(admin.ModelAdmin):
144+
"""Admin class for the Organization model."""
145+
133146
list_display = ["name", "as2_name"]
134147
list_filter = ("name", "as2_name")
135148

136149

137150
@admin.register(Message)
138151
class MessageAdmin(admin.ModelAdmin):
139-
def has_add_permission(self, request):
140-
return False
152+
"""Admin class for the Message model."""
141153

142154
search_fields = ("message_id", "payload")
143155

@@ -157,36 +169,49 @@ def has_add_permission(self, request):
157169
"mdn_url",
158170
]
159171

160-
def mdn_url(self, obj):
172+
@staticmethod
173+
def mdn_url(obj):
174+
"""Return the URL to the related MDN if present for the message."""
175+
# pylint: disable=W0212
176+
161177
if hasattr(obj, "mdn"):
162178
view_url = reverse_lazy(
163179
f"admin:{Mdn._meta.app_label}_{Mdn._meta.model_name}_change",
164180
args=[obj.mdn.id],
165181
)
166182
return format_html('<a href="{}" class="">{}</a>', view_url, obj.mdn.mdn_id)
183+
return None
167184

168185
mdn_url.allow_tags = True
169186
mdn_url.short_description = "MDN"
170187

171-
def download_file(self, obj):
188+
@staticmethod
189+
def download_file(obj):
190+
"""Return the URL to download the message payload."""
172191
if obj.payload:
173192
view_url = reverse_lazy("download-file", args=["message_payload", obj.id])
174193
return format_html(
175194
'<a href="{}">{}</a>', view_url, os.path.basename(obj.payload.name)
176195
)
196+
return None
177197

178198
download_file.allow_tags = True
179199
download_file.short_description = "Payload"
180200

201+
def has_add_permission(self, request):
202+
return False
203+
181204

182205
@admin.register(Mdn)
183206
class MdnAdmin(admin.ModelAdmin):
184-
def has_add_permission(self, request):
185-
return False
207+
"""Admin class for the Mdn model."""
186208

187209
search_fields = (
188210
"mdn_id",
189211
"message__message_id",
190212
)
191213
list_display = ("mdn_id", "message", "timestamp", "status")
192214
list_filter = ("status",)
215+
216+
def has_add_permission(self, request):
217+
return False

pyas2/apps.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
# -*- coding: utf-8 -*-
21
from django.apps import AppConfig
32

43

54
class Pyas2Config(AppConfig):
5+
"""App config for the pyas2 app."""
6+
67
name = "pyas2"
78
verbose_name = "pyAS2 File Transfer Server"
8-
9-
def ready(self):
10-
super(Pyas2Config, self).ready()

pyas2/forms.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212

1313

1414
class PartnerForm(forms.ModelForm):
15+
"""Form for creating and editing AS2 partners."""
16+
1517
def clean(self):
16-
cleaned_data = super(PartnerForm, self).clean()
18+
cleaned_data = super().clean()
1719

1820
# If http auth is set and credentials are missing raise error
1921
if cleaned_data.get("http_auth"):
@@ -57,14 +59,19 @@ def clean(self):
5759
return cleaned_data
5860

5961
class Meta:
62+
"""Define additional config for the PartnerForm class."""
63+
6064
model = Partner
6165
exclude = []
6266

6367

6468
class PrivateKeyForm(forms.ModelForm):
69+
"""Form for creating and editing AS2 Organization private keys."""
70+
6571
key_file = forms.FileField()
6672

6773
def clean_key_file(self):
74+
"""Validate that uploaded private key has the right extension."""
6875
key_file = self.cleaned_data["key_file"]
6976

7077
ext = os.path.splitext(key_file.name)[1]
@@ -78,7 +85,7 @@ def clean_key_file(self):
7885
return key_file
7986

8087
def clean(self):
81-
cleaned_data = super(PrivateKeyForm, self).clean()
88+
cleaned_data = super().clean()
8289
key_file = cleaned_data.get("key_file")
8390

8491
if key_file:
@@ -96,14 +103,16 @@ def clean(self):
96103
return cleaned_data
97104

98105
def save(self, commit=True):
99-
instance = super(PrivateKeyForm, self).save(commit=False)
106+
instance = super().save(commit=False)
100107
instance.name = self.cleaned_data["key_filename"]
101108
instance.key = self.cleaned_data["key_file"]
102109
if commit:
103110
instance.save()
104111
return instance
105112

106113
class Meta:
114+
"""Define additional config for the PrivateKeyForm class."""
115+
107116
model = PrivateKey
108117
fields = ["key_file", "key_pass"]
109118
widgets = {
@@ -112,10 +121,13 @@ class Meta:
112121

113122

114123
class PublicCertificateForm(forms.ModelForm):
124+
"""Form for creating and editing AS2 Partner public certs."""
125+
115126
cert_file = forms.FileField(label="Certificate File")
116127
cert_ca_file = forms.FileField(label="Certificate CA File", required=False)
117128

118129
def clean_cert_file(self):
130+
"""Validate that uploaded cert file has the right extension."""
119131
cert_file = self.cleaned_data["cert_file"]
120132

121133
ext = os.path.splitext(cert_file.name)[1]
@@ -130,6 +142,7 @@ def clean_cert_file(self):
130142
return cert_file
131143

132144
def clean_cert_ca_file(self):
145+
"""Validate that uploaded cert ca file has the right extension."""
133146
cert_ca_file = self.cleaned_data["cert_ca_file"]
134147

135148
if cert_ca_file:
@@ -148,7 +161,7 @@ def clean_cert_ca_file(self):
148161
return cert_ca_file
149162

150163
def clean(self):
151-
cleaned_data = super(PublicCertificateForm, self).clean()
164+
cleaned_data = super().clean()
152165
cert_file = cleaned_data.get("cert_file")
153166
cert_ca_file = cleaned_data.get("cert_ca_file", "")
154167

@@ -173,7 +186,7 @@ def clean(self):
173186
return cleaned_data
174187

175188
def save(self, commit=True):
176-
instance = super(PublicCertificateForm, self).save(commit=False)
189+
instance = super().save(commit=False)
177190
instance.name = self.cleaned_data["cert_filename"]
178191
instance.certificate = self.cleaned_data["cert_file"]
179192

@@ -185,11 +198,15 @@ def save(self, commit=True):
185198
return instance
186199

187200
class Meta:
201+
"""Define additional config for the PublicCertificateForm class."""
202+
188203
model = PublicCertificate
189204
fields = ["cert_file", "cert_ca_file", "verify_cert"]
190205

191206

192207
class SendAs2MessageForm(forms.Form):
208+
"""Form for sending AS2 messages to Partners from the Admin."""
209+
193210
organization = forms.ModelChoiceField(
194211
queryset=Organization.objects.all(), empty_label=None
195212
)

pyas2/management/commands/manageas2server.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import os
2-
import requests
3-
from email.parser import BytesHeaderParser
42
from datetime import timedelta
3+
from email.parser import BytesHeaderParser
4+
5+
import requests
56
from django.core.management.base import BaseCommand
67
from django.utils import timezone
78
from pyas2lib import Message as AS2Message
@@ -11,6 +12,8 @@
1112

1213

1314
class Command(BaseCommand):
15+
"""Command to manage the django pyas2 server."""
16+
1417
help = (
1518
"Command to manage the as2 server, includes options to cleanup, "
1619
"handle async mdns and message retries"
@@ -43,6 +46,7 @@ def add_arguments(self, parser):
4346
)
4447

4548
def retry(self, retry_msg):
49+
"""Retry sending the message to the partner."""
4650
# Increase the retry count
4751
if not retry_msg.retries:
4852
retry_msg.retries = 1
@@ -146,10 +150,10 @@ def handle(self, *args, **options):
146150
for pending_msg in out_pending_msgs:
147151
self.retry(pending_msg)
148152

149-
self.stdout.write(u"Successfully processed all pending mdns.")
153+
self.stdout.write("Successfully processed all pending mdns.")
150154

151155
if options["clean"]:
152-
self.stdout.write(u"Cleanup maintenance process started")
156+
self.stdout.write("Cleanup maintenance process started")
153157
max_archive_dt = timezone.now() - timedelta(settings.MAX_ARCH_DAYS)
154158
self.stdout.write(
155159
"Delete all messages older than %s" % settings.MAX_ARCH_DAYS

pyas2/management/commands/sendas2bulk.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010

1111
class Command(BaseCommand):
12+
"""Command to send all pending messages."""
13+
1214
help = "Command for sending all pending messages in the outbox folders"
1315

1416
def handle(self, *args, **options):

0 commit comments

Comments
 (0)