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


Python DeliveryNodeFactory.current_run方法代码示例

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


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

示例1: RunnableTest

# 需要导入模块: from eums.test.factories.delivery_node_factory import DeliveryNodeFactory [as 别名]
# 或者: from eums.test.factories.delivery_node_factory.DeliveryNodeFactory import current_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

示例2: RunTest

# 需要导入模块: from eums.test.factories.delivery_node_factory import DeliveryNodeFactory [as 别名]
# 或者: from eums.test.factories.delivery_node_factory.DeliveryNodeFactory import current_run [as 别名]
class RunTest(TestCase):
    def setUp(self):
        self.consignee = ConsigneeFactory()
        self.runnable = DeliveryNodeFactory(consignee=self.consignee)

    def tearDown(self):
        Run.objects.all().delete()
        DistributionPlanNode.objects.all().delete()

    def test_should_get_current_run_for_consignee_with_run_with_status_scheduled(self):
        run = RunFactory(runnable=self.runnable)

        self.assertEqual(self.runnable.current_run(), run)

    def test_should_get_none_when_current_run_is_called_for_a_consignee_with_no_runs_scheduled(self):
        RunFactory(runnable=self.runnable, status=Run.STATUS.expired)
        RunFactory(runnable=self.runnable, status=Run.STATUS.completed)

        self.assertEqual(self.runnable.current_run(), None)

    def test_should_get_over_due_runs(self):
        delivery_status_check_delay = datetime.timedelta(days=settings.DELIVERY_STATUS_CHECK_DELAY)
        max_allowed_reply_period = datetime.timedelta(days=settings.MAX_ALLOWED_REPLY_PERIOD)
        one_day = datetime.timedelta(days=1)

        today = datetime.datetime.combine(datetime.date.today(), datetime.datetime.min.time())
        expired_run_date = today - delivery_status_check_delay - max_allowed_reply_period - one_day
        valid_run_date = today - delivery_status_check_delay - max_allowed_reply_period + one_day

        expired_run = RunFactory(status=Run.STATUS.scheduled,
                                 runnable=DeliveryNodeFactory(
                                     delivery_date=expired_run_date))
        RunFactory(status=Run.STATUS.scheduled,
                   runnable=DeliveryNodeFactory(
                       delivery_date=valid_run_date))

        overdue_runs = Run.overdue_runs()

        self.assertEqual(len(overdue_runs), 1)
        self.assertEqual(overdue_runs[0], expired_run)

    def test_should_not_get_completed_expired_or_cancelled_runs_when_getting_expired_runs(self):
        expired_run_date = datetime.date(1990, 1, 1)

        RunFactory(status=Run.STATUS.completed,
                   runnable=DeliveryNodeFactory(
                       delivery_date=expired_run_date))
        RunFactory(status=Run.STATUS.expired,
                   runnable=DeliveryNodeFactory(
                       delivery_date=expired_run_date))
        RunFactory(status=Run.STATUS.cancelled,
                   runnable=DeliveryNodeFactory(
                       delivery_date=expired_run_date))

        overdue_runs = Run.overdue_runs()

        self.assertEqual(len(overdue_runs), 0)

    def test_should_get_all_answers(self):
        run = RunFactory()

        multiple_answer_one = MultipleChoiceAnswerFactory(run=run)
        numeric_answer_one = NumericAnswerFactory(run=run)
        run_answers = run.answers()
        self.assertIn(multiple_answer_one, run_answers)
        self.assertIn(numeric_answer_one, run_answers)

    def test_should_get_all_questions_and_responses(self):
        run = RunFactory()

        item_received_question = MultipleChoiceQuestionFactory(label='product_received')
        yes = OptionFactory(question=item_received_question, text='Yes')
        item_received_question.answers.create(value=yes, run=run)

        date_received_question = TextQuestionFactory(label='date_received')
        date_received_question.textanswer_set.create(value='2014-01-01', run=run)

        quantity_received_question = NumericQuestionFactory(label='quantity_received')
        quantity_received_question.numericanswer_set.create(value=12, run=run)

        expected_data = {'product_received': 'Yes', 'quantity_received': 12, 'date_received': '2014-01-01'}
        self.assertDictEqual(run.questions_and_responses(), expected_data)

    def test_should_get_scheduled_runs_for_contact(self):
        runnable = DeliveryNodeFactory(contact_person_id=2)
        contact_person_id = 2

        self.assertEqual(Run.has_scheduled_run(contact_person_id), False)

        run = RunFactory(runnable=runnable)
        self.assertEqual(Run.has_scheduled_run(contact_person_id), True)

        run.status = Run.STATUS.completed
        run.save()
        self.assertEqual(Run.has_scheduled_run(contact_person_id), False)

    def test_should_update_run_status(self):
        run = RunFactory(status=Run.STATUS.scheduled)

        run.update_status(Run.STATUS.completed)
#.........这里部分代码省略.........
开发者ID:phoenix-zhu,项目名称:eums,代码行数:103,代码来源:test_run.py


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