Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
2.1 kB
1
Indexable
Never
@dataclasses.dataclass
class CustomerServicesDetailsContext:
    products: List[DetailsProduct] = dataclasses.field(default_factory=list)

    handler: Any = None

    def add_product(self, weight=None, measure_unit='GRM', gram_weight=None):
        self.products.append(  # pylint: disable=E1101
            DetailsProduct(
                weight=weight,
                measure_unit=measure_unit,
                gram_weight=gram_weight,
            ),
        )


@pytest.fixture(name='customer_services_details')
def _customer_services_details(mockserver):
    context = CustomerServicesDetailsContext()

    def mock_customer_services_details(request, context):
        payload = {
            'origin_revision_id': 'revision2',
            'created_at': '2021-10-13T15:35:43+00:00',
            'customer_services': [
                {
                    'id': 'composition-products',
                    'name': 'Продукты заказа',
                    'cost_for_customer': '110',
                    'currency': 'RUB',
                    'type': 'composition_products',
                    'trust_product_id': 'eda_107819207_ride',
                    'place_id': '475529',
                    'personal_tin_id': '05fcebe0a0db43e8bf963eaed35efd8f',
                    'balance_client_id': '4294491982',
                    'details': {
                        'composition_products': [],
                        'discriminator_type': 'composition_products_details',
                    },
                },
            ],
        }

        for product in context.products:
            payload['customer_services'][0]['details'][
                'composition_products'
            ].append(product.build())

        return payload

    @mockserver.json_handler(
        '/eats-order-revision/v1'
        '/order-revision/customer-services/details',  # pylint: disable=C0103
    )
    def _customer_services_details_handler(request):
        return mock_customer_services_details(request, context)

    context.handler = _customer_services_details_handler

    return context
Leave a Comment