Example #1
0
def create_item(data, raw_data=False, do_not_create=False):
    address = get_service_address(ServiceNames.CatalogService)
    request_url = "http://%s/items/" % (address)
    _data = data if raw_data is True else serializers.get_raw_data(data)
    response = requests.post(request_url, data=_data)
    if do_not_create is True:
        return response.text, response.status_code

    # TODO
    return "dto.Item(**response.json())"
Example #2
0
def perform_payment(order_id: int, data, raw_data=False, do_not_create=False):
    address = get_service_address(ServiceNames.PaymentService)
    request_url = "http://%s/orders/%s/payment/" % (address, order_id)
    _data = data if raw_data is True else serializers.get_raw_data(data)
    response = requests.put(request_url, data=_data)
    if do_not_create is True:
        return response.text, response.status_code

    # TODO check status code
    # if response.status_code == 500:
    #     return response.text

    return serializers.OrderIdSerializer.create(validated_data=response.text)
Example #3
0
def add_item_to_order(order_id: int,
                      data,
                      raw_data=False,
                      do_not_create=False):
    address = get_service_address(ServiceNames.OrderService)
    request_url = "http://%s/orders/%s/item/" % (address, order_id)
    _data = data if raw_data is True else serializers.get_raw_data(data)
    response = requests.post(request_url, data=_data)
    if do_not_create is True:
        return response.text, response.status_code

    # TODO
    return "dto.OrderId(**response.json())"