def check_stock(self, code, amount, case_id=None, section_id='stock'):
        if not case_id:
            case_id = self.sp.case_id

        [product] = filter(lambda p: p.code_ == code, self.products)

        try:
            state = StockState.objects.get(
                product_id=product._id,
                case_id=case_id,
                section_id=section_id
            )
            self.assertEqual(amount, state.stock_on_hand)
        except StockState.DoesNotExist:
            if amount != 0:
                # only error if we weren't checking for no stock
                raise Exception(
                    'StockState for "%s" section does not exist' % section_id
                )
dataset/ETHPy150Open dimagi/commcare-hq/corehq/apps/commtrack/tests/test_sms_reporting.py/SMSTests.check_stock/original