Exemple #1
0
class RegisteredSellersWithMoreProductsTestCase(
        RegisteredSellersWithProductsTestCase):
    @classmethod
    def setUp(self):
        super().setUp()

        self.product_4 = Product(
            name='Web Shooters',
            category='Kids',
            price=299.99,
            num_stocks=220,
            short_description=
            'Shoot webs everywhere to satisfy your childish dreams!',
            full_description=
            'Web Shooters are twin devices, worn on your wrists beneath the gauntlets of your costume, that can shoot thin strands of a special \'web fluid\' (the chemical composition of which is not known) at high pressure.',
            image='web_shooters.jpg',
            seller=self.seller)
        self.product_4.save()
Exemple #2
0
class RegisteredBuyersWithCartsTestCase(RegisteredBuyersTestCase):
    @classmethod
    def setUp(self):
        super().setUp()

        self.seller = Seller(
            username='******',
            password='******',
            first_name='Michael',
            last_name='Fassbender',
            company_name='The Brotherhood',
            address='900 Exposition Boulevard, Los Angeles',
            description=
            'The Brotherhood was founded by Magneto and its members were his primary allies in his early battles with the X-Men during the 1960s. The original Brotherhood ultimately disbanded, with Quicksilver and Scarlet Witch going on to become members of the Avengers.'
        )
        self.seller.save()

        self.product = Product(
            name='Cerebro',
            category='Cosmetics',
            price=1749.99,
            num_stocks=3,
            short_description='Read minds across the globe!',
            full_description=
            'Cerebro is a fictional device appearing in American comic books published by Marvel Comics. The device is used by the X-Men (in particular, their leader, Professor Charles Xavier) to detect humans, specifically mutants.',
            image='http://localhost:8000/images/cerebro.jpg',
            seller=self.seller)
        self.product.save()

        self.cart = Cart(buyer=self.buyer)
        self.cart.save()

    def add_item_to_cart(self, product_id):
        return self.client.post('/buyers/1/cart/items/',
                                json.dumps({'product_id': product_id}),
                                content_type='application/json')

    def update_item_quantity(self, action):
        return self.client.post('/buyers/1/cart/items/1/',
                                json.dumps({'action': action}),
                                content_type='application/json')
Exemple #3
0
    def post(self):
        data = parser.parse_args()
        name = data['name']
        # Checking that user is already exist or not
        if Product.find_by_name(name):
            return {'message': f'Product {name} already exists'}, 400

        # create new user
        item = Product(
            name=name,
            price=data['price'],
            description=data.get('description', ''),
        )

        try:
            # Saving user in DB and Generating Access and Refresh token
            item.save()
            return {
                'payload': {
                    'product': item.to_json(),
                }
            }, 201
        except:
            return {'message': 'Error while saving the product'}, 500
Exemple #4
0
def retrieve_and_create_product(request, seller_id):
    if (request.method == 'GET'):
        products_list = Product.objects.filter(
            Q(seller_id=seller_id) | Q(seller_id=None)).order_by('id')
        products = []

        for product in products_list:
            products.append({
                'product_id': product.id,
                'seller_id': product.seller_id,
                'name': product.name,
                'category': product.category,
                'price': product.price,
                'short_description': product.short_description,
                'image': product.image
            })

        return JsonResponse({'products': products})
    elif (request.method == 'POST'):
        seller = get_object_or_404(Seller, id=seller_id)

        request_body = json.loads(request.body.decode('utf-8'))
        product = Product(name=request_body['name'],
                          category=request_body['category'],
                          price=request_body['price'],
                          num_stocks=request_body['num_stocks'],
                          short_description=request_body['short_description'],
                          full_description=request_body['full_description'],
                          image='http://localhost:8000{}{}'.format(
                              settings.MEDIA_URL, request_body['image']),
                          seller=seller)
        product.save()

        return JsonResponse({'product_id': product.id}, status=201)
    else:
        return HttpResponse(status=405)
Exemple #5
0
class AdminWithProductsTestCase(AdminTestCase):

    @classmethod
    def setUp(self):
        super().setUp()

        self.seller = Seller(
            username='******',
            password='******',
            first_name='Michael',
            last_name='Fassbender',
            company_name='The Brotherhood',
            address='900 Exposition Boulevard, Los Angeles',
            description='The Brotherhood was founded by Magneto and its members were his primary allies in his early battles with the X-Men during the 1960s. The original Brotherhood ultimately disbanded, with Quicksilver and Scarlet Witch going on to become members of the Avengers.'
        )
        self.seller.save()

        self.product_1 = Product(
            name='Cerebro',
            category='Cosmetics',
            price=1749.99,
            num_stocks=3,
            short_description='Read minds across the globe!',
            full_description='Cerebro is a fictional device appearing in American comic books published by Marvel Comics. The device is used by the X-Men (in particular, their leader, Professor Charles Xavier) to detect humans, specifically mutants.',
            image='http://localhost:8000/images/cerebro.jpg',
            seller=self.seller
        )
        self.product_1.save()

        self.product_2 = Product(
            name='Invisibility Cloak',
            category='Clothes',
            price=799.99,
            num_stocks=3,
            short_description='Hide from anything, even death!',
            full_description='An invisibility cloak is a magical garment which renders whomever or whatever it covers unseeable. These are common items that are massed produced in the wizarding world. The first known cloak was made by Death for Ignotus Peverell in the 13th century and it is one of a kind.',
            image='http://localhost:8000/images/invisibility_cloak.jpg',
            seller=self.seller
        )
        self.product_2.save()

        self.product_3 = Product(
            name='Mjolnir',
            category='Sports',
            price=2499.99,
            num_stocks=3,
            short_description='Weight-lifting like never before!',
            full_description='In Norse mythology, Mjolnir is the hammer of Thor, a major Norse god associated with thunder. Mjolnir is depicted in Norse mythology as one of the most fearsome and powerful weapons in existence, capable of leveling mountains.',
            is_confirmed=True,
            image='http://localhost:8000/images/mjolnir.jpg',
            seller=self.seller
        )
        self.product_3.save()
Exemple #6
0
class RegisteredSellersWithProductsTestCase(RegisteredSellersTestCase):
    @classmethod
    def setUp(self):
        super().setUp()

        self.product_1 = Product(
            name='Cerebro',
            category='Cosmetics',
            price=1749.99,
            num_stocks=3,
            short_description='Read minds across the globe!',
            full_description=
            'Cerebro is a fictional device appearing in American comic books published by Marvel Comics. The device is used by the X-Men (in particular, their leader, Professor Charles Xavier) to detect humans, specifically mutants.',
            is_confirmed=True,
            image='http://localhost:8000/images/cerebro.jpg',
            seller=self.seller)
        self.product_1.save()

        self.product_2 = Product(
            name='Invisibility Cloak',
            category='Clothes',
            price=799.99,
            num_stocks=3,
            short_description='Hide from anything, even death!',
            full_description=
            'An invisibility cloak is a magical garment which renders whomever or whatever it covers unseeable. These are common items that are massed produced in the wizarding world. The first known cloak was made by Death for Ignotus Peverell in the 13th century and it is one of a kind.',
            is_confirmed=True,
            image='http://localhost:8000/images/invisibility_cloak.jpg',
            seller=self.seller)
        self.product_2.save()

        self.product_3 = Product(
            name='Mjolnir',
            category='Sports',
            price=2499.99,
            num_stocks=3,
            short_description='Weight-lifting like never before!',
            full_description=
            'In Norse mythology, Mjolnir is the hammer of Thor, a major Norse god associated with thunder. Mjolnir is depicted in Norse mythology as one of the most fearsome and powerful weapons in existence, capable of leveling mountains.',
            image='http://localhost:8000/images/mjolnir.jpg',
            seller=self.seller)
        self.product_3.save()