当前位置: 首页>>代码示例>>Python>>正文


Python FormProcessorInterface.rebuild_ledger_state方法代码示例

本文整理汇总了Python中corehq.form_processor.interfaces.processor.FormProcessorInterface.rebuild_ledger_state方法的典型用法代码示例。如果您正苦于以下问题:Python FormProcessorInterface.rebuild_ledger_state方法的具体用法?Python FormProcessorInterface.rebuild_ledger_state怎么用?Python FormProcessorInterface.rebuild_ledger_state使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在corehq.form_processor.interfaces.processor.FormProcessorInterface的用法示例。


在下文中一共展示了FormProcessorInterface.rebuild_ledger_state方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: RebuildStockStateTest

# 需要导入模块: from corehq.form_processor.interfaces.processor import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.processor.FormProcessorInterface import rebuild_ledger_state [as 别名]
class RebuildStockStateTest(TestCase):

    def setUp(self):
        super(RebuildStockStateTest, self).setUp()
        self.domain = 'asldkjf-domain'
        self.case = CaseFactory(domain=self.domain).create_case()
        self.product = make_product(self.domain, 'Product Name', 'prodcode')
        self._stock_state_key = dict(
            section_id='stock',
            case_id=self.case.case_id,
            product_id=self.product.get_id
        )
        self.unique_reference = UniqueLedgerReference(
            case_id=self.case.case_id, section_id='stock', entry_id=self.product.get_id
        )

        self.ledger_processor = FormProcessorInterface(self.domain).ledger_processor

    def _assert_stats(self, epxected_tx_count, expected_stock_state_balance, expected_tx_balance):
        ledger_value = LedgerAccessors(self.domain).get_ledger_value(**self.unique_reference._asdict())
        latest_txn = LedgerAccessors(self.domain).get_latest_transaction(**self.unique_reference._asdict())
        all_txns = LedgerAccessors(self.domain).get_ledger_transactions_for_case(**self.unique_reference._asdict())
        self.assertEqual(epxected_tx_count, len(all_txns))
        self.assertEqual(expected_stock_state_balance, ledger_value.stock_on_hand)
        self.assertEqual(expected_tx_balance, latest_txn.stock_on_hand)

    def _submit_ledgers(self, ledger_blocks):
        return submit_case_blocks(
            ledger_blocks.format(**self._stock_state_key), self.domain)[0].form_id

    @run_with_all_backends
    def test_simple(self):
        self._submit_ledgers(LEDGER_BLOCKS_SIMPLE)
        self._assert_stats(2, 100, 100)

        self.ledger_processor.rebuild_ledger_state(**self.unique_reference._asdict())

        self._assert_stats(2, 200, 200)

    def test_inferred(self):
        self._submit_ledgers(LEDGER_BLOCKS_INFERRED)
        # this is weird behavior:
        # it just doesn't process the second one
        # even though knowing yesterday's certainly changes the meaning
        # of today's transfer

        # UPDATE SK 2016-03-14: this happens because the transactions are received out of order
        # (they appear out of order in the form XML) and hence saved out of order.
        # When the older transaction is saved it will only look back in time
        # to create inferred transactions and not ahead.
        self._assert_stats(2, 50, 50)

        rebuild_stock_state(**self._stock_state_key)

        self._assert_stats(2, 150, 150)

    @run_with_all_backends
    def test_case_actions(self):
        # make sure that when a case is rebuilt (using rebuild_case)
        # stock transactions show up as well
        form_id = self._submit_ledgers(LEDGER_BLOCKS_SIMPLE)
        case_id = self.case.case_id
        rebuild_case_from_forms(self.domain, case_id, RebuildWithReason(reason='test'))
        case = CaseAccessors(self.domain).get_case(self.case.case_id)
        self.assertEqual(case.xform_ids[1:], [form_id])
        self.assertTrue(form_id in [action.form_id for action in case.actions])

    @run_with_all_backends
    def test_edit_submissions_simple(self):
        initial_quantity = 100
        form = submit_case_blocks(
            case_blocks=get_single_balance_block(quantity=initial_quantity, **self._stock_state_key),
            domain=self.domain,
        )[0]
        self._assert_stats(1, initial_quantity, initial_quantity)

        case_accessors = CaseAccessors(self.domain)
        case = case_accessors.get_case(self.case.case_id)
        try:
            self.assertTrue(any([action.is_ledger_transaction for action in case.actions]))
        except AttributeError:
            self.assertTrue('commtrack' in [action.action_type for action in case.actions])
        self.assertEqual([form.form_id], case.xform_ids[1:])

        # change the value to 50
        edit_quantity = 50
        submit_case_blocks(
            case_blocks=get_single_balance_block(quantity=edit_quantity, **self._stock_state_key),
            domain=self.domain,
            form_id=form.form_id,
        )
        case = case_accessors.get_case(self.case.case_id)

        try:
            # CaseTransaction
            self.assertTrue(any([action.is_ledger_transaction for action in case.actions]))
        except AttributeError:
            # CaseAction
            self.assertTrue('commtrack' in [action.action_type for action in case.actions])

#.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:103,代码来源:


注:本文中的corehq.form_processor.interfaces.processor.FormProcessorInterface.rebuild_ledger_state方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。