def test_query_product(self): in_transaction_1 = InTransaction.objects.create( in_product=self.phone_A, in_quantity=5, in_unit_price=10, in_purchase=self.purchase_1, in_serial='1111') input = {'id': 'PROD1'} ret = query.query_product(input) self.assertEqual( ret['prod_name'], 'Phone_A') input = {'id': '1111'} ret = query.query_product(input) self.assertEqual( ret['prod_name'], 'Phone_A') input = {'id': '2222'} ret = query.query_product(input) self.assertEqual( ret, {}) input = {'name': 'Phone_A'} ret = query.query_product(input) self.assertEqual( ret['prod_name'], 'Phone_A')
def product_list(request, store): """ handles product list function support GET to retrieve product """ if request.method != "GET": return HttpResponse( 'Method ' + request.method + " is not supported", status=403) try: data = query.query_product(request.GET) return HttpResponse(json.dumps(data)) except ValidationError as ex: return HttpResponse(ex.value, status=403)
def product_detail(request, store, id): if request.method != "GET": return HttpResponse( 'Method ' + request.method + " is not supported", status=403) if request.method == 'GET': try: data = query.query_product({"id": id}) return HttpResponse(json.dumps(data)) except ValidationError as ex: return HttpResponse(ex.value, status=403) else: return HttpResponse( 'Method ' + request.method + " is not supported", status=403)