Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
language: python
sudo: required
dist: xenial

python:
- 3.4
- 3.5
- 3.6
- 3.7

install:
- pip install -r requirements.txt
Expand Down
13 changes: 12 additions & 1 deletion mifiel/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
import mimetypes
from os.path import basename
import requests
try:
import simplejson as json
except ImportError:
import json

class Document(Base):
def __init__(self, client):
Expand Down Expand Up @@ -68,7 +72,14 @@ def request_signature(self, signer, cc=None):
def delete(client, doc_id):
base = Document(client)
response = base.execute_request('delete', url=base.url(doc_id))
return response.json()
try:
return response.json()
except json.JSONDecodeError:
if response.status_code in [204, 205]:
# if the response body is empty returns a dictionary with the success response
return {'status': 'success'}
else:
return response.text

@staticmethod
def create_from_template(client, args={}):
Expand Down
24 changes: 21 additions & 3 deletions test/mifiellib/test_document.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from mifiel import Document
from mifiellib import BaseMifielCase

import json
import responses
import os.path

try:
import simplejson as json
except ImportError:
import json

class TestDocument(BaseMifielCase):
def setUp(self):
super(TestDocument, self).setUp()
Expand Down Expand Up @@ -81,7 +85,21 @@ def test_all(self):
self.assertEqual(len(docs), 1)

@responses.activate
def test_delete(self):
def test_delete_empty_response(self):
url = self.client.url().format(path='documents')
url = '{}/{}'.format(url, 'some-doc-id')
responses.add(
method=responses.DELETE,
url=url,
body='',
status=205,
content_type='application/json',
)
response = Document.delete(self.client, 'some-doc-id')
self.assertEqual(response['status'], 'success')

@responses.activate
def test_delete_json_response(self):
url = self.client.url().format(path='documents')
url = '{}/{}'.format(url, 'some-doc-id')
responses.add(
Expand All @@ -90,7 +108,7 @@ def test_delete(self):
body=json.dumps({
'status': 'success',
'message': 'Destroyed document#some-doc-id',
'data': { 'id': 'some-doc-id'}
'data': {'id': 'some-doc-id'}
}),
status=200,
content_type='application/json',
Expand Down