Example #1
0
def create_time_bomb_validation(request_data):
    if 'time_bomb' not in request_data:
        raise DataValidationError('Request data invalid', None)
    if 'time_bomb_content_en' not in request_data['time_bomb']:
        raise DataValidationError('Request data invalid', None)
    if 'time_bomb_content_cn' not in request_data['time_bomb']:
        raise DataValidationError('Request data invalid', None)
Example #2
0
def dada_order_add_tip_validation(request_data):
    if 'order_id' not in request_data:
        raise DataValidationError('Request data invalid', None)
    if 'tips' not in request_data or 'tips' not in request_data:
        raise DataValidationError('Request data invalid', None)
    if 'city_code' not in request_data or 'info' not in request_data:
        raise DataValidationError('Request data invalid', None)
def request_validation(open_id, request_data):
    if open_id is None:
        raise DataValidationError('Request data invalid', None)

    if 'type' not in request_data or 'name' not in request_data or 'tax_id_number' not in request_data:
        raise DataValidationError('Request data invalid', None)

    if request_data['type'] == 0 and len(request_data['name']) == 0:
        raise DataValidationError('Request data invalid', None)
Example #4
0
def page_list_update_post_validation(request_data):
    if 'curation_pages' not in request_data:
        raise DataValidationError('Required parameter is not found', None)

    page_list = request_data['curation_pages']

    for page in page_list:
        if 'status' not in page or 'id' not in page or 'list_index' not in page:
            raise DataValidationError('Required parameter is not found', None)
Example #5
0
def dada_new_order_validation(request_data):
    if 'order_id' not in request_data:
        raise DataValidationError('Request data invalid', None)
    if 'cargo_weight' not in request_data or 'tips' not in request_data:
        raise DataValidationError('Request data invalid', None)
    if 'is_use_insurance' not in request_data or 'info' not in request_data:
        raise DataValidationError('Request data invalid', None)
    if 'receiver_address' not in request_data:
        raise DataValidationError('Request data invalid', None)
    if 'receiver_lat' not in request_data or 'receiver_lng' not in request_data:
        raise DataValidationError('Request data invalid', None)
    def get_open_id_from_unique_id(self, share_id):
        referral_event = self.referral_service.read_referral_with_unique_id(share_id)

        if referral_event is None:
            raise DataValidationError('Do not find unique id', None)

        referral_result = {'open_id': referral_event.open_id, 'share_id': referral_event.share_id}

        return referral_result
    def set_delivery_detail(self, cn_header):
        # Shipping method
        self.request_data['shipping_method'] = 1
        if 'delivery_on_site' in self.request_data:
            delivery_on_site = self.request_data['delivery_on_site']
        else:
            delivery_on_site = False
            self.request_data['delivery_on_site'] = False

        if delivery_on_site:
            delivery_type = 2
            self.request_data['shipping_method'] = 2
            self.request_data['shipping_cost'] = 0.0
            self.request_data['delivery_as_fast'] = False
        else:
            self.request_data['shipping_cost'] = 8.0
            delivery_type = self.request_data['shipping_method']

        # add shipping name
        delivery_name = hub_data.get_delivery_service_str(cn_header, delivery_type)
        self.request_data['shipping_name'] = delivery_name

        delivery_price = self.request_data['shipping_cost']

        # Check delivery price
        if float(hub_data.get_shipping_cost(delivery_type)) != float(delivery_price):
            self.logger_info.info('Some cost is incorrect')
            raise DataValidationError('Some costs are incorrect')

        delivery_detail_json = {'delivery_title': hub_data.get_delivery_str(cn_header, delivery_type),
                                'price': delivery_price}
        self.order_details['delivery_detail'] = delivery_detail_json

        delivery_date = self.request_data['delivery_date'].replace('.', '-')
        self.request_data['delivery_date'] = delivery_date

        time_table_delivery_type = delivery_type
        if delivery_on_site:
            time_table_delivery_type = 1

        time_table_address = '{}/{}/{}/{}/{}'.format(
            urlmapper.get_url('TIMETABLE_LIST'), str(self.request_data['hub_id']), delivery_date,
            str(self.request_data['delivery_schedule']), str(time_table_delivery_type)
        )

        response = requests.get(time_table_address)
        response_json = response.json()

        if response.status_code != code.ARIES_200_SUCCESS:
            self.logger_error.error(code.ERROR_3007_DELIVERY_SCHEDULE_INVALID)
            raise BusinessLogicError(message_mapper.get(3007, cn_header), 3007, None)

        self.logger_info.info(response_json)
        self.request_data['shipping_detail'] = json.dumps(response_json['shipping_detail'])
        self.request_data['delivery_start_time'] = response_json['delivery_start_time']
        self.request_data['delivery_end_time'] = response_json['delivery_end_time']
Example #8
0
    def request_validation(self, request_data):
        if self.open_id is None or self.access_token is None:
            raise AuthInfoError

        serializer = PurchaseOrderRequestSerializer(data=request_data)

        if not serializer.is_valid():
            raise DataValidationError('Request data invalid', None)

        if 'product_list' not in request_data \
                or 'coupon_list' not in request_data \
                or 'delivery_date' not in request_data:
            raise DataValidationError('Request data invalid', None)

        self.request_data = request_data

        if not request_user_validation(self.open_id, self.access_token):
            raise AuthInfoError

        self.request_data['open_id'] = self.open_id
Example #9
0
    def get_product_validation(self, discount_info_list):
        """
        Check product is available or not
        :param discount_info_list: Discount info from time bomb
        :return: If available, true or not.
        """
        product_service = ProductService(self.logger_info, self.logger_error, 'default')

        for discount_info in discount_info_list:
            if not product_service.has_product(discount_info['product_id']):
                raise DataValidationError('Request data invalid', None)
    def save_purchase_order(self):
        # No purchase order object. Create new one.
        serializer = PurchaseOrderSerializer(data=self.request_data)

        if not serializer.is_valid():
            self.logger_info.info(serializer.errors)
            raise DataValidationError('Request data invalid', None)

        serializer.save()
        save_result = self.order_id

        return save_result
def request_validation(open_id, access_token, request_data):
    if open_id is None or access_token is None:
        raise AuthInfoError

    if 'hub_id' in request_data:
        if request_data['hub_id'] == 0:
            request_data['hub_id'] = 1

    serializer = PurchaseOrderRequestSerializer(data=request_data)

    if not serializer.is_valid():
        raise DataValidationError('Request data invalid', None)

    if 'product_list' not in request_data \
            or 'coupon_list' not in request_data \
            or 'delivery_date' not in request_data:
        raise DataValidationError('Request data invalid', None)

    if not request_user_validation(open_id, access_token):
        raise AuthInfoError

    request_data['open_id'] = open_id
Example #12
0
    def delete_curation_article(self, article_id):
        curation_page = self.curation_service.admin_read_all_curation_page()
        page_data = CurationPageSerializer(curation_page, many=True).data

        for page in page_data:
            articles = page['articles']

            if article_id in articles:
                raise DataValidationError(
                    'Articles can be deleted without registering in page object.',
                    None)

        return self.article_service.delete_article(article_id)
Example #13
0
def dada_query_validation(request_data):
    if 'order_id' not in request_data:
        raise DataValidationError('Request data invalid', None)
Example #14
0
def get_article_validation(article_id):
    if article_id == 0:
        raise DataValidationError('Request data invalid', None)
Example #15
0
def article_post_validation(request_data):
    if 'article' not in request_data:
        raise DataValidationError('Required parameter is not found', None)

    if 'content_en' not in request_data['article'] or 'content_cn' not in request_data['article']:
        raise DataValidationError('Required parameter is not found', None)
Example #16
0
def time_bomb_activation_validation(request_data):
    if 'activate' not in request_data:
        raise DataValidationError('Request data invalid', None)
def req_admin_product_list(hub_id):
    if hub_id != 1 or hub_id != 2:
        msg = 'Request data invalid'
        raise DataValidationError(msg, None)
def cart_inst_validation(request_data):
    if 'special_instruction' not in request_data:
        raise DataValidationError('Request data invalid', None)
Example #19
0
def request_validation(request_data):
    if 'menu_id_list' not in request_data or 'target_db' not in request_data:
        raise DataValidationError('Hub id or Menu id not found', None)
def request_validation(request_data):
    if 'open_id' not in request_data:
        raise DataValidationError('Request data invalid', None)
Example #21
0
def create_article_validation(article, content_en, content_cn):
    if 'layout_type' not in article or 'action_type' not in article:
        raise DataValidationError('Request data invalid', None)

    if 'language_type' not in content_en or 'language_type' not in content_cn:
        raise DataValidationError('Request data invalid', None)
def coupon_issue_validation(request_data):
    if 'coupon_list' not in request_data or 'open_id' not in request_data:
        raise DataValidationError('Request data invalid', None)

    if 'coupon_code' not in request_data or 'sender_id' not in request_data:
        raise DataValidationError('Request data invalid', None)
Example #23
0
def dada_cancel_order_validation(request_data):
    if 'order_id' not in request_data:
        raise DataValidationError('Request data invalid', None)
    if 'cancel_reason_id' not in request_data:
        raise DataValidationError('Request data invalid', None)
def member_coupon_issue_validation(request_data):
    if 'open_id' not in request_data:
        raise DataValidationError('Request data invalid', None)
def req_admin_product_update(product_data):
    if 'id' not in product_data:
        raise DataValidationError('Request data invalid', None)
Example #26
0
def dada_order_add_after_query_validation(request_data):
    if 'deliveryNo' not in request_data:
        raise DataValidationError('Request data invalid', None)
def coupon_issue_validation(request_data):
    if 'coupon_list' not in request_data or 'coupon_type' not in request_data:
        raise DataValidationError('Request data invalid', None)