Skip to content

Commit

Permalink
Merge pull request #111 from mdsol/feature/error_origin_location
Browse files Browse the repository at this point in the history
feature/error_origin_location - travis-ci doesn't seem to be reporting correctly
  • Loading branch information
glow-mdsol committed Mar 9, 2021
2 parents 655c37d + 20ce3f5 commit ef21eb4
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 20 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ htmlcov

# VirtualEnvs!
venv

# Pyenv
.python-version
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
language: python
python:
- 3.5
- 3.6
- 3.7
- 3.8
- 3.9
install: python setup.py install
script: python setup.py test
deploy:
Expand Down
3 changes: 0 additions & 3 deletions __init__.py

This file was deleted.

1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
lxml
requests
six
enum34; python_version < '3.4'
click
faker
13 changes: 7 additions & 6 deletions rwslib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

__title__ = "rwslib"
__author__ = "Ian Sparks (isparks@trialgrid.com)"
__version__ = "1.2.6"
__maintainer__ = "Geoff Low (glow@mdsol.com)"
__version__ = "1.2.7"
__license__ = "MIT"
__copyright__ = "Copyright 2017 Medidata Solutions Inc"
__copyright__ = "Copyright 2021 Medidata Solutions Inc"


import requests

from .rws_requests import RWSRequest, make_url
from .rwsobjects import RWSException, RWSError, RWSErrorResponse
from .rwsobjects import RWSException, RWSError, RWSErrorResponse, RWSPostErrorResponse

import time

Expand Down Expand Up @@ -127,7 +128,7 @@ def send_request(self, request_object, timeout=None, retries=1, **kwargs):
if r.status_code in [400, 404]:
# Is it a RWS response?
if r.text.startswith("<Response"):
error = RWSErrorResponse(r.text)
error = RWSErrorResponse(r.text) if request_object.method == "GET" else RWSPostErrorResponse(r.text)
raise RWSException(error.errordescription, error)
elif "<html" in r.text:
raise RWSException("IIS Error", r.text)
Expand Down Expand Up @@ -155,7 +156,7 @@ def send_request(self, request_object, timeout=None, retries=1, **kwargs):
if r.headers.get("content-type").startswith("text/xml"):
# XML response
if r.text.startswith("<Response"):
error = RWSErrorResponse(r.text)
error = RWSErrorResponse(r.text) if request_object.method == "GET" else RWSPostErrorResponse(r.text)
elif "ODM" in r.text:
error = RWSError(r.text)
else:
Expand All @@ -168,7 +169,7 @@ def send_request(self, request_object, timeout=None, retries=1, **kwargs):
if "<" in r.text:
# XML like
if r.text.strip().startswith("<Response"):
error = RWSErrorResponse(r.text)
error = RWSErrorResponse(r.text) if request_object.method == "GET" else RWSPostErrorResponse(r.text)
elif "ODM" in r.text:
error = RWSError(r.text)
else:
Expand Down
4 changes: 2 additions & 2 deletions rwslib/builders/admindata.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def build(self, builder):
:param builder:
:return:
"""
builder.start(self.__class__.__name__)
builder.start(self.__class__.__name__, {})
builder.data(self.text)
builder.end(self.__class__.__name__)

Expand Down Expand Up @@ -372,7 +372,7 @@ def build(self, builder):
:param builder:
:return:
"""
builder.start(self.__class__.__name__)
builder.start(self.__class__.__name__, {})
builder.data(self.country_code)
builder.end(self.__class__.__name__)

Expand Down
2 changes: 1 addition & 1 deletion rwslib/builders/clinicaldata.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ def build(self, builder):
"""
Build XML by appending to builder
"""
builder.start("Annotations")
builder.start("Annotations", {})

# populate the flags
for annotation in self.annotations:
Expand Down
4 changes: 2 additions & 2 deletions rwslib/rwsobjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def __init__(self, xml):
self.draft_imported = r_get("DraftImported")


class RWSPostErrorResponse(RWSResponse):
class RWSPostErrorResponse(RWSErrorResponse):
"""
Responses to Clinical data post messages have additional Attributes to normal RWS Response messages:
Expand All @@ -262,7 +262,7 @@ def __init__(self, xml):
"""
:param str xml: Error response
"""
RWSResponse.__init__(self, xml)
RWSErrorResponse.__init__(self, xml)

# Get additional properties
r_get = self.root.get
Expand Down
6 changes: 6 additions & 0 deletions rwslib/tests/test_rwslib.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import rwslib
from rwslib.rws_requests import StudyDatasetRequest
from rwslib.rwsobjects import RWSPostErrorResponse


# TODO: per the Repository, httpretty is not supporting Python3 - do we need to replace?
Expand Down Expand Up @@ -180,6 +181,11 @@ def test_400_error_error_response(self):
with self.assertRaises(rwslib.RWSException) as exc:
v = rave.send_request(rwslib.rws_requests.PostDataRequest("<ODM/>"))
self.assertEqual("Subject already exists.", str(exc.exception))
rws_error = exc.exception.rws_error
self.assertEqual("/ODM/ClinicalData[1]/SubjectData[1]", str(rws_error.error_origin_location))
self.assertEqual("RWS00024", str(rws_error.reasoncode))
self.assertTrue(isinstance(rws_error, (RWSPostErrorResponse, )))
self.assertFalse(rws_error.istransactionsuccessful)

@httpretty.activate
def test_400_error_iis_error(self):
Expand Down
2 changes: 2 additions & 0 deletions rwslib/tests/test_rwsobjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@ def test_parse(self):
self.assertEqual(
"/ODM/ClinicalData[1]/SubjectData[1]", parsed.error_origin_location
)
self.assertEqual("RWS00024", parsed.reason_code)
self.assertEqual("RWS00024", parsed.reasoncode)


class TestRWSStudies(unittest.TestCase):
Expand Down
10 changes: 7 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@

rwsinit = open("rwslib/__init__.py").read()
author = re.search(r"__author__ = \"([^\"]+)\"", rwsinit).group(1)
author_email = re.search('\(([^\)]+)', author).group(1)
maintainer = re.search(r"__maintainer__ = \"([^\"]+)\"", rwsinit).group(1)
maintainer_email = re.search('\(([^\)]+)', maintainer).group(1)
version = re.search(r"__version__ = \"([^\"]+)\"", rwsinit).group(1)

with open("README.md", "r") as fh:
Expand All @@ -36,7 +39,9 @@
long_description=long_description,
long_description_content_type="text/markdown",
author=author,
author_email="isparks@trialgrid.com",
author_email=author_email,
maintainer=maintainer,
maintainer_email=maintainer_email,
packages=packages,
package_dir={"rwslib": "rwslib"},
include_package_data=True,
Expand All @@ -45,7 +50,6 @@
'six',
'click',
'faker',
"enum34; python_version < '3.4'",
],
tests_require=['mock', 'httpretty'],
license="MIT License",
Expand All @@ -58,10 +62,10 @@
'Natural Language :: English',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
],
entry_points="""
[console_scripts]
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# and then run "tox" from this directory.

[tox]
envlist = clean, py35, py36, py37, py38, anaconda3, stats
envlist = clean, py36, py37, py38, py39, anaconda3, stats
recreate = true

[testenv]
Expand Down

0 comments on commit ef21eb4

Please sign in to comment.