def setUpTestData(cls): cls.list_url = reverse('products-list') cls.user = User.objects.create_superuser(username='******', email='*****@*****.**', password='******', is_active=True) cls.product = PublishedProductFactory() # 2019-11-01 –> 2019-11-02 rental_period = RentalPeriodFactory( start_datetime=timezone.datetime(2019, 11, 1, 0, 0, 0), end_datetime=timezone.datetime(2019, 11, 2, 0, 0, 0)) # 2019-01-01 –> 2019-01-05 rental_period2 = RentalPeriodFactory( start_datetime=timezone.datetime(2019, 1, 1, 0, 0, 0), end_datetime=timezone.datetime(2019, 1, 5, 0, 0, 0)) # 2019-01-04 –> 2019-02-01 rental_period3 = RentalPeriodFactory( start_datetime=timezone.datetime(2019, 1, 4, 0, 0, 0), end_datetime=timezone.datetime(2019, 2, 1, 0, 0, 0)) order = OrderFactory(rental_period=rental_period) order2 = OrderFactory(rental_period=rental_period2) order3 = OrderFactory(rental_period=rental_period3) OrderItemFactory(order=order, product=cls.product, quantity=2) OrderItemFactory(order=order2, product=cls.product, quantity=1) OrderItemFactory(order=order3, product=cls.product, quantity=1) warehouse_item = WarehouseItemFactory(product=cls.product) warehouse_item_component = WarehouseItemComponentFactory( item=warehouse_item, quantity=1) StorageUnitComponentFactory( component=warehouse_item_component.component, quantity=2)
class OrderFSMTestCase(TestCase): def setUp(self) -> None: self.order = OrderFactory() def test_allowed_transitions(self): self.order.accept() self.order.start_delivery() self.order.arrive_at_customer() self.order.deliver() def test_cancellation_from_state(self): self.order.cancel()
def setUpTestData(cls): cls.order = OrderFactory() cls.order_item = OrderItemFactory(order=cls.order) cls.list_url = reverse('orders-list') cls.detail_url = reverse('orders-detail', kwargs={'pk': cls.order.id}) cls.address_dict = { 'first_name': 'A', 'last_name': 'B', 'address_line_1': 'C', 'address_line_2': 'D', 'zip_code': 'E', 'city': 'F', 'country': 'G', 'note': 'SOME NOTE', } cls.product = PublishedProductFactory(name='Product 2', price=1000, currency=EUR) cls.order_items_list = [{ 'product': { 'name': 'Product 2', 'price': 1000, 'currency': EUR }, 'quantity': 1 }] cls.rental_period_dict = { 'start_datetime': '2019-01-01T00:00:00Z', 'end_datetime': '2019-01-10T00:00:00Z', } cls.user = User.objects.create_superuser(username='******', email='*****@*****.**', password='******', is_active=True)
def setUpTestData(cls): cls.rental_period = RentalPeriodFactory( start_datetime=datetime.datetime(2019, 11, 1, 0, 0, 0), end_datetime=datetime.datetime(2019, 11, 2, 0, 0, 0)) cls.service = AvailableProductsService( datetime.datetime(2019, 10, 1, 0, 0, 0), datetime.datetime(2019, 12, 1, 0, 0, 0)) cls.product = PublishedProductFactory() cls.product2 = PublishedProductFactory() cls.product3 = PublishedProductFactory() cls.order = OrderFactory(rental_period=cls.rental_period) cls.order_item = OrderItemFactory(order=cls.order, product=cls.product) cls.order_item = OrderItemFactory(order=cls.order, product=cls.product2) cls.order_item = OrderItemFactory(order=cls.order, product=cls.product3) cls.warehouse_item = WarehouseItemFactory(product=cls.product) cls.warehouse_item2 = WarehouseItemFactory(product=cls.product2) cls.warehouse_item3 = WarehouseItemFactory(product=cls.product3) cls.warehouse_item_component = WarehouseItemComponentFactory( item=cls.warehouse_item, quantity=1) cls.warehouse_item_component2 = WarehouseItemComponentFactory( item=cls.warehouse_item2, quantity=1) cls.warehouse_item_component3 = WarehouseItemComponentFactory( item=cls.warehouse_item3, quantity=1) cls.storage_unit_component = StorageUnitComponentFactory( component=cls.warehouse_item_component.component, quantity=2) cls.storage_unit_component2 = StorageUnitComponentFactory( component=cls.warehouse_item_component2.component, quantity=3) cls.storage_unit_component3 = StorageUnitComponentFactory( component=cls.warehouse_item_component3.component, quantity=1)
def _set_orders(cls): for i in range(cls.dataset_len): setattr( cls, f'order{i}', OrderFactory(rental_period=getattr( cls, f'rental_period{i%(cls.dataset_len % 12)}'))) setattr( cls, f'order_item{i}', OrderItemFactory(order=getattr(cls, f'order{i}'), product=getattr( cls, f'product{i % cls.dataset_product_len}')))
def manipulate_orders(cls): # from 2020-05-01 –> 2020-05-10 # ordered amount of products: 10 rental_period, _ = RentalPeriod.objects.get_or_create( start_datetime=timezone.datetime(2020, 5, 1, 0, 0, 0), end_datetime=timezone.datetime(2020, 5, 10, 0, 0, 0)) order1 = OrderFactory(rental_period=rental_period) order2 = OrderFactory(rental_period=rental_period) OrderItemFactory(order=order1, product=cls.product0, quantity=6) OrderItemFactory(order=order2, product=cls.product0, quantity=4) cls.period_01 = rental_period # from 2020-06-01 –> 2020-06-10 # ordered amount of products: 6 rental_period, _ = RentalPeriod.objects.get_or_create( start_datetime=timezone.datetime(2020, 6, 1, 0, 0, 0), end_datetime=timezone.datetime(2020, 6, 10, 0, 0, 0)) order1 = OrderFactory(rental_period=rental_period) order2 = OrderFactory(rental_period=rental_period) order3 = OrderFactory(rental_period=rental_period) OrderItemFactory(order=order1, product=cls.product0, quantity=2) OrderItemFactory(order=order2, product=cls.product0, quantity=1) OrderItemFactory(order=order3, product=cls.product0, quantity=3) cls.period_02 = rental_period # reuse generated data to check performance # ordered amount of products: 8 # 2019-05-01 –> 2019-05-10 rental_period, _ = RentalPeriod.objects.get_or_create( start_datetime=timezone.datetime(2019, 5, 1, 0, 0, 0), end_datetime=timezone.datetime(2019, 5, 10, 0, 0, 0)) service = RentalPeriodService(rental_period.start_datetime, rental_period.end_datetime) # NOTE: we just set current rented quantity to 0 # the calculation should take care of the rest OrderItem.objects.filter( product=cls.product0, order__rental_period__in=service.get_overlapping().keys()).update( quantity=0) order1 = OrderFactory(rental_period=rental_period) order2 = OrderFactory(rental_period=rental_period) OrderItemFactory(order=order1, product=cls.product0, quantity=6) OrderItemFactory(order=order2, product=cls.product0, quantity=2) cls.period_03 = rental_period
class OrderNameTestCase(TestCase, ModelStrTestCaseMixin): obj = OrderFactory(customer__first_name='A', customer__last_name='B') string = f'{obj.pk}: A B ({obj.created_at})'
def setUp(self) -> None: self.order = OrderFactory()