Skip to content

Commit

Permalink
Catch invalid fill data
Browse files Browse the repository at this point in the history
  • Loading branch information
agarrido19 committed Feb 5, 2020
1 parent 3d483ee commit 36716a6
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions dhlmex/resources/guides.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
class Guide(Resource):
@classmethod
def create_guide(
cls, origin: Origin, destination: Destination, details: OrderDetails,
cls, origin: Origin, destination: Destination,
details: OrderDetails,
) -> Tuple[str, Optional[bytes]]:
guide = cls()
try:
Expand Down Expand Up @@ -95,7 +96,8 @@ def _select_guide(self, guides_data: Dict) -> Dict:
return select_data

def _fill_guide_table(
self, origin: Origin, destination: Destination, details: OrderDetails
self, origin: Origin, destination: Destination,
details: OrderDetails
) -> str:
resp = self._client.get(self._urls['capture'])
soup = BeautifulSoup(resp.text, features='html.parser')
Expand Down Expand Up @@ -128,9 +130,19 @@ def _fill_guide_table(
fill_data['javax.faces.ViewState'] = view_state
fill_data['datos:j_id105'] = 'datos:j_id105'

self._client.post(self._urls['capture'], fill_data)
msg = self._validate_data()
if msg:
raise DhlmexException(f'Invalid data: {msg}')
else:
return fill_data['javax.faces.ViewState']

return fill_data['javax.faces.ViewState']
def _validate_data(self, fill_data: Dict) -> str:
resp = self._client.post(self._urls['capture'], fill_data)
if 'messageError' in resp.text:
soup = BeautifulSoup(resp.text, features='html.parser')
msg = soup.find('span', {'class': 'rich-messages-label'}).text
return msg
return ''

def _confirm_capture(self, view_state: str) -> Response:
confirm_data = {
Expand Down

0 comments on commit 36716a6

Please sign in to comment.