Skip to content

Commit

Permalink
Merge pull request #9 from tmconsulting/develop
Browse files Browse the repository at this point in the history
1.2.2 fixes from onelya
  • Loading branch information
roquie authored Apr 15, 2018
2 parents d38feac + 8b1041d commit 714bf51
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 12 deletions.
5 changes: 4 additions & 1 deletion onelya_sdk/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ def __init__(self, method, error_data, request_data):

self.code = error_data.get('Code')
self.message = error_data.get('Message').replace('request.', '')
self.message_params = self.__prettify_message_params(error_data, request_data)
try:
self.message_params = self.__prettify_message_params(error_data, request_data)
except:
self.message_params = 'Can\'t prettify message'

@staticmethod
def __prettify_message_params(error_data, request_data):
Expand Down
4 changes: 3 additions & 1 deletion onelya_sdk/railway/reservation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ def confirm(self, order_id: int, provider_payment_form: ProviderPaymentForm,
provider_payment_form=provider_payment_form)
return Confirm(response)

def blank(self, order_id: int, order_item_id: int, retrieve_main_services: bool=True, retrieve_upsales: bool=True):
def blank(self, order_id: int, order_item_id: int, order_item_ids: 'list of int', retrieve_main_services: bool=True,
retrieve_upsales: bool=True):

response = self.request_wrapper.make_request(BLANK_METHOD, order_id=order_id, order_item_id=order_item_id,
order_item_ids=order_item_ids,
retrieve_main_services=retrieve_main_services,
retrieve_upsales=retrieve_upsales)
return Blank(response)
Expand Down
26 changes: 21 additions & 5 deletions onelya_sdk/wrapper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def __init__(self, json_data):
self.international_service_classes = json_data.get('InternationalServiceClasses')
self.availability_indication = json_data.get('AvailabilityIndication')
self.is_three_hours_reservation_available = get_bool_item(json_data.get('IsThreeHoursReservationAvailable'))
self.is_deferred_payment_available = get_bool_item(json_data.get('IsDeferredPaymentAvailable'))
self.is_meal_option_possible = get_bool_item(json_data.get('IsMealOptionPossible'))
self.is_additional_meal_option_possible = get_bool_item(json_data.get('IsAdditionalMealOptionPossible'))
self.is_transit_document_required = get_bool_item(json_data.get('IsTransitDocumentRequired'))
Expand All @@ -118,6 +119,12 @@ def __init__(self, json_data):
self.json_data = json_data


class FreePlacesByCompartments(object):
def __init__(self, json_data):
self.compartment_number = get_array(json_data.get('CompartmentNumber'), int)
self.places = json_data.get('Places')


class CarPriceInfo(object):
def __init__(self, json_data):
self.car_type = json_data.get('CarType')
Expand All @@ -135,7 +142,7 @@ def __init__(self, json_data):
self.min_price = get_item(json_data.get('MinPrice'), float)
self.max_price = get_item(json_data.get('MaxPrice'), float)
self.service_cost = get_item(json_data.get('ServiceCost'), float)
self.free_places_by_compartments = json_data.get('FreePlacesByCompartments')
self.free_places_by_compartments = get_item(json_data.get('FreePlacesByCompartments'), FreePlacesByCompartments)
self.place_reservation_type = json_data.get('PlaceReservationType')
self.availability_indication = json_data.get('AvailabilityIndication')
self.carrier = json_data.get('Carrier')
Expand Down Expand Up @@ -342,8 +349,8 @@ def __init__(self, json_data):
class PassengerResponse(object):
def __init__(self, json_data):
self.category = json_data.get('Category')
self.places = json_data.get('Places')
self.place_tiers = json_data.get('PlaceTiers')
self.places = get_array(json_data.get('Places'), int)
self.place_tiers = get_array(json_data.get('PlaceTiers'), str)
self.places_with_type = get_item(json_data.get('PlacesWithType'), PlaceWithType)
self.tariff_type = json_data.get('TariffType')
self.first_name = json_data.get('FirstName')
Expand Down Expand Up @@ -380,6 +387,15 @@ def __init__(self, json_data):
self.json_data = json_data


class PrepaidMealInfo(object):
def __init__(self, json_data):
self.v = json_data.get('MealOptionCode')
self.v = json_data.get('MealName')
self.v = json_data.get('Description')

self.json_data = json_data


class ReservationBlankResponse(object):
def __init__(self, json_data):
self.order_item_blank_id = get_item(json_data.get('OrderItemBlankId'), int)
Expand All @@ -392,7 +408,7 @@ def __init__(self, json_data):
self.additional_price = get_item(json_data.get('AdditionalPrice'), float)
self.tariff_info = get_item(json_data.get('TariffInfo'), TicketTariffInfo)
self.tariff_additional_info = json_data.get('TariffAdditionalInfo')
self.prepaid_meal_info = json_data.get('PrepaidMealInfo')
self.prepaid_meal_info = get_item(json_data.get('PrepaidMealInfo'), PrepaidMealInfo)
self.service_price = get_item(json_data.get('ServicePrice'), float)

self.json_data = json_data
Expand Down Expand Up @@ -630,7 +646,7 @@ def __init__(self, json_data):
self.electronic_registration_set_date_time = get_datetime(json_data.get('ElectronicRegistrationSetDateTime'))
self.sign_sequence = json_data.get('SignSequence')
self.tariff_info = get_item(json_data.get('TariffInfo'), TicketTariffInfo)
self.prepaid_meal_info = json_data.get('PrepaidMealInfo')
self.prepaid_meal_info = get_item(json_data.get('PrepaidMealInfo'), PrepaidMealInfo)
self.transit_permission_approval_status = json_data.get('TransitPermissionApprovalStatus')
self.place_quantity = json_data.get('PlaceQuantity')
self.order_item_blank_id = json_data.get('OrderItemBlankId')
Expand Down
6 changes: 6 additions & 0 deletions onelya_sdk/wrapper/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ class TariffType:
CHILD = 'Child'


class RailwayTransitPermissionApprovalStatus:
NO_VALUE = 'NoValue'
ACCEPTED = 'Accepted'
REJECTED = 'Rejected'


class MealTime:
BREAKFAST = 'Breakfast'
LUNCH = 'Lunch'
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup, find_packages

__version__ = '1.2.1'
__version__ = '1.2.2'

setup(
version=__version__,
Expand Down
8 changes: 6 additions & 2 deletions tests/data/Order/Reservation/Blank.in.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"OrderId": 1,
"OrderItemId": 2,
"OrderId": 52157,
"OrderItemId": null,
"OrderItemIds": [
55234,
55238
],
"RetrieveMainServices": true,
"RetrieveUpsales": true
}
1 change: 1 addition & 0 deletions tests/data/Railway/Search/TrainPricing.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"TwoPlacesAtOnce"
],
"IsThreeHoursReservationAvailable": false,
"IsDeferredPaymentAvailable": false,
"IsMealOptionPossible": false,
"IsAdditionalMealOptionPossible": false,
"IsTransitDocumentRequired": false,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def test_reservation_confirm(self):
@mock.patch('requests.Session', MockFileSession)
def test_reservation_blank(self):
api = API(self.username, self.password, self.pos)
blank = api.railway_reservation.blank(1, 2)
blank = api.railway_reservation.blank(52157, None, [55234, 55238])

input_data = json.loads(open('tests/data/Order/Reservation/Blank.in.json', 'r', encoding='utf8').read())
pdf_file = open(PDF_PATH, 'rb').read()
Expand Down Expand Up @@ -387,7 +387,7 @@ def test_aeroexpress_reservation_confirm(self):
@mock.patch('requests.Session', MockFileSession)
def test_aeroexpress_reservation_blank(self):
api = API(self.username, self.password, self.pos)
blank = api.railway_reservation.blank(1, 2)
blank = api.aeroexpress_reservation.blank(1, 2)

input_data = json.loads(open('tests/data/Aeroexpress/Order/Reservation/Blank.in.json', 'r', encoding='utf8').read())
pdf_file = open(PDF_PATH, 'rb').read()
Expand Down

0 comments on commit 714bf51

Please sign in to comment.