本文整理汇总了Python中test_tools.utils.model_factory函数的典型用法代码示例。如果您正苦于以下问题:Python model_factory函数的具体用法?Python model_factory怎么用?Python model_factory使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了model_factory函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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)
示例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])
示例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))
示例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()))
示例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))
示例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")
示例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)
示例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')
示例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()')
示例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)
示例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)
示例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())
示例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)
示例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)