def post_seller (request): payload = json.loads(request.body) name = payload.get("name") seller_id = payload.get("seller_id") #status_seller = payload.get("status_seller") seller = Seller() seller.name = name seller.seller_id = seller_id #seller.status_seller= 'A' seller.save() return JsonResponse ({"sellers": seller.to_dict()})
def test_to_dict_when_valid_product_expected_dict(self): dict = { 'title': 'productTitle', 'price': 1, 'id_product': 'productId', 'seller': 'sellerName', 'qt_stock': 0, 'status': 'A' } seller = Seller() seller.name = "sellerName" product = Product() product.title = "productTitle" product.price = 1 product.id_product = "productId" product.seller = seller product.qt_stock = 0 product.status = "A" self.assertEquals(product.to_dict(), dict)
def setUpTestData(cls): seller = Seller() seller.name = "sellerName" seller.seller_id = 1 Seller.objects.create(name="sellerName", seller_id=1) Product.objects.create(title="cadeira", price=5, id_product="32", qt_stock=8, seller_id=1, status='A') Product.objects.create(title="mesa", price=15, id_product="8", qt_stock=3, seller_id=1, status='A') Product.objects.create(title="computador", price=1000, id_product="6", qt_stock=1, seller_id=1, status='A')