Example #1
0
 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)
Example #2
0
 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)
Example #3
0
 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])
Example #4
0
 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))
Example #5
0
 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()))
Example #6
0
 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))
Example #7
0
 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")
Example #8
0
 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)
Example #9
0
 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')
Example #10
0
 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()')
Example #11
0
 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)
Example #12
0
 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)
Example #13
0
 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())
Example #14
0
 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)
Example #15
0
 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)
Example #16
0
 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())
Example #17
0
 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])
Example #18
0
 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)
Example #19
0
 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()
Example #20
0
 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)
Example #21
0
 def test_dummy_form_save_credit_number(self):
     """
     Test that dummy payment form save method save order
     """
     wizard = PrePaymentWizard()
     cart = model_factory(Cart, save=True)
     wizard.order = model_factory(Order, cart=cart)
     form = DummyPaymentForm()
     form.cleaned_data = FORM_CLEANED_DATA
     order = form.save(wizard)
     self.assertEqual(order.card_number, '1111')
Example #22
0
 def test_view(self):
     """ Test signup view process """
     model_factory(EmailTemplate, template_key="invitation_email", save=True)
     resp = self.app.get(reverse("accounts:signup"))
     form = resp.form
     form["username"] = "******"
     form["password1"] = "password"
     form["password2"] = "password"
     form["email"] = get_fake_email()
     response = form.submit()
     self.assertEqual(response.status, "302 FOUND")
Example #23
0
 def test_dummy_sucsess_remove_cart_from_session(self):
     """
     Test that success method call remove_cart_from_session
     """
     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.cart.models.CartManager.remove_cart_from_session')\
                                                                 as remove:
         dummy_success_view(request=request).get_context_data()
         remove.assert_called_once_with(request)
Example #24
0
 def test_clear_cart(self):
     cart = Cart.objects.create_active()
     product = model_factory(Product, save=True)
     product_variation = model_factory(ProductVariation, product=product,
                                       save=True)
     discount = model_factory(Discount, save=True)
     cart.discount.add(discount)
     cart_item = model_factory(CartItem, cart=cart,
                               product=product_variation, save=True)
     self.assertTrue(bool(cart.items.all()))
     cart.clear_cart()
     self.assertFalse(bool(cart.items.all()))
Example #25
0
 def test_get_quantity(self):
     cart = Cart.objects.create_active()
     product = model_factory(Product, save=True)
     product_variation = model_factory(ProductVariation, product=product,
                                       save=True)
     discount = model_factory(Discount, save=True)
     cart.discount.add(discount)
     cart_item = model_factory(CartItem, cart=cart,
                               product=product_variation,
                               quantity=10,
                               save=True)
     self.assertEqual(cart.get_quantity(), 10)
Example #26
0
 def test_generate_duration_choice_method(self):
     """
     Test that method generate currect choices
     """
     subscription = model_factory(Subscription, save=True)
     duration = model_factory(Duration, product=subscription, price=12,
                                                                 save=True)
     expected_value = [(duration.id, "{0} days for ${1}.00".format(
                                                 duration.duration.days,
                                                 duration.price))]
     current_value = generate_duration_choice(subscription.id)
     self.assertEqual(expected_value, current_value)
Example #27
0
 def test_create_active_with_contact(self):
     """
     Test that create_active creates active cart with contact
     and update other carts to be inactive
     """
     contact = model_factory(Contact, save=True)
     old_cart = model_factory(Cart, contact=contact, is_active=True,
                              save=True)
     new_cart = Cart.objects.create_active(contact=contact)
     self.assertTrue(new_cart.is_active)
     old_cart = Cart.objects.get(id=old_cart.id)
     self.assertFalse(old_cart.is_active)
Example #28
0
 def test_add_new_product(self):
     """
     Test that cart item created if product not in cart yet
     """
     cart = model_factory(Cart, save=True)
     product = model_factory(Product, save=True)
     product_variation = model_factory(ProductVariation, items_in_stock=1,
                                                 product=product, save=True)
     cart.add_product(product_variation)
     actual_cart_item = cart.items.get()
     self.assertEqual(actual_cart_item.quantity, 1)
     self.assertEqual(actual_cart_item.product, product_variation)
Example #29
0
 def test_base_address_save(self):
     """
     Test that form save address with shipping=True and address is saved
     """
     wizard = PrePaymentWizard()
     wizard.contact = model_factory(Contact, save=True)
     address = model_factory(Address)
     form = BaseAddressForm()
     with patch('django.forms.ModelForm.save', Mock(return_value=address)):
         address = form.save(wizard=wizard)
     self.assertTrue(address.pk is not None)
     self.assertEqual(address.contact, wizard.contact)
Example #30
0
 def test_get(self):
     cart = Cart.objects.create_active()
     product = model_factory(Product, save=True)
     product_variation = model_factory(ProductVariation, product=product,
                                       save=True)
     user = model_factory(User, save=True)
     request = RequestFactory().get('/')
     request.user = user
     request.cart = cart
     view = CartItemAddView()
     with patch('salest.cart.models.Cart.add_product', Mock()) as test_cart:
         view.get(request, product_variation.id)
         test_cart.assert_called_once_with(product_variation)