class StockTestBase(TestCase): @classmethod def setUpClass(cls): super(StockTestBase, cls).setUpClass() cls.domain = create_domain("stock-report-test") @classmethod def tearDownClass(cls): cls.domain.delete() super(StockTestBase, cls).tearDownClass() def setUp(self): # create case case = CaseFactory(domain=self.domain.name).create_case() self.case_id = case.case_id self.product_id = uuid.uuid4().hex SQLProduct(product_id=self.product_id, domain=self.domain.name).save() self._stock_report = functools.partial(_stock_report, self.domain.name, self.case_id, self.product_id) self._receipt_report = functools.partial(_receipt_report, self.domain.name, self.case_id, self.product_id) self._test_config = ConsumptionConfiguration.test_config() self._compute_consumption = functools.partial( compute_daily_consumption, self.domain.name, self.case_id, self.product_id, now, configuration=self._test_config)
def setUp(self): # create case self.case_id = uuid.uuid4().hex CommCareCase(_id=self.case_id, domain="fakedomain").save() self.product_id = uuid.uuid4().hex self._stock_report = functools.partial(_stock_report, self.case_id, self.product_id) self._receipt_report = functools.partial(_receipt_report, self.case_id, self.product_id) self._test_config = ConsumptionConfiguration.test_config() self._compute_consumption = functools.partial( compute_consumption, self.case_id, self.product_id, now, configuration=self._test_config )
def _stock_report(case_id, product_id, amount, days_ago): report = StockReport.objects.create(form_id=uuid.uuid4().hex, date=ago(days_ago), type=const.REPORT_TYPE_BALANCE) txn = StockTransaction( report=report, section_id=const.SECTION_TYPE_STOCK, type=const.TRANSACTION_TYPE_STOCKONHAND, case_id=case_id, product_id=product_id, stock_on_hand=Decimal(amount), ) txn._test_config = ConsumptionConfiguration.test_config() txn.quantity = 0 txn.save()
def setUp(self): # create case case = CaseFactory(domain=self.domain.name).create_case() self.case_id = case.case_id self.product_id = uuid.uuid4().hex SQLProduct(product_id=self.product_id, domain=self.domain.name).save() self._stock_report = functools.partial(_stock_report, self.domain.name, self.case_id, self.product_id) self._receipt_report = functools.partial(_receipt_report, self.domain.name, self.case_id, self.product_id) self._test_config = ConsumptionConfiguration.test_config() self._compute_consumption = functools.partial( compute_daily_consumption, self.domain.name, self.case_id, self.product_id, now, configuration=self._test_config )
def _stock_report(case_id, product_id, amount, days_ago): report = StockReport.objects.create(form_id=uuid.uuid4().hex, date=ago(days_ago), type=const.REPORT_TYPE_BALANCE) txn = StockTransaction( report=report, section_id=const.SECTION_TYPE_STOCK, type=const.TRANSACTION_TYPE_STOCKONHAND, case_id=case_id, product_id=product_id, stock_on_hand=Decimal(amount), ) txn._test_config = ConsumptionConfiguration.test_config() txn.quantity = 0 txn.save()
def setUp(self): # create case self.case_id = uuid.uuid4().hex CommCareCase( _id=self.case_id, domain='fakedomain', ).save() self.product_id = uuid.uuid4().hex self._stock_report = functools.partial(_stock_report, self.case_id, self.product_id) self._receipt_report = functools.partial(_receipt_report, self.case_id, self.product_id) self._test_config = ConsumptionConfiguration.test_config() self._compute_consumption = functools.partial(compute_consumption, self.case_id, self.product_id, now, configuration=self._test_config)