コード例 #1
0
ファイル: test_models.py プロジェクト: philip136/books-shop
class TestRoomOrderModel(TestCase):
    """
    Test Room Order model
    """
    def setUp(self):
        self.customer = User.objects.create(
            username='******',
            password='******',
        )
        self.courier = User.objects.create(username='******',
                                           password='******',
                                           is_staff=True,
                                           is_active=True)
        self.profile_customer = Profile.objects.create(user=self.customer)
        self.profile_courier = Profile.objects.create(user=self.courier)
        self.location_customer = Location.objects.create(
            title=f'Current position {self.customer.username}',
            profile=self.profile_customer)
        self.location_courier = Location.objects.create(
            title=f'Current position {self.courier.username}',
            profile=self.profile_courier)
        self.location_courier.latitude, self.location_courier.longitude = 20.15, 10.15
        self.location_customer.latitude, self.location_customer.longitude = 55.123, 27.50

        self.room = RoomOrder()
        self.room.save()
        self.room.participants.add(self.profile_customer, self.profile_courier)
        self.room.locations.add(self.location_customer, self.location_courier)

    def test_room_order_created(self):
        assert self.room is not None
コード例 #2
0
ファイル: test_apis.py プロジェクト: philip136/books-shop
    def test_order_room_connect_if_room_is_exist(self):
        order_room = RoomOrder()
        order_room.save()

        order_room.participants.add(self.profile)
        location = Location.objects.create(
            title=f'current pos {self.username}', profile=self.profile)
        order_room.locations.add(location)
        url = reverse("magazine:order-room", args=[order_room.id])
        response = self.client.get(url)
        assert response.status_code == 200
コード例 #3
0
ファイル: views.py プロジェクト: philip136/books-shop
    def operations_with_room(shop: Shop, type_delivery: str, order_data: dict, customer: Profile):
        room: RoomOrder = RoomOrder()
        order: Order = Order.objects.create(**order_data)
        room.save()
        order.save()

        another_location: Union[Location, None] = None
        courier_or_personal: Union[Profile, None] = None

        customer_location: Location = Location.objects.update_or_create(
                                        title=f'{customer}',
                                        profile=order_data.get('user'),
                                        defaults={'updated_at': datetime.datetime.now()}
                                    )[0]
        
        if type_delivery == "Самовывоз":
            another_location: Location = shop.position
            courier_or_personal: Profile = shop.personal.first()

        elif type_delivery == "Доставка курьером":
            courier: Profile = order.search_free_driver()
            if courier is not None:
                courier_or_personal: Profile = courier
                another_location: Location = Location.objects.update_or_create(
                    title=f'{courier.user.username}',
                    profile=courier
                )[0]
            else:
                return Response({'message': "Простите свободных курьеров сейчас нет, "
                                "обратитесь позже"}, status=status.HTTP_200_OK)
        room.participants.add(customer, courier_or_personal)
        room.locations.add(customer_location, another_location)
コード例 #4
0
 def setUp(self):
     self.type_product = TypeProduct.objects.create(type='book')
     self.product = Product.objects.create(
         type=self.type_product,
         name='test_book',
         count=10,
         delivery_time=datetime.now().date(),
         price=Decimal(20.00))
     self.item = CartItem.objects.create(product=self.product,
                                         count=1,
                                         product_total=self.product.price)
     self.user = User.objects.create_user(username='******')
     self.profile = Profile.objects.create(user=self.user)
     self.location = Location.objects.create(
         title=f'Current position {self.user.username}',
         profile=self.profile)
     self.room = RoomOrder()
     self.room.save()
     self.room.participants.add(self.profile)
     self.room.locations.add(self.location)
コード例 #5
0
ファイル: test_apis.py プロジェクト: philip136/books-shop
    def test_connect_as_courier(self):
        order_room = RoomOrder()
        order_room.save()

        courier = User.objects.create(username='******',
                                      password='******',
                                      email='*****@*****.**',
                                      is_staff=True,
                                      is_active=True)
        p_courier = Profile.objects.create(user=courier)

        order_room.participants.add(self.profile, p_courier)
        location_customer = Location.objects.create(
            title=f'current pos {self.username}', profile=self.profile)
        location_courier = Location.objects.create(
            title=f'current pos {courier.username}', profile=p_courier)
        order_room.locations.add(location_customer, location_courier)
        url = reverse("magazine:connect-to-room")
        username = {"username": courier.username}
        response = self.client.post(url, username)
        assert response.status_code == 200
        assert response.data["message"] == order_room.id
コード例 #6
0
class TestMagazineAppUrls(TestCase):
    """
    Test Magazine app urls 
    """
    def setUp(self):
        self.type_product = TypeProduct.objects.create(type='book')
        self.product = Product.objects.create(
            type=self.type_product,
            name='test_book',
            count=10,
            delivery_time=datetime.now().date(),
            price=Decimal(20.00))
        self.item = CartItem.objects.create(product=self.product,
                                            count=1,
                                            product_total=self.product.price)
        self.user = User.objects.create_user(username='******')
        self.profile = Profile.objects.create(user=self.user)
        self.location = Location.objects.create(
            title=f'Current position {self.user.username}',
            profile=self.profile)
        self.room = RoomOrder()
        self.room.save()
        self.room.participants.add(self.profile)
        self.room.locations.add(self.location)

    def test_type_products_url(self):
        type_slug = self.type_product.type
        url = reverse("magazine:filter-products", args=[type_slug])
        assert resolve(url).func.view_class == TypeProductsApi

    def test_list_products_url(self):
        url = reverse("magazine:products")
        assert resolve(url).func.view_class == ProductsApi

    def test_detail_product_url(self):
        product_slug = self.product.id
        url = reverse("magazine:product", args=[product_slug])
        assert resolve(url).func.view_class == ProductDetailApi

    def test_cart_item_detail_url(self):
        cart_slug = self.item.id
        url = reverse("magazine:cart-item", args=[cart_slug])
        assert resolve(url).func.view_class == CartItemApi

    def test_cart_url(self):
        url = reverse("magazine:my-cart", args=['test'])
        assert resolve(url).func.view_class == CartApi

    def test_cart_item_delete_url(self):
        cart_item_slug = self.item.id
        url = reverse("magazine:delete-item", args=[cart_item_slug])
        assert resolve(url).func.view_class == DeleteItemApi

    def test_update_item_url(self):
        cart_item_slug = self.item.id
        url = reverse("magazine:update-item", args=[cart_item_slug])
        assert resolve(url).func.view_class == UpdateCartItemApi

    def test_order_success_url(self):
        url = reverse("magazine:order-success")
        assert resolve(url).func.view_class == OrderSuccessApi

    def test_locations_list_url(self):
        url = reverse("magazine:location-list")
        assert resolve(url).func.view_class == LocationList

    def test_location_detail_url(self):
        location_slug = self.location.id
        url = reverse("magazine:location-detail", args=[location_slug])
        assert resolve(url).func.view_class == LocationDetail

    def test_profile_detail_url(self):
        profile_slug = self.profile.id
        url = reverse("magazine:profile", args=[profile_slug])
        assert resolve(url).func.view_class == ProfileApi

    def test_order_room_detail_url(self):
        room_slug = self.room.id
        url = reverse("magazine:order-room", args=[room_slug])
        assert resolve(url).func.view_class == OrderRoomApi

    def test_connect_to_room_url(self):
        url = reverse("magazine:connect-to-room")
        assert resolve(url).func.view_class == OrderRoomConnectApi