def post(self, request, *args, **kwargs): if "price" not in request.POST: return HttpResponseBadRequest( json.dumps({"message": "missing parameter"})) try: price = int(request.POST.get("price")) except ValueError: return HttpResponseBadRequest( json.dumps({"message": "price must be int"})) SeveralCosts.set_actual_cash_balance(price) return HttpResponse()
def test_set_actual_cash_balance_nothing(self): SeveralCosts.objects.get(name="ActualCashBalance").delete() SeveralCosts.set_actual_cash_balance(2001) self.assertEqual(SeveralCosts.get_actual_cash_balance(), 2001)
def test_set_actual_cash_balance(self): SeveralCosts.set_actual_cash_balance(2001) self.assertEqual(SeveralCosts.get_actual_cash_balance(), 2001)