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


Python fuzzy.FuzzyInteger方法代码示例

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


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

示例1: test_dummy_web_profiles

# 需要导入模块: from factory import fuzzy [as 别名]
# 或者: from factory.fuzzy import FuzzyInteger [as 别名]
def test_dummy_web_profiles(self, enabled_profile_name, mock_payment):
        """
        Verify that the payment creation payload references a web profile when one is enabled with the expected name.
        This should occur when the create_and_set_webprofile waffle is disabled.
        """
        toggle_switch('create_and_set_webprofile', False)
        mock_payment_instance = mock.Mock()
        # NOTE: This is necessary to avoid the issue in https://code.djangoproject.com/ticket/25493.
        mock_payment_instance.id = FuzzyInteger(low=1).fuzz()
        mock_payment_instance.to_dict.return_value = {}
        mock_payment_instance.links = [mock.Mock(rel='approval_url', href='dummy')]
        mock_payment.return_value = mock_payment_instance

        if enabled_profile_name is not None:
            PaypalWebProfile.objects.create(name=enabled_profile_name, id='test-profile-id')

        self.processor.get_transaction_parameters(self.basket, request=self.request)
        payment_creation_payload = mock_payment.call_args[0][0]
        if enabled_profile_name == Paypal.DEFAULT_PROFILE_NAME:
            self.assertEqual(payment_creation_payload['experience_profile_id'], 'test-profile-id')
        else:
            self.assertNotIn('experience_profile_id', payment_creation_payload) 
开发者ID:edx,项目名称:ecommerce,代码行数:24,代码来源:test_paypal.py

示例2: test_web_profile_with_exception

# 需要导入模块: from factory import fuzzy [as 别名]
# 或者: from factory.fuzzy import FuzzyInteger [as 别名]
def test_web_profile_with_exception(self, mock_web_profile_init, mock_payment, mock_logger):
        """
        Verify that the payment creation payload does not reference a web profile if its creation results in exception.
        This should occur when the create_and_set_webprofile waffle is enabled.
        """
        toggle_switch('create_and_set_webprofile', True)
        mock_payment_instance = mock.Mock()
        # NOTE: This is necessary to avoid the issue in https://code.djangoproject.com/ticket/25493.
        mock_payment_instance.id = FuzzyInteger(low=1).fuzz()
        mock_payment_instance.to_dict.return_value = {}
        mock_payment_instance.links = [mock.Mock(rel='approval_url', href='dummy')]
        mock_payment.return_value = mock_payment_instance

        Paypal.resolve_paypal_locale = mock.Mock(return_value="valid_locale")
        mock_web_profile_init.side_effect = Exception('MissingConfig Exception')

        self.processor.get_transaction_parameters(self.basket, request=self.request)
        payment_creation_payload = mock_payment.call_args[0][0]
        self.assertNotIn('experience_profile_id', payment_creation_payload)
        with self.assertRaises(Exception) as ex:
            self.assertEqual(ex.message, 'MissingConfig Exception')

        msg = 'Creating PayPal WebProfile resulted in exception. Will continue without one.'
        mock_logger.warning.assert_any_call(msg) 
开发者ID:edx,项目名称:ecommerce,代码行数:26,代码来源:test_paypal.py

示例3: setUp

# 需要导入模块: from factory import fuzzy [as 别名]
# 或者: from factory.fuzzy import FuzzyInteger [as 别名]
def setUp(self):
        super(MarketingSiteAPIClientTestMixin, self).setUp()
        self.username = FuzzyText().fuzz()
        self.password = FuzzyText().fuzz()
        self.api_root = FuzzyUrlRoot().fuzz()
        self.csrf_token = FuzzyText().fuzz()
        self.user_id = FuzzyInteger(1).fuzz() 
开发者ID:edx,项目名称:course-discovery,代码行数:9,代码来源:mixins.py

示例4: test_web_profile_with_valid_locale

# 需要导入模块: from factory import fuzzy [as 别名]
# 或者: from factory.fuzzy import FuzzyInteger [as 别名]
def test_web_profile_with_valid_locale(self, mock_web_profile, mock_payment, mock_logger):
        """
        Verify that the payment creation payload references a web profile when a valid locale is chosen
        This should occur when the create_and_set_webprofile waffle is enabled.
        """
        toggle_switch('create_and_set_webprofile', True)
        mock_payment_instance = mock.Mock()
        # NOTE: This is necessary to avoid the issue in https://code.djangoproject.com/ticket/25493.
        mock_payment_instance.id = FuzzyInteger(low=1).fuzz()
        mock_payment_instance.to_dict.return_value = {}
        mock_payment_instance.links = [mock.Mock(rel='approval_url', href='dummy')]
        mock_payment.return_value = mock_payment_instance

        Paypal.resolve_paypal_locale = mock.Mock(return_value='valid_locale')
        mock_web_profile_instance = mock.Mock()
        mock_web_profile_instance.id = 'test-profile-id'
        mock_web_profile_instance.presentation.locale_code = 'valid_locale'
        mock_web_profile.create = mock.Mock(return_value=True)
        mock_web_profile.return_value = mock_web_profile_instance

        self.processor.get_transaction_parameters(self.basket, request=self.request)
        payment_creation_payload = mock_payment.call_args[0][0]
        self.assertEqual(payment_creation_payload['experience_profile_id'], 'test-profile-id')

        msg = 'Web Profile[%s] for locale %s created successfully' % (
            mock_web_profile_instance.id,
            mock_web_profile_instance.presentation.locale_code
        )
        mock_logger.info.assert_any_call(msg) 
开发者ID:edx,项目名称:ecommerce,代码行数:31,代码来源:test_paypal.py

示例5: test_web_profile_with_invalid_locale

# 需要导入模块: from factory import fuzzy [as 别名]
# 或者: from factory.fuzzy import FuzzyInteger [as 别名]
def test_web_profile_with_invalid_locale(self, mock_web_profile, mock_payment, mock_logger):
        """
        Verify that the payment creation payload does not reference a web profile when an invalid locale is chosen.
        This should occur when the create_and_set_webprofile waffle is enabled.
        """
        toggle_switch('create_and_set_webprofile', True)
        mock_payment_instance = mock.Mock()
        # NOTE: This is necessary to avoid the issue in https://code.djangoproject.com/ticket/25493.
        mock_payment_instance.id = FuzzyInteger(low=1).fuzz()
        mock_payment_instance.to_dict.return_value = {}
        mock_payment_instance.links = [mock.Mock(rel='approval_url', href='dummy')]
        mock_payment.return_value = mock_payment_instance

        Paypal.resolve_paypal_locale = mock.Mock(return_value='invalid_locale')
        mock_web_profile_instance = mock.Mock()
        mock_web_profile_instance.create = mock.Mock(return_value=False)
        mock_web_profile_instance.error = 'invalid_config'
        mock_web_profile.return_value = mock_web_profile_instance

        self.processor.get_transaction_parameters(self.basket, request=self.request)
        payment_creation_payload = mock_payment.call_args[0][0]
        self.assertNotIn('experience_profile_id', payment_creation_payload)

        msg = 'Web profile creation encountered error [%s]. Will continue without one' % (
            mock_web_profile_instance.error
        )
        mock_logger.warning.assert_any_call(msg) 
开发者ID:edx,项目名称:ecommerce,代码行数:29,代码来源:test_paypal.py

示例6: test_make_thumbnail

# 需要导入模块: from factory import fuzzy [as 别名]
# 或者: from factory.fuzzy import FuzzyInteger [as 别名]
def test_make_thumbnail(self):
        """
        Test that image output by make_thumbnail uses dimensions provided by make_small_dimensions
        """

        thumbnail_size = 64
        thumb_width = FuzzyInteger(1, 1024).fuzz()
        thumb_height = FuzzyInteger(1, 1024).fuzz()
        # To do the asserts correctly thumbnail dimensions have to have the same aspect ratio
        width = thumb_width * 4
        height = thumb_height * 4

        image = Image.new('RGBA', (width, height))
        full_image_file = BytesIO()
        image.save(full_image_file, "PNG")
        full_image_file.seek(0)

        with patch(
            'profiles.util.shrink_dimensions',
            return_value=(thumb_width, thumb_height, thumbnail_size)
        ) as mocked:
            thumb_file = util.make_thumbnail(full_image_file, 64)
            thumb_image = Image.open(thumb_file)
            mocked.assert_called_with(width, height, thumbnail_size)
            assert thumb_image.width == thumb_width
            assert thumb_image.height == thumb_height 
开发者ID:mitodl,项目名称:micromasters,代码行数:28,代码来源:util_test.py


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