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


Python DeliveryNodeFactory.completed_run方法代码示例

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


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

示例1: RunnableTest

# 需要导入模块: from eums.test.factories.delivery_node_factory import DeliveryNodeFactory [as 别名]
# 或者: from eums.test.factories.delivery_node_factory.DeliveryNodeFactory import completed_run [as 别名]
class RunnableTest(TestCase):
    def setUp(self):
        self.node = DeliveryNodeFactory()

    @patch('requests.get')
    def test_should_build_contact_with_details_from_contacts_service(self, mock_get):
        contact_id = '54335c56b3ae9d92f038abb0'
        fake_contact_json = {'firstName': "test", 'lastName': "user1", 'phone': "+256 782 443439", '_id': contact_id}
        fake_response = FakeResponse(fake_contact_json, 200)
        node = NodeFactory(contact_person_id=contact_id)
        mock_get.return_value = fake_response

        contact = node.build_contact()

        self.assertEqual(contact, fake_contact_json)
        mock_get.assert_called_with("%s%s/" % (settings.CONTACTS_SERVICE_URL, contact_id))

    def test_gets_all_response_for_node_consignee(self):
        multichoice_question = MultipleChoiceQuestionFactory(label='productReceived')
        yes_option = OptionFactory(text='Yes', question=multichoice_question)
        no_option = OptionFactory(text='No', question=multichoice_question)

        sugar = ItemFactory(description='Sugar')
        salt = ItemFactory(description='Salt')

        numeric_question = NumericQuestionFactory(label='AmountReceived')
        item = SalesOrderItemFactory(item=salt, description='10 bags of salt')

        salt_node = DeliveryNodeFactory(quantity=100, item=PurchaseOrderItemFactory(sales_order_item=item))
        run = RunFactory(runnable=salt_node, status='completed')

        sugar_item = SalesOrderItemFactory(item=sugar, description='10 bags of sugar')
        sugar_node = DeliveryNodeFactory(quantity=100, item=PurchaseOrderItemFactory(sales_order_item=sugar_item))
        sugar_run = RunFactory(runnable=sugar_node, status='completed')

        multiple_answer_one = MultipleChoiceAnswerFactory(run=run, question=multichoice_question, value=yes_option)
        numeric_answer_one = NumericAnswerFactory(run=run, value=80, question=numeric_question)

        multiple_answer_two = MultipleChoiceAnswerFactory(run=sugar_run, question=multichoice_question, value=no_option)
        numeric_answer_two = NumericAnswerFactory(run=sugar_run, value=80, question=numeric_question)
        salt_node_responses = salt_node.responses()
        sugar_node_responses = sugar_node.responses()

        self.assertIn(multiple_answer_one, salt_node_responses[run])
        self.assertIn(numeric_answer_one, salt_node_responses[run])

        self.assertIn(multiple_answer_two, sugar_node_responses[sugar_run])
        self.assertIn(numeric_answer_two, sugar_node_responses[sugar_run])

    def test_should_get_run_with_status_scheduled(self):
        run = RunFactory(runnable=self.node, status=Run.STATUS.scheduled)
        self.assertEqual(self.node.current_run(), run)

    def test_should_not_get_run_with_status_completed(self):
        RunFactory(runnable=self.node, status=Run.STATUS.completed)
        self.assertEqual(self.node.current_run(), None)

    def test_should_not_get_run_with_status_expired(self):
        RunFactory(runnable=self.node, status=Run.STATUS.expired)
        self.assertEqual(self.node.current_run(), None)

    def test_should_not_get_run_with_status_cancelled(self):
        RunFactory(runnable=self.node, status=Run.STATUS.cancelled)
        self.assertEqual(self.node.current_run(), None)

    def test_should_get_the_completed_run(self):
        self.assertIsNone(self.node.completed_run())
        run = RunFactory(runnable=self.node, status=Run.STATUS.completed)
        self.assertEqual(self.node.completed_run(), run)

    def test_should_get_latest_run(self):
        first_run = RunFactory(runnable=self.node)
        self.assertEqual(self.node.latest_run(), first_run)
        second_run = RunFactory(runnable=self.node)
        self.assertEqual(self.node.latest_run(), second_run)

    def test_should_get_latest_response(self):
        multichoice_question = MultipleChoiceQuestionFactory(label='productReceived')
        no_option = OptionFactory(text='No', question=multichoice_question)

        sugar = ItemFactory(description='Sugar')

        numeric_question = NumericQuestionFactory(label='AmountReceived')

        node = DeliveryNodeFactory(quantity=100, item=PurchaseOrderItemFactory(item=sugar))
        run = RunFactory(runnable=node, status='completed')

        self.assertIsNone(node.latest_response())

        multiple_answer = MultipleChoiceAnswerFactory(run=run, question=multichoice_question, value=no_option)
        self.assertEqual(node.latest_response(), multiple_answer)

        numeric_answer = NumericAnswerFactory(run=run, value=80, question=numeric_question)
        self.assertEqual(node.latest_response(), numeric_answer)

    @patch('eums.models.runnable.Runnable.build_contact')
    def test_should_create_alert(self, mock_contact):
        purchase_order = PurchaseOrderFactory(order_number=5678)
        purchase_order_item = PurchaseOrderItemFactory(purchase_order=purchase_order)
        consignee = ConsigneeFactory(name="Liverpool FC")
#.........这里部分代码省略.........
开发者ID:v55448330,项目名称:eums,代码行数:103,代码来源:test_runnable.py


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