• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python utils.model_factory函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中test_tools.utils.model_factory函数的典型用法代码示例。如果您正苦于以下问题:Python model_factory函数的具体用法?Python model_factory怎么用?Python model_factory使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_subscription_property

 def test_subscription_property(self):
     """
     Test that property return write subscription
     """
     subscription = model_factory(Subscription, save=True)
     duration = model_factory(Duration, product=subscription)
     self.assertEqual(duration.subscription, subscription)
开发者ID:anvileight,项目名称:salest,代码行数:7,代码来源:models.py


示例2: test_order_comfirm_method_cart

 def test_order_comfirm_method_cart(self):
     """
     Test that method set cart as no active
     """
     cart = model_factory(Cart, is_active=True, save=True)
     order = model_factory(Order, cart=cart, save=True)
     order.confirm()
     self.assertFalse(cart.is_active)
开发者ID:anvileight,项目名称:salest,代码行数:8,代码来源:models.py


示例3: test_min_variation

 def test_min_variation(self):
     product = model_factory(Product, save=True)
     self.assertEqual(product.min_variation(), None)
     variations = model_factory(ProductVariation,
                                product = [product, product],
                                price = [10, 20],
                                save=True)
     self.assertEqual(product.min_variation(), variations[0])
开发者ID:anvileight,项目名称:salest,代码行数:8,代码来源:models.py


示例4: test_authenticate

 def test_authenticate(self):
     """ Test that backend can authenticate user """
     code = 'test_code'
     expected_user = model_factory(User, save=True)
     model_factory(UserConfirmation, key=code,
                   user=expected_user, save=True)
     backend = ConfirmationUserBackend()
     self.assertEqual(expected_user, backend.authenticate(code))
开发者ID:anvileight,项目名称:salest,代码行数:8,代码来源:backends.py


示例5: test_get_discounts

 def test_get_discounts(self):
     """ Test has_discount method """
     expected = model_factory(Discount, end_date=datetime.now(),
                              start_date=datetime.now(),
                              save=True)
     user = model_factory(User, save=True)
     expected.valid_users.add(user.contact)
     self.assertEqual([expected], list(user.contact.get_discounts_list()))
开发者ID:anvileight,项目名称:salest,代码行数:8,代码来源:models.py


示例6: test_unicode

 def test_unicode(self):
     """ Test that profile return valid username """
     expeced_value = 'test_username'
     user = model_factory(User, username=expeced_value, save=True)
     profile = Contact.objects.get(user=user)
     self.assertEqual(expeced_value, str(profile))
     profile = model_factory(Contact, save=True)
     self.assertEqual('Anonimus', str(profile))
开发者ID:anvileight,项目名称:salest,代码行数:8,代码来源:models.py


示例7: test_confirm_view

 def test_confirm_view(self):
     """ Test confirmation view """
     confirm_key = "some_key"
     user = model_factory(User, save=True)
     model_factory(UserConfirmation, key=confirm_key, user=user, save=True)
     response = self.app.get(reverse("accounts:confirm"), params={"key": confirm_key})
     self.assertEqual(self.app.session[SESSION_KEY], user.id)
     self.assertEqual(response.status, "200 OK")
开发者ID:anvileight,项目名称:salest,代码行数:8,代码来源:signup.py


示例8: test_set_no_active_method

 def test_set_no_active_method(self):
     """
     Test that method set cart as no active
     """
     contact = model_factory(Contact, save=True)
     cart = model_factory(Cart, contact=contact, save=True)
     cart.set_no_active()
     self.assertFalse(cart.is_active)
开发者ID:anvileight,项目名称:salest,代码行数:8,代码来源:cart.py


示例9: test_order_confirm_order_status

 def test_order_confirm_order_status(self):
     """
     Test that method change order status
     """
     cart = model_factory(Cart, is_active=True, save=True)
     order = model_factory(Order, cart=cart, save=True)
     order.confirm()
     self.assertEqual(order.status, 'Billed')
开发者ID:anvileight,项目名称:salest,代码行数:8,代码来源:models.py


示例10: test_unicode

 def test_unicode(self):
     product = model_factory(Product,
                             name='test',
                             save=True)
     variation = model_factory(ProductVariation,
                               price=10,
                               product=product,
                               save=True)
     self.assertEqual(str(variation), 'test()')
开发者ID:anvileight,项目名称:salest,代码行数:9,代码来源:models.py


示例11: test_add_out_of_stock_product

 def test_add_out_of_stock_product(self):
     """
     Test that product can't be added if it out of stock
     """
     cart = model_factory(Cart, save=True)
     product = model_factory(Product, save=True)
     product_variation = model_factory(ProductVariation, items_in_stock=0,
                                                 product=product, save=True)
     self.assertRaises(AssertionError, cart.add_product, product_variation)
开发者ID:anvileight,项目名称:salest,代码行数:9,代码来源:cart.py


示例12: test_get_existed_user

 def test_get_existed_user(self):
     """ Test that cart can gets for anonymous user """
     request = RequestFactory().get('/')
     user = model_factory(User, save=True)
     expected_cart = model_factory(Cart, contact=user.contact,
                                   is_active=True, save=True)
     request.user = user
     actual_cart = Cart.objects.get_or_create_from_request(request)
     self.assertEqual(expected_cart, actual_cart)
开发者ID:anvileight,项目名称:salest,代码行数:9,代码来源:cart.py


示例13: test_has_discount

 def test_has_discount(self):
     """ Test has_discount method """
     discount = model_factory(Discount, end_date=datetime.now(),
                              start_date=datetime.now(),
                              save=True)
     user = model_factory(User, save=True)
     self.assertFalse(user.contact.has_discount())
     discount.valid_users.add(user.contact)
     self.assertTrue(user.contact.has_discount())
开发者ID:anvileight,项目名称:salest,代码行数:9,代码来源:models.py


示例14: test_get_items_price

 def test_get_items_price(self):
     cart = Cart.objects.create_active()
     product = model_factory(Product, save=True)
     product_variation = model_factory(ProductVariation, product=product,
                                       save=True)
     cart_item = model_factory(CartItem, cart=cart,
                               product=product_variation, save=True)
     with patch('salest.cart.models.CartItem.get_cart_item_price',
               Mock(return_value=10)):
         self.assertEqual(cart.get_items_price(), 10)
开发者ID:anvileight,项目名称:salest,代码行数:10,代码来源:cart.py


示例15: test_create_with_request_user

 def test_create_with_request_user(self):
     """ Test that cart can be created from request and user logged in """
     request = RequestFactory().get('/')
     user = model_factory(User, save=True)
     request.user = user
     expected_cart = model_factory(Cart)
     with patch('salest.cart.models.CartManager.create_active',
                Mock(return_value=expected_cart)) as active:
         Cart.objects.get_or_create_from_request(request)
         active.assert_called_once_with(contact=user.contact)
开发者ID:anvileight,项目名称:salest,代码行数:10,代码来源:cart.py


示例16: test_confirm_method

 def test_confirm_method(self):
     """
     Test that method add user
     """
     user = model_factory(User, save=True)
     subscription = model_factory(Subscription, save=True)
     duration = model_factory(Duration, product=subscription, price=1,
                                                                 save=True)
     duration.confirm(user)
     self.assertTrue(user in duration.users.all())
开发者ID:anvileight,项目名称:salest,代码行数:10,代码来源:models.py


示例17: test_get_items

 def test_get_items(self):
     cart = Cart.objects.create_active()
     product = model_factory(Product, save=True)
     product_variation = model_factory(ProductVariation, product=product,
                                       save=True)
     cart_item = model_factory(CartItem, cart=cart,
                               product=product_variation,
                               quantity=10,
                               save=True)
     self.assertEqual(list(cart.get_items()), [cart_item])
开发者ID:anvileight,项目名称:salest,代码行数:10,代码来源:cart.py


示例18: test_authenticate_invalid

 def test_authenticate_invalid(self):
     """
     Test that backend skip authentication of invalid user confirmations
     codes
     """
     expected_user = model_factory(User, save=True)
     model_factory(UserConfirmation, key='test_code',
                   user=expected_user, save=True)
     backend = ConfirmationUserBackend()
     self.assertTrue(backend.authenticate('another code') is None)
开发者ID:anvileight,项目名称:salest,代码行数:10,代码来源:backends.py


示例19: test_dummy_sucsess_get_context_data_confirm

 def test_dummy_sucsess_get_context_data_confirm(self):
     """
     Test that method call order confirm method
     """
     cart = model_factory(Cart, is_active=True, save=True)
     order = model_factory(Order, cart=cart, save=True)
     request = RequestFactory().post('/', {'order_id': order.id})
     request.session = {}
     with patch('salest.payments.models.Order.confirm') as confirm:
         dummy_success_view(request=request).get_context_data()
         confirm.assert_called_once_with()
开发者ID:anvileight,项目名称:salest,代码行数:11,代码来源:modules.py


示例20: test_get_404

 def test_get_404(self):
     product = model_factory(Product, save=True)
     product_variation = model_factory(ProductVariation, product=product,
                                       save=True)
     cart = Cart.objects.create_active()
     user = model_factory(User, save=True)
     request = RequestFactory().get('/')
     request.user = user
     request.cart = cart
     view = CartItemAddView()
     self.assertRaises(Http404, view.get, request, 0)
开发者ID:anvileight,项目名称:salest,代码行数:11,代码来源:views.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python test_util.fileurl函数代码示例发布时间:2022-05-27
下一篇:
Python test_env.setup_test_env函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap