Skip to content

Commit

Permalink
send and receive messages
Browse files Browse the repository at this point in the history
basic test cases
  • Loading branch information
abhishekram committed Apr 22, 2018
1 parent 3d5c094 commit 7abb13f
Show file tree
Hide file tree
Showing 26 changed files with 868 additions and 273 deletions.
8 changes: 8 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[run]
omit =
# Omit the django apps file
pyas2/apps.py

# Omit the django forms and admin file
pyas2/forms.py
pyas2/admin.py
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,6 @@ ENV/
.mypy_cache/
db.sqlite3
.idea/
messages/
messages/
.coverage
DS_Store
1 change: 1 addition & 0 deletions .pytest_cache/v/cache/lastfailed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
test:
@(py.test -s --cov-report term --cov-config .coveragerc --cov=linguist --color=yes pyas2/tests/ -k 'not concurrency')
@(py.test -s --cov-report term --cov-config .coveragerc --cov=pyas2 --color=yes pyas2/tests/ -k 'not concurrency')

serve:
@(ENV=example python manage.py migrate && python manage.py runserver)
Expand Down
2 changes: 2 additions & 0 deletions example/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
]

ROOT_URLCONF = 'example.urls'
# APPEND_SLASH = False

TEMPLATES = [
{
Expand Down Expand Up @@ -119,3 +120,4 @@
# https://docs.djangoproject.com/en/1.11/howto/static-files/

STATIC_URL = '/static/'

10 changes: 10 additions & 0 deletions pyas2/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version = (1, 0, 0)

__version__ = '.'.join(map(str, version))

default_app_config = 'pyas2.apps.Pyas2Config'

__all__ = [
'default_app_config',
'version',
]
15 changes: 10 additions & 5 deletions pyas2/forms.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import unicode_literals
from django import forms
from django.utils.translation import ugettext as _
from pyas2lib import Organization as AS2Organization, Partner as AS2Partner
from pyas2lib.as2 import Organization as As2Organization, Partner as As2Partner
from pyas2lib.exceptions import AS2Exception
from .models import Partner, PrivateKey, PublicCertificate
import os
Expand Down Expand Up @@ -76,7 +76,8 @@ def clean(self):
cleaned_data['key_file'] = key_file.read()

try:
AS2Organization.load_key(cleaned_data['key_file'],

As2Organization.load_key(cleaned_data['key_file'],
cleaned_data['key_pass'])
except AS2Exception as e:
raise forms.ValidationError(e.args[0])
Expand Down Expand Up @@ -140,9 +141,13 @@ def clean(self):
cleaned_data['cert_ca_file'] = cert_ca_file.read()

try:
AS2Partner.load_cert(cleaned_data['cert_file'],
cleaned_data['cert_ca_file'],
cleaned_data['verify_cert'])
partner = As2Partner(
'partner',
verify_cert=cleaned_data['cert_file'],
verify_cert_ca = cleaned_data['cert_ca_file'],
validate_certs = cleaned_data['verify_cert']
)
partner.load_verify_cert()
except AS2Exception as e:
raise forms.ValidationError(e.args[0])

Expand Down
6 changes: 4 additions & 2 deletions pyas2/management/commands/sendas2message.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,18 @@ def handle(self, *args, **options):

# Build and send the AS2 message
with open(options['path_to_payload'], 'rb') as in_file:
payload = in_file.read()
as2message = AS2Message(
sender=org.as2org, receiver=partner.as2partner)
as2message.build(
in_file.read(),
payload,
filename=os.path.basename(options['path_to_payload']),
subject=partner.subject,
content_type=partner.content_type
)
message = Message.objects.create_from_as2message(
message, _ = Message.objects.create_from_as2message(
as2message=as2message,
content=payload,
direction='OUT',
status='P'
)
Expand Down
17 changes: 9 additions & 8 deletions pyas2/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.10 on 2018-04-14 04:26
# Generated by Django 1.11.10 on 2018-04-21 11:03
from __future__ import unicode_literals

from django.db import migrations, models
Expand All @@ -18,13 +18,14 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='MDN',
fields=[
('mdn_id', models.CharField(max_length=100, primary_key=True, serialize=False)),
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('mdn_id', models.CharField(max_length=100)),
('timestamp', models.DateTimeField(auto_now_add=True)),
('status', models.CharField(choices=[('S', 'Sent'), ('R', 'Received'), ('P', 'Pending')], max_length=2)),
('signed', models.BooleanField(default=False)),
('return_url', models.URLField(null=True)),
('headers', models.FileField(blank=True, null=True, upload_to=pyas2.models.get_mdn_store)),
('payload', models.FileField(blank=True, null=True, upload_to=pyas2.models.get_mdn_store)),
('headers', models.FileField(blank=True, max_length=500, null=True, upload_to=pyas2.models.get_mdn_store)),
('payload', models.FileField(blank=True, max_length=500, null=True, upload_to=pyas2.models.get_mdn_store)),
],
),
migrations.CreateModel(
Expand All @@ -36,8 +37,8 @@ class Migration(migrations.Migration):
('timestamp', models.DateTimeField(auto_now_add=True)),
('status', models.CharField(choices=[('S', 'Success'), ('E', 'Error'), ('W', 'Warning'), ('P', 'Pending'), ('R', 'Retry')], max_length=2)),
('detailed_status', models.TextField(null=True)),
('headers', models.FileField(blank=True, null=True, upload_to=pyas2.models.get_message_store)),
('payload', models.FileField(blank=True, null=True, upload_to=pyas2.models.get_message_store)),
('headers', models.FileField(blank=True, max_length=500, null=True, upload_to=pyas2.models.get_message_store)),
('payload', models.FileField(blank=True, max_length=500, null=True, upload_to=pyas2.models.get_message_store)),
('compressed', models.BooleanField(default=False)),
('encrypted', models.BooleanField(default=False)),
('signed', models.BooleanField(default=False)),
Expand Down Expand Up @@ -69,10 +70,10 @@ class Migration(migrations.Migration):
('content_type', models.CharField(choices=[('application/EDI-X12', 'application/EDI-X12'), ('application/EDIFACT', 'application/EDIFACT'), ('application/edi-consent', 'application/edi-consent'), ('application/XML', 'application/XML')], default='application/edi-consent', max_length=100)),
('compress', models.BooleanField(default=False, verbose_name='Compress Message')),
('encryption', models.CharField(blank=True, choices=[('tripledes_192_cbc', '3DES'), ('rc2_128_cbc', 'RC2-128'), ('rc4_128_cbc', 'RC4-128')], max_length=20, null=True, verbose_name='Encrypt Message')),
('signature', models.CharField(blank=True, choices=[('sha1', 'SHA-1'), ('sha256', 'SHA-1')], max_length=20, null=True, verbose_name='Sign Message')),
('signature', models.CharField(blank=True, choices=[('sha1', 'SHA-1'), ('sha256', 'SHA-256')], max_length=20, null=True, verbose_name='Sign Message')),
('mdn', models.BooleanField(default=False, verbose_name='Request MDN')),
('mdn_mode', models.CharField(blank=True, choices=[('SYNC', 'Synchronous'), ('ASYNC', 'Asynchronous')], max_length=20, null=True)),
('mdn_sign', models.CharField(blank=True, choices=[('sha1', 'SHA-1'), ('sha256', 'SHA-1')], max_length=20, null=True, verbose_name='Request Signed MDN')),
('mdn_sign', models.CharField(blank=True, choices=[('sha1', 'SHA-1'), ('sha256', 'SHA-256')], max_length=20, null=True, verbose_name='Request Signed MDN')),
('confirmation_message', models.CharField(blank=True, help_text='Use this field to send a customized message in the MDN Confirmations for this Partner', max_length=300, null=True, verbose_name='Confirmation Message')),
('keep_filename', models.BooleanField(default=False, help_text='Use Original Filename to to store file on receipt, use this option only if you are sure partner sends unique names', verbose_name='Keep Original Filename')),
('cmd_send', models.TextField(blank=True, help_text='Command executed after successful message send, replacements are $filename, $sender, $recevier, $messageid and any message header such as $Subject', null=True, verbose_name='Command on Message Send')),
Expand Down
36 changes: 0 additions & 36 deletions pyas2/migrations/0002_auto_20180414_0558.py

This file was deleted.

25 changes: 0 additions & 25 deletions pyas2/migrations/0003_auto_20180414_1015.py

This file was deleted.

Loading

0 comments on commit 7abb13f

Please sign in to comment.