class SignalHandlerBaseTestCase(object): """ Base test case class for test classes that test signal handlers. """ def setUp(self): self.user = User.objects.create(username="******", email="*****@*****.**") self.request = Mock() setattr(self.request, 'user', self.user) self.order = Order() self.order.user = self.user self.order.order_subtotal = decimal.Decimal('10') self.order.order_total = decimal.Decimal('10') self.order.shipping_cost = decimal.Decimal('0') self.order.shipping_address_text = 'shipping address example' self.order.billing_address_text = 'billing address example' self.order.save() self.rendered_templates = [] template_rendered.connect(self.template_rendered_listener) def tearDown(self): template_rendered.disconnect(self.template_rendered_listener) def template_rendered_listener(self, **kwargs): self.rendered_templates.append(kwargs.get('sender')) def was_template_rendered(self, name): for template in self.rendered_templates: if template.name == name: return True return False
class SignalHandlerBaseTestCase(object): """ Base test case class for test classes that test signal handlers. """ def setUp(self): self.user = User.objects.create( username="******", email="*****@*****.**") self.request = Mock() setattr(self.request, 'user', self.user) self.order = Order() self.order.user = self.user self.order.order_subtotal = decimal.Decimal('10') self.order.order_total = decimal.Decimal('10') self.order.shipping_cost = decimal.Decimal('0') self.order.shipping_address_text = 'shipping address example' self.order.billing_address_text = 'billing address example' self.order.save() self.rendered_templates = [] template_rendered.connect(self.template_rendered_listener) def tearDown(self): template_rendered.disconnect(self.template_rendered_listener) def template_rendered_listener(self, **kwargs): self.rendered_templates.append(kwargs.get('sender')) def was_template_rendered(self, name): for template in self.rendered_templates: if template.name == name: return True return False
def create_fixtures(self): self.user = User.objects.create(username="******", email="*****@*****.**", first_name="Test", last_name="Toto") backends_pool.USE_CACHE = False self.order = Order() self.order.order_subtotal = Decimal('10') self.order.order_total = Decimal('10') self.order.amount_payed = Decimal('0') self.order.shipping_cost = Decimal('0') self.order.shipping_name = 'toto' self.order.shipping_address = 'address' self.order.shipping_address2 = 'address2' self.order.shipping_zip_code = 'zip' self.order.shipping_state = 'state' self.order.shipping_country = 'country' self.order.billing_name = 'toto' self.order.billing_address = 'address' self.order.billing_address2 = 'address2' self.order.billing_zip_code = 'zip' self.order.billing_state = 'state' self.order.billing_country = 'country' self.order.save()
def create_fixtures(self): self.user = User.objects.create(username="******", email="*****@*****.**") self.request = Mock() setattr(self.request, 'user', None) self.order = Order() self.order.order_subtotal = Decimal('10') self.order.order_total = Decimal('10') self.order.amount_payed = Decimal('0') self.order.shipping_cost = Decimal('0') self.order.shipping_name = 'toto' self.order.shipping_address = 'address' self.order.shipping_address2 = 'address2' self.order.shipping_zip_code = 'zip' self.order.shipping_state = 'state' self.order.shipping_country = 'country' self.order.billing_name = 'toto' self.order.billing_address = 'address' self.order.billing_address2 = 'address2' self.order.billing_zip_code = 'zip' self.order.billing_state = 'state' self.order.billing_country = 'country' self.order.save()
def setUp(self): self.user = User.objects.create(username="******", email="*****@*****.**", first_name="Mary-Jane", last_name="Watson") self.order = Order() self.order.order_subtotal = Decimal('10') self.order.order_total = Decimal('10') self.order.shipping_cost = Decimal('0') self.address = AddressModel.objects.create( name="Mary-Jane Watson", address="Main Street 123", address2="c/o Someone", zip_code="12345", city="Anytown", state="N/A", user_shipping=self.user, user_billing=self.user, ) self.order.shipping_address_text = self.address.as_text() self.order.billing_address_text = self.address.as_text() self.order.save()
class OrderTestCase(TestCase): def create_fixtures(self): self.order = Order() self.order.order_subtotal = Decimal('10') self.order.order_total = Decimal('10') self.order.amount_payed = Decimal('0') self.order.shipping_cost = Decimal('0') self.order.shipping_name = 'toto' self.order.shipping_address = 'address' self.order.shipping_address2 = 'address2' self.order.shipping_zip_code = 'zip' self.order.shipping_state = 'state' self.order.shipping_country = 'country' self.order.billing_name = 'toto' self.order.billing_address = 'address' self.order.billing_address2 = 'address2' self.order.billing_zip_code = 'zip' self.order.billing_state = 'state' self.order.billing_country = 'country' self.order.save() def test_01_order_is_completed_works(self): self.create_fixtures() ret = self.order.is_completed() self.assertNotEqual(ret, Order.COMPLETED) def test_02_is_payed_works(self): self.create_fixtures() ret = self.order.is_payed() self.assertEqual(ret, False)
class OrderTestCase(TestCase): def setUp(self): self.order = Order() self.order.order_subtotal = Decimal("10") self.order.order_total = Decimal("10") self.order.shipping_cost = Decimal("0") self.order.shipping_name = "toto" self.order.shipping_address = "address" self.order.shipping_address2 = "address2" self.order.shipping_zip_code = "zip" self.order.shipping_state = "state" self.order.shipping_country = "country" self.order.billing_name = "toto" self.order.billing_address = "address" self.order.billing_address2 = "address2" self.order.billing_zip_code = "zip" self.order.billing_state = "state" self.order.billing_country = "country" self.order.save() def test_order_is_completed_works(self): ret = self.order.is_completed() self.assertNotEqual(ret, Order.COMPLETED) def test_is_payed_works(self): ret = self.order.is_payed() self.assertEqual(ret, False)
class ProductStatisticsTestCase(TestCase): def setUp(self): self.product = Product() self.product.name = 'test' self.product.unit_price = Decimal('1.0') self.product.save() self.product2 = Product() self.product2.name = 'test2' self.product2.unit_price = Decimal('1.0') self.product2.save() self.product3 = Product() self.product3.name = 'test3' self.product3.unit_price = Decimal('1.0') self.product3.save() self.order = Order() self.order.order_subtotal = Decimal('10') self.order.order_total = Decimal('10') self.order.shipping_cost = Decimal('0') self.order.shipping_name = 'toto' self.order.shipping_address = 'address' self.order.shipping_address2 = 'address2' self.order.shipping_city = 'city' self.order.shipping_zip_code = 'zip' self.order.shipping_state = 'state' self.order.shipping_country = 'country' self.order.billing_name = 'toto' self.order.billing_address = 'address' self.order.billing_address2 = 'address2' self.order.billing_city = 'city' self.order.billing_zip_code = 'zip' self.order.billing_state = 'state' self.order.billing_country = 'country' self.order.save() self.orderitem1 = OrderItem() self.orderitem1.order = self.order self.orderitem1.product = self.product self.orderitem1.quantity = 5 # this will be the most bought self.orderitem1.save() self.orderitem2 = OrderItem() self.orderitem2.order = self.order self.orderitem2.product = self.product2 self.orderitem2.quantity = 1 # this will be the second most self.orderitem2.save() def test_top_selling_works(self): res = Product.statistics.top_selling_products(10) self.assertNotEqual(res, None) self.assertEqual(len(res), 2) self.assertTrue(self.product3 not in res)
class OrderPaymentTestCase(TestCase): def create_fixtures(self): self.user = User.objects.create(username="******", email="*****@*****.**") self.request = Mock() setattr(self.request, 'user', None) self.order = Order() self.order.order_subtotal = Decimal('10') self.order.order_total = Decimal('10') self.order.shipping_cost = Decimal('0') self.order.shipping_name = 'toto' self.order.shipping_address = 'address' self.order.shipping_address2 = 'address2' self.order.shipping_zip_code = 'zip' self.order.shipping_state = 'state' self.order.shipping_country = 'country' self.order.billing_name = 'toto' self.order.billing_address = 'address' self.order.billing_address2 = 'address2' self.order.billing_zip_code = 'zip' self.order.billing_state = 'state' self.order.billing_country = 'country' self.order.save() def test_payment_sum_works(self): self.create_fixtures() self.assertEqual(self.order.amount_payed, 0) def test_payment_sum_works_with_partial_payments(self): self.create_fixtures() OrderPayment.objects.create( order = self.order, amount = Decimal('2'), transaction_id = 'whatever', payment_method = 'test method' ) self.assertEqual(self.order.amount_payed, 2) self.assertEqual(self.order.is_payed(), False) def test_payment_sum_works_with_full_payments(self): self.create_fixtures() OrderPayment.objects.create( order = self.order, amount = Decimal('10'), transaction_id = 'whatever', payment_method = 'test method' ) self.assertEqual(self.order.amount_payed, 10) self.assertEqual(self.order.is_payed(), True)
def setUp(self): self.order = Order() self.order.order_subtotal = Decimal('10') self.order.order_total = Decimal('10') self.order.shipping_cost = Decimal('0') self.order.shipping_address_text = 'shipping address example' self.order.billing_address_text = 'billing address example' self.order.save()
class ShippingApiTestCase(TestCase): def create_fixtures(self): self.user = User.objects.create(username="******", email="*****@*****.**") self.request = Mock() setattr(self.request, 'user', None) self.order = Order() self.order.order_subtotal = Decimal('10') self.order.order_total = Decimal('10') self.order.shipping_cost = Decimal('0') self.order.shipping_name = 'toto' self.order.shipping_address = 'address' self.order.shipping_address2 = 'address2' self.order.shipping_city = 'city' self.order.shipping_zip_code = 'zip' self.order.shipping_state = 'state' self.order.shipping_country = 'country' self.order.billing_name = 'toto' self.order.billing_address = 'address' self.order.billing_address2 = 'address2' self.order.billing_city = 'city' self.order.billing_zip_code = 'zip' self.order.billing_state = 'state' self.order.billing_country = 'country' self.order.save() self.shipping_label = "Shipping" self.shipping_value = Decimal("10") def test_adding_shipping_costs_work(self): self.create_fixtures() api = ShippingAPI() api.add_shipping_costs(self.order, self.shipping_label, self.shipping_value) self.assertEqual(self.order.shipping_costs, self.shipping_value) self.assertEqual(self.order.order_total, (self.order.order_subtotal + self.shipping_value)) def test_adding_shipping_costs_twice_works(self): # That should test against #39 regressions self.create_fixtures() api = ShippingAPI() api.add_shipping_costs(self.order, self.shipping_label, self.shipping_value) api.add_shipping_costs(self.order, self.shipping_label, self.shipping_value) self.assertEqual(self.order.shipping_costs, self.shipping_value) self.assertEqual(self.order.order_total, (self.order.order_subtotal + self.shipping_value))
class OrderPaymentTestCase(TestCase): def create_fixtures(self): self.user = User.objects.create(username="******", email="*****@*****.**") self.request = Mock() setattr(self.request, 'user', None) self.order = Order() self.order.order_subtotal = Decimal('10') self.order.order_total = Decimal('10') self.order.shipping_cost = Decimal('0') self.order.shipping_name = 'toto' self.order.shipping_address = 'address' self.order.shipping_address2 = 'address2' self.order.shipping_zip_code = 'zip' self.order.shipping_state = 'state' self.order.shipping_country = 'country' self.order.billing_name = 'toto' self.order.billing_address = 'address' self.order.billing_address2 = 'address2' self.order.billing_zip_code = 'zip' self.order.billing_state = 'state' self.order.billing_country = 'country' self.order.save() def test_payment_sum_works(self): self.create_fixtures() self.assertEqual(self.order.amount_payed, 0) def test_payment_sum_works_with_partial_payments(self): self.create_fixtures() OrderPayment.objects.create(order=self.order, amount=Decimal('2'), transaction_id='whatever', payment_method='test method') self.assertEqual(self.order.amount_payed, 2) self.assertEqual(self.order.is_payed(), False) def test_payment_sum_works_with_full_payments(self): self.create_fixtures() OrderPayment.objects.create(order=self.order, amount=Decimal('10'), transaction_id='whatever', payment_method='test method') self.assertEqual(self.order.amount_payed, 10) self.assertEqual(self.order.is_payed(), True)
def setUp(self): self.user = User.objects.create(username="******", email="*****@*****.**") self.request = Mock() setattr(self.request, 'user', None) self.order = Order() self.order.order_subtotal = Decimal('10') self.order.order_total = Decimal('10') self.order.shipping_cost = Decimal('0') self.order.shipping_address_text = 'shipping address example' self.order.billing_address_text = 'billing address example' self.order.save()
def setUp(self): self.user = User.objects.create(username="******", email="*****@*****.**") self.request = Mock() setattr(self.request, 'user', None) self.order = Order() self.order.order_subtotal = Decimal('10') self.order.order_total = Decimal('10') self.order.shipping_cost = Decimal('0') self.order.shipping_name = 'toto' self.order.shipping_address = 'address' self.order.shipping_address2 = 'address2' self.order.shipping_city = 'city' self.order.shipping_zip_code = 'zip' self.order.shipping_state = 'state' self.order.shipping_country = 'country' self.order.billing_name = 'toto' self.order.billing_address = 'address' self.order.billing_address2 = 'address2' self.order.billing_city = 'city' self.order.billing_zip_code = 'zip' self.order.billing_state = 'state' self.order.billing_country = 'country' self.order.save() self.shipping_label = "Shipping" self.shipping_value = Decimal("10")
def setUp(self): self.user = User.objects.create(username="******", email="*****@*****.**", first_name="Test", last_name = "Toto") backends_pool.use_cache = False self.order = Order() self.order.order_subtotal = Decimal('10') self.order.order_total = Decimal('10') self.order.shipping_cost = Decimal('0') self.order.shipping_name = 'toto' self.order.shipping_address = 'address' self.order.shipping_address2 = 'address2' self.order.shipping_zip_code = 'zip' self.order.shipping_state = 'state' self.order.shipping_country = 'country' self.order.billing_name = 'toto' self.order.billing_address = 'address' self.order.billing_address2 = 'address2' self.order.billing_zip_code = 'zip' self.order.billing_state = 'state' self.order.billing_country = 'country' self.order.save()
def test_order_required_before_shipping_processed(self): """ See issue #84 """ # Session only (no order) response = self.client.get(reverse('flat_process')) self.assertEqual(response.status_code, 302) # User logged in (no order) view = self.backend.view_process_order(self.request) self.assertEqual(view.get('location', None), '/') # User logged in with order order = Order() setattr(order, 'user', self.user) order.save() view = self.backend.view_process_order(self.request) self.assertEqual(view.get('location', None), reverse('checkout_confirm'))
def setUp(self): self.user = User.objects.create(username="******", email="*****@*****.**") self.request = Mock() setattr(self.request, "user", None) self.order = Order() self.order.order_subtotal = Decimal("10") self.order.order_total = Decimal("10") self.order.shipping_cost = Decimal("0") self.order.shipping_name = "toto" self.order.shipping_address = "address" self.order.shipping_address2 = "address2" self.order.shipping_zip_code = "zip" self.order.shipping_state = "state" self.order.shipping_country = "country" self.order.billing_name = "toto" self.order.billing_address = "address" self.order.billing_address2 = "address2" self.order.billing_zip_code = "zip" self.order.billing_state = "state" self.order.billing_country = "country" self.order.save()
def test_order_required_before_shipping_processed(self): """ See issue #84 """ # Session only (no order) response = self.client.get(reverse('flat_process')) self.assertEqual(response.status_code, 302) # User logged in (no order) view = self.backend.view_process_order(self.request) self.assertEqual(view.get('location', None), '/shop/cart/') # User logged in with order order = Order() setattr(order, 'user', self.user) order.save() view = self.backend.view_process_order(self.request) self.assertEqual(view.get('location', None), reverse('checkout_confirm'))
def setUp(self): self.user = User.objects.create(username='******', email='*****@*****.**', first_name='Test', last_name='Toto') backends_pool.use_cache = False self.order = Order() self.order.order_subtotal = Decimal('10') self.order.order_total = Decimal('10') self.order.shipping_cost = Decimal('0') self.order.shipping_address_text = 'shipping address example' self.order.billing_address_text = 'billing address example' self.order.save()
def setUp(self): self.user = User.objects.create( username="******", email="*****@*****.**", first_name="Mary-Jane", last_name="Watson") self.order = Order() self.order.order_subtotal = Decimal('10') self.order.order_total = Decimal('10') self.order.shipping_cost = Decimal('0') self.address = AddressModel.objects.create( name="Mary-Jane Watson", address="Main Street 123", address2="c/o Someone", zip_code="12345", city="Anytown", state="N/A", user_shipping=self.user, user_billing=self.user, ) self.order.shipping_address_text = self.address.as_text() self.order.billing_address_text = self.address.as_text() self.order.save()
class ProductStatisticsTestCase(TestCase): def setUp(self): self.product = Product() self.product.name = 'test' self.product.slug = 'test' self.product.unit_price = Decimal('1.0') self.product.save() self.product2 = Product() self.product2.name = 'test2' self.product2.slug = 'test2' self.product2.unit_price = Decimal('1.0') self.product2.save() self.product3 = Product() self.product3.name = 'test3' self.product3.slug = 'test3' self.product3.unit_price = Decimal('1.0') self.product3.save() self.order = Order() self.order.order_subtotal = Decimal('10') self.order.order_total = Decimal('10') self.order.shipping_cost = Decimal('0') self.order.shipping_address_text = 'shipping address example' self.order.billing_address_text = 'billing address example' self.order.save() self.orderitem1 = OrderItem() self.orderitem1.order = self.order self.orderitem1.product = self.product self.orderitem1.quantity = 5 # this will be the most bought self.orderitem1.save() self.orderitem2 = OrderItem() self.orderitem2.order = self.order self.orderitem2.product = self.product2 self.orderitem2.quantity = 1 # this will be the second most self.orderitem2.save() def test_top_selling_works(self): res = Product.statistics.top_selling_products(10) self.assertNotEqual(res, None) self.assertEqual(len(res), 2) self.assertTrue(self.product3 not in res)
def setUp(self): self.user = User.objects.create(username="******", email="*****@*****.**") self.request = Mock() setattr(self.request, 'user', self.user) self.order = Order() self.order.user = self.user self.order.order_subtotal = decimal.Decimal('10') self.order.order_total = decimal.Decimal('10') self.order.shipping_cost = decimal.Decimal('0') self.order.shipping_address_text = 'shipping address example' self.order.billing_address_text = 'billing address example' self.order.save() self.rendered_templates = [] template_rendered.connect(self.template_rendered_listener)
class OrderPaymentTestCase(TestCase): def setUp(self): self.user = User.objects.create(username="******", email="*****@*****.**") self.request = Mock() setattr(self.request, "user", None) self.order = Order() self.order.order_subtotal = Decimal("10") self.order.order_total = Decimal("10") self.order.shipping_cost = Decimal("0") self.order.shipping_name = "toto" self.order.shipping_address = "address" self.order.shipping_address2 = "address2" self.order.shipping_zip_code = "zip" self.order.shipping_state = "state" self.order.shipping_country = "country" self.order.billing_name = "toto" self.order.billing_address = "address" self.order.billing_address2 = "address2" self.order.billing_zip_code = "zip" self.order.billing_state = "state" self.order.billing_country = "country" self.order.save() def test_payment_sum_works(self): self.assertEqual(self.order.amount_payed, Decimal("-1")) def test_payment_sum_works_with_partial_payments(self): OrderPayment.objects.create( order=self.order, amount=Decimal("2"), transaction_id="whatever", payment_method="test method" ) self.assertEqual(self.order.amount_payed, 2) self.assertEqual(self.order.is_payed(), False) def test_payment_sum_works_with_full_payments(self): OrderPayment.objects.create( order=self.order, amount=Decimal("10"), transaction_id="whatever", payment_method="test method" ) self.assertEqual(self.order.amount_payed, 10) self.assertEqual(self.order.is_payed(), True)
class ShippingApiTestCase(TestCase): def setUp(self): self.user = User.objects.create(username="******", email="*****@*****.**") self.request = Mock() setattr(self.request, 'user', None) self.order = Order() self.order.order_subtotal = Decimal('10') self.order.order_total = Decimal('10') self.order.shipping_cost = Decimal('0') self.order.shipping_address_text = 'shipping address example' self.order.billing_address_text = 'billing address example' self.order.save() self.shipping_label = "Shipping" self.shipping_value = Decimal("10") def test_adding_shipping_costs_work(self): api = ShippingAPI() api.add_shipping_costs(self.order, self.shipping_label, self.shipping_value) self.assertEqual(self.order.shipping_costs, self.shipping_value) self.assertEqual(self.order.order_total, (self.order.order_subtotal + self.shipping_value)) def test_adding_shipping_costs_twice_works(self): # That should test against #39 regressions api = ShippingAPI() api.add_shipping_costs(self.order, self.shipping_label, self.shipping_value) api.add_shipping_costs(self.order, self.shipping_label, self.shipping_value) self.assertEqual(self.order.shipping_costs, self.shipping_value) self.assertEqual(self.order.order_total, (self.order.order_subtotal + self.shipping_value))
class OrderTestCase(TestCase): def setUp(self): self.order = Order() self.order.order_subtotal = Decimal('10') self.order.order_total = Decimal('10') self.order.shipping_cost = Decimal('0') self.order.shipping_address_text = 'shipping address example' self.order.billing_address_text = 'billing address example' self.order.save() def test_order_is_completed_works(self): ret = self.order.is_completed() self.assertNotEqual(ret, Order.COMPLETED) def test_is_payed_works(self): ret = self.order.is_payed() self.assertEqual(ret, False)
class OrderPaymentTestCase(TestCase): def setUp(self): self.user = User.objects.create(username="******", email="*****@*****.**") self.request = Mock() setattr(self.request, 'user', None) self.order = Order() self.order.order_subtotal = Decimal('10') self.order.order_total = Decimal('10') self.order.shipping_cost = Decimal('0') self.order.shipping_address_text = 'shipping address example' self.order.billing_address_text = 'billing address example' self.order.save() def test_payment_sum_works(self): self.assertEqual(self.order.amount_payed, Decimal('-1')) def test_payment_sum_works_with_partial_payments(self): OrderPayment.objects.create( order = self.order, amount = Decimal('2'), transaction_id = 'whatever', payment_method = 'test method' ) self.assertEqual(self.order.amount_payed, 2) self.assertEqual(self.order.is_payed(), False) def test_payment_sum_works_with_full_payments(self): OrderPayment.objects.create( order = self.order, amount = Decimal('10'), transaction_id = 'whatever', payment_method = 'test method' ) self.assertEqual(self.order.amount_payed, 10) self.assertEqual(self.order.is_payed(), True)
def create_fixtures(self): self.order = Order() self.order.order_subtotal = Decimal('10') self.order.order_total = Decimal('10') self.order.shipping_cost = Decimal('0') self.order.shipping_name = 'toto' self.order.shipping_address = 'address' self.order.shipping_address2 = 'address2' self.order.shipping_zip_code = 'zip' self.order.shipping_state = 'state' self.order.shipping_country = 'country' self.order.billing_name = 'toto' self.order.billing_address = 'address' self.order.billing_address2 = 'address2' self.order.billing_zip_code = 'zip' self.order.billing_state = 'state' self.order.billing_country = 'country' self.order.save()
def setUp(self): self.product = Product() self.product.name = 'test' self.product.slug = 'test' self.product.unit_price = Decimal('1.0') self.product.save() self.product2 = Product() self.product2.name = 'test2' self.product2.slug = 'test2' self.product2.unit_price = Decimal('1.0') self.product2.save() self.product3 = Product() self.product3.name = 'test3' self.product3.slug = 'test3' self.product3.unit_price = Decimal('1.0') self.product3.save() self.order = Order() self.order.order_subtotal = Decimal('10') self.order.order_total = Decimal('10') self.order.shipping_cost = Decimal('0') self.order.shipping_address_text = 'shipping address example' self.order.billing_address_text = 'billing address example' self.order.save() self.orderitem1 = OrderItem() self.orderitem1.order = self.order self.orderitem1.product = self.product self.orderitem1.quantity = 5 # this will be the most bought self.orderitem1.save() self.orderitem2 = OrderItem() self.orderitem2.order = self.order self.orderitem2.product = self.product2 self.orderitem2.quantity = 1 # this will be the second most self.orderitem2.save()
def setUp(self): self.product = Product() self.product.name = 'test' self.product.unit_price = Decimal('1.0') self.product.save() self.product2 = Product() self.product2.name = 'test2' self.product2.unit_price = Decimal('1.0') self.product2.save() self.product3 = Product() self.product3.name = 'test3' self.product3.unit_price = Decimal('1.0') self.product3.save() self.order = Order() self.order.order_subtotal = Decimal('10') self.order.order_total = Decimal('10') self.order.shipping_cost = Decimal('0') self.order.shipping_name = 'toto' self.order.shipping_address = 'address' self.order.shipping_address2 = 'address2' self.order.shipping_city = 'city' self.order.shipping_zip_code = 'zip' self.order.shipping_state = 'state' self.order.shipping_country = 'country' self.order.billing_name = 'toto' self.order.billing_address = 'address' self.order.billing_address2 = 'address2' self.order.billing_city = 'city' self.order.billing_zip_code = 'zip' self.order.billing_state = 'state' self.order.billing_country = 'country' self.order.save() self.orderitem1 = OrderItem() self.orderitem1.order = self.order self.orderitem1.product = self.product self.orderitem1.quantity = 5 # this will be the most bought self.orderitem1.save() self.orderitem2 = OrderItem() self.orderitem2.order = self.order self.orderitem2.product = self.product2 self.orderitem2.quantity = 1 # this will be the second most self.orderitem2.save()
class OrderPaymentTestCase(TestCase): def setUp(self): self.user = User.objects.create(username="******", email="*****@*****.**") self.request = Mock() setattr(self.request, 'user', None) self.order = Order() self.order.order_subtotal = Decimal('10') self.order.order_total = Decimal('10') self.order.shipping_cost = Decimal('0') self.order.shipping_address_text = 'shipping address example' self.order.billing_address_text = 'billing address example' self.order.save() def test_payment_sum_works(self): self.assertEqual(self.order.amount_payed, Decimal('-1')) def test_payment_sum_works_with_partial_payments(self): OrderPayment.objects.create(order=self.order, amount=Decimal('2'), transaction_id='whatever', payment_method='test method') self.assertEqual(self.order.amount_payed, 2) self.assertEqual(self.order.is_payed(), False) def test_payment_sum_works_with_full_payments(self): OrderPayment.objects.create(order=self.order, amount=Decimal('10'), transaction_id='whatever', payment_method='test method') self.assertEqual(self.order.amount_payed, 10) self.assertEqual(self.order.is_payed(), True)
def setUp(self): self.user = User.objects.create( username="******", email="*****@*****.**") self.request = Mock() setattr(self.request, 'user', self.user) self.order = Order() self.order.user = self.user self.order.order_subtotal = decimal.Decimal('10') self.order.order_total = decimal.Decimal('10') self.order.shipping_cost = decimal.Decimal('0') self.order.shipping_address_text = 'shipping address example' self.order.billing_address_text = 'billing address example' self.order.save() self.rendered_templates = [] template_rendered.connect(self.template_rendered_listener)
def test_address_parsing_failed(self): order = Order() order.order_subtotal = Decimal('10') order.order_total = Decimal('10') order.shipping_cost = Decimal('0') order.save() from django_shop_payer_backend.helper import AddressParsingFailedException self.assertRaises(AddressParsingFailedException, buyer_details_from_user, (AnonymousUser(), order,)) self.assertRaises(AddressParsingFailedException, buyer_details_from_user, (AnonymousUser(), None,))
def test_address_parsing_failed(self): order = Order() order.order_subtotal = Decimal('10') order.order_total = Decimal('10') order.shipping_cost = Decimal('0') order.save() from django_shop_payer_backend.helper import AddressParsingFailedException self.assertRaises(AddressParsingFailedException, buyer_details_from_user, ( AnonymousUser(), order, )) self.assertRaises(AddressParsingFailedException, buyer_details_from_user, ( AnonymousUser(), None, ))
def setUp(self): self.order = Order() self.order.order_subtotal = Decimal("10") self.order.order_total = Decimal("10") self.order.shipping_cost = Decimal("0") self.order.shipping_name = "toto" self.order.shipping_address = "address" self.order.shipping_address2 = "address2" self.order.shipping_zip_code = "zip" self.order.shipping_state = "state" self.order.shipping_country = "country" self.order.billing_name = "toto" self.order.billing_address = "address" self.order.billing_address2 = "address2" self.order.billing_zip_code = "zip" self.order.billing_state = "state" self.order.billing_country = "country" self.order.save()
class OrderUtilTestCase(TestCase): def create_fixtures(self): self.user = User.objects.create(username="******", email="*****@*****.**") self.request = Mock() setattr(self.request, 'user', None) self.order = Order() self.order.order_subtotal = Decimal('10') self.order.order_total = Decimal('10') self.order.amount_payed = Decimal('0') self.order.shipping_cost = Decimal('0') self.order.shipping_name = 'toto' self.order.shipping_address = 'address' self.order.shipping_address2 = 'address2' self.order.shipping_zip_code = 'zip' self.order.shipping_state = 'state' self.order.shipping_country = 'country' self.order.billing_name = 'toto' self.order.billing_address = 'address' self.order.billing_address2 = 'address2' self.order.billing_zip_code = 'zip' self.order.billing_state = 'state' self.order.billing_country = 'country' self.order.save() def test_01_request_without_user_or_session_returns_none(self): self.create_fixtures() ret = get_order_from_request(self.request) self.assertEqual(ret, None) def test_02_request_with_session_without_order_returns_none(self): self.create_fixtures() setattr(self.request,'session', {}) ret = get_order_from_request(self.request) self.assertEqual(ret, None) def test_03_request_with_order_returns_order(self): self.create_fixtures() session = {} session['order_id'] = self.order.id setattr(self.request, 'session', session) ret = get_order_from_request(self.request) self.assertEqual(ret, self.order) def test_04_request_with_user_returns_correct_order(self): self.create_fixtures() setattr(self.request, 'user', self.user) self.order.user = self.user self.order.save() ret = get_order_from_request(self.request) self.assertEqual(ret, self.order) def test_05_set_order_to_session_works(self): self.create_fixtures() setattr(self.request,'session', {}) add_order_to_request(self.request, self.order) self.assertEqual(self.request.session['order_id'], self.order.id) def test_06_set_order_to_user_works(self): self.create_fixtures() setattr(self.request,'user', self.user) add_order_to_request(self.request, self.order) self.assertEqual(self.order.user, self.user) def test_06_same_user_does_not_override(self): self.create_fixtures() self.order.user = self.user self.order.save() setattr(self.request,'user', self.user) add_order_to_request(self.request, self.order) self.assertEqual(self.order.user, self.user)
class GeneralShippingBackendTestCase(TestCase): def create_fixtures(self): self.user = User.objects.create(username="******", email="*****@*****.**", first_name="Test", last_name="Toto") backends_pool.USE_CACHE = False self.order = Order() self.order.order_subtotal = Decimal('10') self.order.order_total = Decimal('10') self.order.amount_payed = Decimal('0') self.order.shipping_cost = Decimal('0') self.order.shipping_name = 'toto' self.order.shipping_address = 'address' self.order.shipping_address2 = 'address2' self.order.shipping_zip_code = 'zip' self.order.shipping_state = 'state' self.order.shipping_country = 'country' self.order.billing_name = 'toto' self.order.billing_address = 'address' self.order.billing_address2 = 'address2' self.order.billing_zip_code = 'zip' self.order.billing_state = 'state' self.order.billing_country = 'country' self.order.save() def test_01_enforcing_of_name_works(self): self.create_fixtures() class MockBackend(BaseShippingBackend): pass raised = False try: MockBackend() except NotImplementedError: raised = True self.assertEqual(raised, True) def test_02_enforcing_of_namespace_works(self): self.create_fixtures() class MockBackend(BaseShippingBackend): backend_name = "Fake" raised = False try: MockBackend() except NotImplementedError: raised = True self.assertEqual(raised, True) def test_03_get_order_returns_sensible_nulls(self): self.create_fixtures() class MockBackend(BaseShippingBackend): backend_name = "Fake" url_namespace = "fake" class MockRequest(): user = self.user be = MockBackend() order = be.shop.get_order(MockRequest()) self.assertEqual(order, None) def test_04_get_backends_from_pool(self): self.create_fixtures() MODIFIERS = ['shop.tests.shipping.MockShippingBackend'] with SettingsOverride(SHOP_SHIPPING_BACKENDS=MODIFIERS): list = backends_pool.get_shipping_backends_list() self.assertEqual(len(list), 1) def test_05_get_backends_from_empty_pool(self): self.create_fixtures() MODIFIERS = [] with SettingsOverride(SHOP_SHIPPING_BACKENDS=MODIFIERS): list = backends_pool.get_shipping_backends_list() self.assertEqual(len(list), 0) def test_06_get_backends_from_non_path(self): self.create_fixtures() MODIFIERS = ['blob'] with SettingsOverride(SHOP_SHIPPING_BACKENDS=MODIFIERS): raised = False try: backends_pool.get_shipping_backends_list() except ImproperlyConfigured: raised = True self.assertEqual(raised, True) def test_07_get_backends_from_non_module(self): self.create_fixtures() MODIFIERS = ['shop.tests.IdontExist.IdontExistEither'] with SettingsOverride(SHOP_SHIPPING_BACKENDS=MODIFIERS): raised = False try: backends_pool.get_shipping_backends_list() except ImproperlyConfigured: raised = True self.assertEqual(raised, True) def test_08_get_backends_from_non_class(self): self.create_fixtures() MODIFIERS = ['shop.tests.shipping.IdontExistEither'] with SettingsOverride(SHOP_SHIPPING_BACKENDS=MODIFIERS): raised = False try: backends_pool.get_shipping_backends_list() except ImproperlyConfigured: raised = True self.assertEqual(raised, True) def test_09_get_backends_cache_works(self): self.create_fixtures() MODIFIERS = ['shop.tests.shipping.MockShippingBackend'] backends_pool.USE_CACHE = True with SettingsOverride(SHOP_SHIPPING_BACKENDS=MODIFIERS): list = backends_pool.get_shipping_backends_list() self.assertEqual(len(list), 1) list2 = backends_pool.get_shipping_backends_list() self.assertEqual(len(list2), 1) self.assertEqual(list, list2) def test_10_add_shipping_costs_works(self): self.create_fixtures() class MockBackend(BaseShippingBackend): backend_name = "Fake" url_namespace = "fake" MODIFIERS = ['shop.tests.shipping.MockShippingBackend'] backends_pool.USE_CACHE = True with SettingsOverride(SHOP_SHIPPING_BACKENDS=MODIFIERS): be = MockBackend() be.shop.add_shipping_costs(self.order, 'Test shipping', Decimal('-10')) self.assertEqual(self.order.shipping_costs, Decimal('-10'))
class AddressHelperTestCase(TestCase): def setUp(self): self.user = User.objects.create(username="******", email="*****@*****.**", first_name="Mary-Jane", last_name="Watson") self.order = Order() self.order.order_subtotal = Decimal('10') self.order.order_total = Decimal('10') self.order.shipping_cost = Decimal('0') self.address = AddressModel.objects.create( name="Mary-Jane Watson", address="Main Street 123", address2="c/o Someone", zip_code="12345", city="Anytown", state="N/A", user_shipping=self.user, user_billing=self.user, ) self.order.shipping_address_text = self.address.as_text() self.order.billing_address_text = self.address.as_text() self.order.save() def assertAddressData(self, buyer): self.assertEquals(buyer.first_name, "Mary-Jane") self.assertEquals(buyer.last_name, "Watson") self.assertEquals(buyer.address_line_1, "Main Street 123") self.assertEquals(buyer.address_line_2, "c/o Someone") self.assertEquals(buyer.postal_code, "12345") self.assertEquals(buyer.city, "Anytown") def add_additional_buyer_details(self, sender, **kwargs): buyer_details_dict = kwargs.get('buyer_details_dict', None) buyer_details_dict.update({ 'organisation': "The Company Inc.", }) def test_anonymous_user_no_signal(self): buyer = buyer_details_from_user(AnonymousUser(), self.order) self.assertAddressData(buyer) self.assertEquals(buyer.email, None) def test_anonymous_user_with_signal(self): populate_buyer_details_dict.connect(self.add_additional_buyer_details) buyer = buyer_details_from_user(AnonymousUser(), self.order) self.assertAddressData(buyer) self.assertEquals(buyer.email, None) self.assertEquals(buyer.organisation, "The Company Inc.") populate_buyer_details_dict.disconnect( self.add_additional_buyer_details) def test_anonymous_user_with_address_signal(self): # Existing callable at path with self.settings(SHOP_PAYER_BACKEND_ADDRESS_HANDLER= 'django_shop_payer_backend.tests.override_address'): buyer = buyer_details_from_user(AnonymousUser(), self.order) self.assertEquals(buyer.first_name, "Peter") self.assertEquals(buyer.last_name, "Parker") self.assertEquals(buyer.address_line_1, "Back Street 987") self.assertEquals(buyer.postal_code, "98765") self.assertEquals(buyer.city, "Somewhere") self.assertEquals(buyer.email, None) # Inexistent callable at path for invalid_path in ['invalid.path']: with self.settings( SHOP_PAYER_BACKEND_ADDRESS_HANDLER=invalid_path): self.assertRaises(ImportError, buyer_details_from_user, ( AnonymousUser(), self.order, )) from django_shop_payer_backend.helper import _import_path self.assertRaises(ValueError, _import_path, None) self.assertRaises(ValueError, _import_path, "") def test_auth_user_no_signal(self): buyer = buyer_details_from_user(self.user, self.order) self.assertAddressData(buyer) self.assertEquals(buyer.email, "*****@*****.**") def test_auth_user_with_signal(self): populate_buyer_details_dict.connect(self.add_additional_buyer_details) buyer = buyer_details_from_user(self.user, self.order) self.assertAddressData(buyer) self.assertEquals(buyer.email, "*****@*****.**") self.assertEquals(buyer.organisation, "The Company Inc.") populate_buyer_details_dict.disconnect( self.add_additional_buyer_details) def test_auth_user_without_address_no_signal(self): user = User.objects.create(username="******", email="*****@*****.**", first_name="Mary-Jane", last_name="Watson") user.save() buyer = buyer_details_from_user(user, self.order) self.assertAddressData(buyer) self.assertEquals(buyer.email, "*****@*****.**") def test_auth_user_without_address_with_signal(self): populate_buyer_details_dict.connect(self.add_additional_buyer_details) buyer = buyer_details_from_user(self.user, self.order) self.assertAddressData(buyer) self.assertEquals(buyer.email, "*****@*****.**") self.assertEquals(buyer.organisation, "The Company Inc.") populate_buyer_details_dict.disconnect( self.add_additional_buyer_details) def test_address_parsing_failed(self): order = Order() order.order_subtotal = Decimal('10') order.order_total = Decimal('10') order.shipping_cost = Decimal('0') order.save() from django_shop_payer_backend.helper import AddressParsingFailedException self.assertRaises(AddressParsingFailedException, buyer_details_from_user, ( AnonymousUser(), order, )) self.assertRaises(AddressParsingFailedException, buyer_details_from_user, ( AnonymousUser(), None, )) def test_name_parsing(self): from helper import AddressFormatParser self.assertEquals( AddressFormatParser.get_first_and_last_name("Peter Parker"), ( "Peter", "Parker", )) self.assertEquals( AddressFormatParser.get_first_and_last_name("Mary Jane Watson"), ( "Mary", "Jane Watson", )) self.assertEquals( AddressFormatParser.get_first_and_last_name("Mary-Kate Olsen"), ( "Mary-Kate", "Olsen", )) self.assertEquals( AddressFormatParser.get_first_and_last_name( u"Gabriel García Márquez"), ( u"Gabriel", u"García Márquez", )) self.assertEquals( AddressFormatParser.get_first_and_last_name( u"Gabriel José de la Concordia García Márquez"), ( u"Gabriel José De", u"La Concordia García Márquez", )) self.assertEquals( AddressFormatParser.get_first_and_last_name( "Kirsten Moore-Towers"), ( "Kirsten", "Moore-Towers", )) self.assertEquals( AddressFormatParser.get_first_and_last_name( "Ralph Vaughan Williams"), ( "Ralph", "Vaughan Williams", )) self.assertEquals( AddressFormatParser.get_first_and_last_name("Spiderman"), ( "Spiderman", "", )) self.assertEquals( AddressFormatParser.get_first_and_last_name("P. Sherman"), ( "P.", "Sherman", )) self.assertEquals( AddressFormatParser.get_first_and_last_name("p.sherman"), ( "P", "Sherman", )) self.assertEquals(AddressFormatParser.get_first_and_last_name(None), ( "", "", )) def test_address_parsing(self): from shop.addressmodel.models import ADDRESS_TEMPLATE from helper import AddressFormatParser CUSTOM_ADDRESS_TEMPLATE = """Name: %(name)s, Address: %(address)s, City: %(city)s %(zipcode)s, State: %(state)s""" def test_template(template): def filter_address_vars(address_vars, template): expected_keys = AddressFormatParser( "", template)._get_format_vars(template) address_vars = dict((k, v) for k, v in address_vars.iteritems() if k in expected_keys) return address_vars # All vars address_vars = { 'name': u"P. Sherman", 'address': u"42 Wallaby Way", 'zipcode': u"2123", 'city': u"Sydney", 'state': u"NSW", 'country': u"Australia", } address_vars = filter_address_vars(address_vars, template) address = template % address_vars parser = AddressFormatParser(address, template) self.assertEquals(parser.get_address_vars(), address_vars) # Payer vars payer_vars = { 'first_name': u'P.', 'last_name': u'Sherman', 'address_line_1': u'42 Wallaby Way', 'postal_code': u'2123', 'city': u'Sydney', 'state': u'NSW', 'country': 'Australia', } self.assertEquals( filter_address_vars(parser.get_payer_vars(), template), filter_address_vars(payer_vars, template)) # Missing vars address_vars = { 'name': u"P. Sherman", 'address': u"42 Wallaby Way", 'zipcode': u"2123", 'city': u"Sydney", 'state': u"", 'country': u"", } address_vars = filter_address_vars(address_vars, template) address = template % address_vars parser = AddressFormatParser(address, template) actual_vars = dict( (k, v) for k, v in parser.get_address_vars().iteritems() if v) expected_vars = dict( (k, v) for k, v in address_vars.iteritems() if v) self.assertEquals(expected_vars, actual_vars) test_template(ADDRESS_TEMPLATE) test_template(CUSTOM_ADDRESS_TEMPLATE) # Address string None value parser = AddressFormatParser(None, ADDRESS_TEMPLATE) self.assertEqual(parser.get_address_vars(), {})
def setUp(self): self.user = User.objects.create(username="******", email="*****@*****.**", first_name="Test", last_name="User") self.shop = PaymentAPI() self.backend = GenericPayerBackend(shop=self.shop) class Mock(object): pass self.request = Mock() setattr(self.request, 'user', self.user) self.user.save() self.country = Country.objects.create(name='CH') self.address = AddressModel() self.address.client = self.client self.address.address = 'address' self.address.address2 = 'address2' self.address.zip_code = '1234' self.address.state = 'ZH' self.address.country = self.country self.address.is_billing = False self.address.is_shipping = True self.address.save() self.address2 = AddressModel() self.address2.client = self.client self.address2.address = '2address' self.address2.address2 = '2address2' self.address2.zip_code = '21234' self.address2.state = '2ZH' self.address2.country = self.country self.address2.is_billing = True self.address2.is_shipping = False self.address2.save() # The order fixture self.order = Order() self.order.user = self.user self.order.order_subtotal = Decimal('100') # One item worth 100 self.order.order_total = Decimal('120') # plus a test field worth 10 self.order.status = Order.PROCESSING ship_address = self.address bill_address = self.address2 self.order.set_shipping_address(ship_address) self.order.set_billing_address(bill_address) self.order.save() # Orderitems self.orderitem = OrderItem() self.orderitem.order = self.order self.orderitem.product_name = 'Test item' self.orderitem.unit_price = Decimal("100") self.orderitem.quantity = 1 self.orderitem.line_subtotal = Decimal('100') self.orderitem.line_total = Decimal('110') self.orderitem.save() oi = OrderExtraInfo() oi.order = self.order oi.text = "buffalo " * 64 oi.save() eoif = ExtraOrderItemPriceField() eoif.order_item = self.orderitem eoif.label = 'Fake extra field' eoif.value = Decimal("10") eoif.save() eof = ExtraOrderPriceField() eof.order = self.order eof.label = "Fake Taxes" eof.value = Decimal("10") eof.save()
class GeneralShippingBackendTestCase(TestCase): def setUp(self): self.user = User.objects.create(username="******", email="*****@*****.**", first_name="Test", last_name = "Toto") backends_pool.use_cache = False self.order = Order() self.order.order_subtotal = Decimal('10') self.order.order_total = Decimal('10') self.order.shipping_cost = Decimal('0') self.order.shipping_name = 'toto' self.order.shipping_address = 'address' self.order.shipping_address2 = 'address2' self.order.shipping_zip_code = 'zip' self.order.shipping_state = 'state' self.order.shipping_country = 'country' self.order.billing_name = 'toto' self.order.billing_address = 'address' self.order.billing_address2 = 'address2' self.order.billing_zip_code = 'zip' self.order.billing_state = 'state' self.order.billing_country = 'country' self.order.save() def test_enforcing_of_name_works(self): MODIFIERS = ['shop.tests.shipping.MockShippingBackend'] with SettingsOverride(SHOP_SHIPPING_BACKENDS=MODIFIERS): self.assertRaises(NotImplementedError, backends_pool.get_shipping_backends_list) def test_enforcing_of_namespace_works(self): MODIFIERS = ['shop.tests.shipping.NamedMockShippingBackend'] with SettingsOverride(SHOP_SHIPPING_BACKENDS=MODIFIERS): self.assertRaises(NotImplementedError, backends_pool.get_shipping_backends_list) def test_get_order_returns_sensible_nulls(self): class MockRequest(): user = self.user be = ValidMockShippingBackend(shop=ShippingAPI()) order = be.shop.get_order(MockRequest()) self.assertEqual(order, None) def test_get_backends_from_pool(self): MODIFIERS = ['shop.tests.shipping.ValidMockShippingBackend'] with SettingsOverride(SHOP_SHIPPING_BACKENDS=MODIFIERS): list = backends_pool.get_shipping_backends_list() self.assertEqual(len(list), 1) def test_get_backends_from_empty_pool(self): MODIFIERS = [] with SettingsOverride(SHOP_SHIPPING_BACKENDS=MODIFIERS): list = backends_pool.get_shipping_backends_list() self.assertEqual(len(list), 0) def test_get_backends_from_non_path(self): MODIFIERS = ['blob'] with SettingsOverride(SHOP_SHIPPING_BACKENDS=MODIFIERS): self.assertRaises(ImproperlyConfigured, backends_pool.get_shipping_backends_list) def test_get_backends_from_non_module(self): MODIFIERS = ['shop.tests.IdontExist.IdontExistEither'] with SettingsOverride(SHOP_SHIPPING_BACKENDS=MODIFIERS): self.assertRaises(ImproperlyConfigured, backends_pool.get_shipping_backends_list) def test_get_backends_from_non_class(self): MODIFIERS = ['shop.tests.shipping.IdontExistEither'] with SettingsOverride(SHOP_SHIPPING_BACKENDS=MODIFIERS): self.assertRaises(ImproperlyConfigured, backends_pool.get_shipping_backends_list) def test_get_backends_cache_works(self): MODIFIERS = ['shop.tests.shipping.ValidMockShippingBackend'] backends_pool.use_cache = True with SettingsOverride(SHOP_SHIPPING_BACKENDS=MODIFIERS): list = backends_pool.get_shipping_backends_list() self.assertEqual(len(list), 1) list2 = backends_pool.get_shipping_backends_list() self.assertEqual(len(list2), 1) self.assertEqual(list,list2)
def setUp(self): self.user = User.objects.create(username="******", email="*****@*****.**", first_name="Test", last_name="Toto") self.user.save() self.country = Country.objects.create(name='CH') self.address = Address() self.address.client = self.client self.address.address = 'address' self.address.address2 = 'address2' self.address.zip_code = '1234' self.address.state = 'ZH' self.address.country = self.country self.address.is_billing = False self.address.is_shipping = True self.address.save() self.address2 = Address() self.address2.client = self.client self.address2.address = '2address' self.address2.address2 = '2address2' self.address2.zip_code = '21234' self.address2.state = '2ZH' self.address2.country = self.country self.address2.is_billing = True self.address2.is_shipping = False self.address2.save() # The order fixture self.order = Order() self.order.user = self.user self.order.order_subtotal = Decimal('100') # One item worth 100 self.order.order_total = Decimal('120') # plus a test field worth 10 self.order.status = Order.PROCESSING ship_address = self.address bill_address = self.address2 self.order.set_shipping_address(ship_address) self.order.set_billing_address(bill_address) self.order.save() # Orderitems self.orderitem = OrderItem() self.orderitem.order = self.order self.orderitem.product_name = 'Test item' self.orderitem.unit_price = Decimal("100") self.orderitem.quantity = 1 self.orderitem.line_subtotal = Decimal('100') self.orderitem.line_total = Decimal('110') self.orderitem.save() eoif = ExtraOrderItemPriceField() eoif.order_item = self.orderitem eoif.label = 'Fake extra field' eoif.value = Decimal("10") eoif.save() eof = ExtraOrderPriceField() eof.order = self.order eof.label = "Fake Taxes" eof.value = Decimal("10") eof.save()
class PayOnDeliveryTestCase(TestCase): def setUp(self): self.user = User.objects.create(username="******", email="*****@*****.**", first_name="Test", last_name="Toto") self.user.save() self.country = Country.objects.create(name='CH') self.address = Address() self.address.client = self.client self.address.address = 'address' self.address.address2 = 'address2' self.address.zip_code = '1234' self.address.state = 'ZH' self.address.country = self.country self.address.is_billing = False self.address.is_shipping = True self.address.save() self.address2 = Address() self.address2.client = self.client self.address2.address = '2address' self.address2.address2 = '2address2' self.address2.zip_code = '21234' self.address2.state = '2ZH' self.address2.country = self.country self.address2.is_billing = True self.address2.is_shipping = False self.address2.save() # The order fixture self.order = Order() self.order.user = self.user self.order.order_subtotal = Decimal('100') # One item worth 100 self.order.order_total = Decimal('120') # plus a test field worth 10 self.order.status = Order.PROCESSING ship_address = self.address bill_address = self.address2 self.order.set_shipping_address(ship_address) self.order.set_billing_address(bill_address) self.order.save() # Orderitems self.orderitem = OrderItem() self.orderitem.order = self.order self.orderitem.product_name = 'Test item' self.orderitem.unit_price = Decimal("100") self.orderitem.quantity = 1 self.orderitem.line_subtotal = Decimal('100') self.orderitem.line_total = Decimal('110') self.orderitem.save() eoif = ExtraOrderItemPriceField() eoif.order_item = self.orderitem eoif.label = 'Fake extra field' eoif.value = Decimal("10") eoif.save() eof = ExtraOrderPriceField() eof.order = self.order eof.label = "Fake Taxes" eof.value = Decimal("10") eof.save() def test01_backend_returns_urls(self): be = PayOnDeliveryBackend(shop=PaymentAPI()) urls = be.get_urls() self.assertNotEqual(urls, None) self.assertEqual(len(urls), 1) def test02_must_be_logged_in_if_setting_is_true(self): with SettingsOverride(SHOP_FORCE_LOGIN=True): resp = self.client.get(reverse('pay-on-delivery')) self.assertEqual(resp.status_code, 302) self.assertTrue('accounts/login/' in resp._headers['location'][1]) def test_order_required_before_payment(self): """ See issue #84 """ # Session only (no order) response = self.client.get(reverse('pay-on-delivery')) self.assertEqual(302, response.status_code) self.assertEqual('http://testserver/', response._headers['location'][1]) # User logged in (no order) username = '******' pw = 'pass' User.objects.create_user(username=username, password=pw, email='*****@*****.**') logged_in = self.client.login(username=username, password=pw) self.assertTrue(logged_in) response = self.client.get(reverse('pay-on-delivery')) self.assertEqual(302, response.status_code) self.assertEqual('http://testserver/', response._headers['location'][1]) self.client.logout() # User logged in and has order self.user.set_password('blah') self.user.save() logged_in = self.client.login(username=self.user.username, password='******') self.assertTrue(logged_in) response = self.client.get(reverse('pay-on-delivery')) self.assertTrue( reverse('thank_you_for_your_order') in response._headers['location'][1])
class PayOnDeliveryTestCase(TestCase): def setUp(self): self.user = User.objects.create(username="******", email="*****@*****.**", first_name="Test", last_name = "Toto") self.user.save() self.country = Country.objects.create(name='CH') self.address = Address() self.address.client = self.client self.address.address = 'address' self.address.address2 = 'address2' self.address.zip_code = '1234' self.address.state = 'ZH' self.address.country = self.country self.address.is_billing = False self.address.is_shipping = True self.address.save() self.address2 = Address() self.address2.client = self.client self.address2.address = '2address' self.address2.address2 = '2address2' self.address2.zip_code = '21234' self.address2.state = '2ZH' self.address2.country = self.country self.address2.is_billing = True self.address2.is_shipping = False self.address2.save() # The order fixture self.order = Order() self.order.user = self.user self.order.order_subtotal = Decimal('100') # One item worth 100 self.order.order_total = Decimal('120') # plus a test field worth 10 self.order.status = Order.PROCESSING ship_address = self.address bill_address = self.address2 self.order.shipping_name = "%s %s" %(self.user.first_name, self.user.last_name) self.order.shipping_address = ship_address.address self.order.shipping_address2 = ship_address.address2 self.order.shipping_zip_code = ship_address.zip_code self.order.shipping_state = ship_address.state self.order.shipping_country = ship_address.country.name self.order.shipping_name = "%s %s" %(self.user.first_name, self.user.last_name) self.order.billing_address = bill_address.address self.order.billing_address2 = bill_address.address2 self.order.billing_zip_code = bill_address.zip_code self.order.billing_state = bill_address.state self.order.billing_country = bill_address.country.name self.order.save() # Orderitems self.orderitem = OrderItem() self.orderitem.order = self.order self.orderitem.product_reference = 'fakeref' self.orderitem.product_name = 'Test item' self.orderitem.unit_price = Decimal("100") self.orderitem.quantity = 1 self.orderitem.line_subtotal = Decimal('100') self.orderitem.line_total = Decimal('110') self.orderitem.save() eoif = ExtraOrderItemPriceField() eoif.order_item = self.orderitem eoif.label = 'Fake extra field' eoif.value = Decimal("10") eoif.save() eof = ExtraOrderPriceField() eof.order = self.order eof.label = "Fake Taxes" eof.value = Decimal("10") eof.save() def test_backend_returns_urls(self): be = PayOnDeliveryBackend(shop=PaymentAPI()) urls = be.get_urls() self.assertNotEqual(urls,None) self.assertEqual(len(urls), 1)
class GeneralShippingBackendTestCase(TestCase): def setUp(self): self.user = User.objects.create(username='******', email='*****@*****.**', first_name='Test', last_name='Toto') backends_pool.use_cache = False self.order = Order() self.order.order_subtotal = Decimal('10') self.order.order_total = Decimal('10') self.order.shipping_cost = Decimal('0') self.order.shipping_address_text = 'shipping address example' self.order.billing_address_text = 'billing address example' self.order.save() def test_enforcing_of_name_works(self): MODIFIERS = ['shop.tests.shipping.MockShippingBackend'] with SettingsOverride(SHOP_SHIPPING_BACKENDS=MODIFIERS): self.assertRaises(NotImplementedError, backends_pool.get_shipping_backends_list) def test_enforcing_of_namespace_works(self): MODIFIERS = ['shop.tests.shipping.NamedMockShippingBackend'] with SettingsOverride(SHOP_SHIPPING_BACKENDS=MODIFIERS): self.assertRaises(NotImplementedError, backends_pool.get_shipping_backends_list) def test_get_order_returns_sensible_nulls(self): class MockRequest(): user = self.user be = ValidMockShippingBackend(shop=ShippingAPI()) order = be.shop.get_order(MockRequest()) self.assertEqual(order, None) def test_get_backends_from_pool(self): MODIFIERS = ['shop.tests.shipping.ValidMockShippingBackend'] with SettingsOverride(SHOP_SHIPPING_BACKENDS=MODIFIERS): list_ = backends_pool.get_shipping_backends_list() self.assertEqual(len(list_), 1) def test_get_backends_from_empty_pool(self): MODIFIERS = [] with SettingsOverride(SHOP_SHIPPING_BACKENDS=MODIFIERS): list_ = backends_pool.get_shipping_backends_list() self.assertEqual(len(list_), 0) def test_get_backends_from_non_path(self): MODIFIERS = ['blob'] with SettingsOverride(SHOP_SHIPPING_BACKENDS=MODIFIERS): self.assertRaises(ImproperlyConfigured, backends_pool.get_shipping_backends_list) def test_get_backends_from_non_module(self): MODIFIERS = ['shop.tests.IdontExist.IdontExistEither'] with SettingsOverride(SHOP_SHIPPING_BACKENDS=MODIFIERS): self.assertRaises(ImproperlyConfigured, backends_pool.get_shipping_backends_list) def test_get_backends_from_non_class(self): MODIFIERS = ['shop.tests.shipping.IdontExistEither'] with SettingsOverride(SHOP_SHIPPING_BACKENDS=MODIFIERS): self.assertRaises(ImproperlyConfigured, backends_pool.get_shipping_backends_list) def test_get_backends_cache_works(self): MODIFIERS = ['shop.tests.shipping.ValidMockShippingBackend'] backends_pool.use_cache = True with SettingsOverride(SHOP_SHIPPING_BACKENDS=MODIFIERS): list_ = backends_pool.get_shipping_backends_list() self.assertEqual(len(list_), 1) list2 = backends_pool.get_shipping_backends_list() self.assertEqual(len(list2), 1) self.assertEqual(list_, list2)
def create_fixtures(self): self.user = User.objects.create(username="******", email="*****@*****.**", first_name="Test", last_name = "Toto") self.user.save() self.client = Client() self.client.user = self.user self.client.save() self.country = Country.objects.create(name='CH') self.address = Address() self.address.client = self.client self.address.address = 'address' self.address.address2 = 'address2' self.address.zip_code = '1234' self.address.state = 'ZH' self.address.country = self.country self.address.is_billing = False self.address.is_shipping = True self.address.save() self.address2 = Address() self.address2.client = self.client self.address2.address = '2address' self.address2.address2 = '2address2' self.address2.zip_code = '21234' self.address2.state = '2ZH' self.address2.country = self.country self.address2.is_billing = True self.address2.is_shipping = False self.address2.save() # The order fixture self.order = Order() self.order.user = self.user self.order.order_subtotal = Decimal('100') # One item worth 100 self.order.order_total = Decimal('120') # plus a test field worth 10 self.order.status = Order.PROCESSING ship_address = self.address bill_address = self.address2 self.order.shipping_name = "%s %s" %(self.address.client.user.first_name, self.address.client.user.last_name) self.order.shipping_address = ship_address.address self.order.shipping_address2 = ship_address.address2 self.order.shipping_zip_code = ship_address.zip_code self.order.shipping_state = ship_address.state self.order.shipping_country = ship_address.country.name self.order.shipping_name = "%s %s" %(self.address.client.user.first_name, self.address.client.user.last_name) self.order.billing_address = bill_address.address self.order.billing_address2 = bill_address.address2 self.order.billing_zip_code = bill_address.zip_code self.order.billing_state = bill_address.state self.order.billing_country = bill_address.country.name self.order.save() # Orderitems self.orderitem = OrderItem() self.orderitem.order = self.order self.orderitem.product_reference = 'fakeref' self.orderitem.product_name = 'Test item' self.orderitem.unit_price = Decimal("100") self.orderitem.quantity = 1 self.orderitem.line_subtotal = Decimal('100') self.orderitem.line_total = Decimal('110') self.orderitem.save() eoif = ExtraOrderItemPriceField() eoif.order_item = self.orderitem eoif.label = 'Fake extra field' eoif.value = Decimal("10") eoif.save() eof = ExtraOrderPriceField() eof.order = self.order eof.label = "Fake Taxes" eof.value = Decimal("10") eof.save()
class PayOnDeliveryTestCase(TestCase): def create_fixtures(self): self.user = User.objects.create(username="******", email="*****@*****.**", first_name="Test", last_name="Toto") self.user.save() self.client = Client() self.client.user = self.user self.client.save() self.country = Country.objects.create(name='CH') self.address = Address() self.address.client = self.client self.address.address = 'address' self.address.address2 = 'address2' self.address.zip_code = '1234' self.address.state = 'ZH' self.address.country = self.country self.address.is_billing = False self.address.is_shipping = True self.address.save() self.address2 = Address() self.address2.client = self.client self.address2.address = '2address' self.address2.address2 = '2address2' self.address2.zip_code = '21234' self.address2.state = '2ZH' self.address2.country = self.country self.address2.is_billing = True self.address2.is_shipping = False self.address2.save() # The order fixture self.order = Order() self.order.user = self.user self.order.order_subtotal = Decimal('100') # One item worth 100 self.order.order_total = Decimal('120') # plus a test field worth 10 self.order.status = Order.PROCESSING ship_address = self.address bill_address = self.address2 self.order.shipping_name = "%s %s" % ( self.address.client.user.first_name, self.address.client.user.last_name) self.order.shipping_address = ship_address.address self.order.shipping_address2 = ship_address.address2 self.order.shipping_zip_code = ship_address.zip_code self.order.shipping_state = ship_address.state self.order.shipping_country = ship_address.country.name self.order.shipping_name = "%s %s" % ( self.address.client.user.first_name, self.address.client.user.last_name) self.order.billing_address = bill_address.address self.order.billing_address2 = bill_address.address2 self.order.billing_zip_code = bill_address.zip_code self.order.billing_state = bill_address.state self.order.billing_country = bill_address.country.name self.order.save() # Orderitems self.orderitem = OrderItem() self.orderitem.order = self.order self.orderitem.product_reference = 'fakeref' self.orderitem.product_name = 'Test item' self.orderitem.unit_price = Decimal("100") self.orderitem.quantity = 1 self.orderitem.line_subtotal = Decimal('100') self.orderitem.line_total = Decimal('110') self.orderitem.save() eoif = ExtraOrderItemPriceField() eoif.order_item = self.orderitem eoif.label = 'Fake extra field' eoif.value = Decimal("10") eoif.save() eof = ExtraOrderPriceField() eof.order = self.order eof.label = "Fake Taxes" eof.value = Decimal("10") eof.save() def test_01_backend_returns_urls(self): self.create_fixtures() be = PayOnDeliveryBackend(shop=PaymentAPI()) urls = be.get_urls() self.assertNotEqual(urls, None) self.assertEqual(len(urls), 1)
class OrderUtilTestCase(TestCase): def setUp(self): self.user = User.objects.create(username="******", email="*****@*****.**") self.request = Mock() setattr(self.request, 'user', None) self.order = Order() self.order.order_subtotal = Decimal('10') self.order.order_total = Decimal('10') self.order.shipping_cost = Decimal('0') self.order.shipping_address_text = 'shipping address example' self.order.billing_address_text = 'billing address example' self.order.save() def test_request_without_user_or_session_returns_none(self): ret = get_order_from_request(self.request) self.assertEqual(ret, None) def test_request_with_session_without_order_returns_none(self): setattr(self.request, 'session', {}) ret = get_order_from_request(self.request) self.assertEqual(ret, None) def test_request_with_order_returns_order(self): session = {} session['order_id'] = self.order.pk setattr(self.request, 'session', session) ret = get_order_from_request(self.request) self.assertEqual(ret, self.order) def test_request_with_user_returns_correct_order(self): setattr(self.request, 'user', self.user) self.order.user = self.user self.order.save() ret = get_order_from_request(self.request) self.assertEqual(ret, self.order) def test_set_order_to_session_works(self): setattr(self.request, 'session', {}) add_order_to_request(self.request, self.order) self.assertEqual(self.request.session['order_id'], self.order.pk) def test_set_order_to_user_works(self): setattr(self.request, 'user', self.user) add_order_to_request(self.request, self.order) self.assertEqual(self.order.user, self.user) def test_same_user_does_not_override(self): self.order.user = self.user self.order.save() setattr(self.request, 'user', self.user) add_order_to_request(self.request, self.order) self.assertEqual(self.order.user, self.user) def test_request_with_user_returns_last_order(self): setattr(self.request, 'user', self.user) order1 = Order.objects.create(user=self.user) ret = get_order_from_request(self.request) self.assertEqual(ret, order1) order2 = Order.objects.create(user=self.user) ret = get_order_from_request(self.request) self.assertEqual(ret, order2) def test_addresses_are_conserved_properly(self): session = {} session['order_id'] = self.order.pk setattr(self.request, 'session', session) ret = get_order_from_request(self.request) self.assertEqual(ret, self.order) self.assertEqual(ret.shipping_address_text, self.order.shipping_address_text) self.assertEqual(ret.billing_address_text, self.order.billing_address_text)
class GeneralShippingBackendTestCase(TestCase): def create_fixtures(self): self.user = User.objects.create(username="******", email="*****@*****.**", first_name="Test", last_name="Toto") backends_pool.use_cache = False self.order = Order() self.order.order_subtotal = Decimal('10') self.order.order_total = Decimal('10') self.order.shipping_cost = Decimal('0') self.order.shipping_name = 'toto' self.order.shipping_address = 'address' self.order.shipping_address2 = 'address2' self.order.shipping_zip_code = 'zip' self.order.shipping_state = 'state' self.order.shipping_country = 'country' self.order.billing_name = 'toto' self.order.billing_address = 'address' self.order.billing_address2 = 'address2' self.order.billing_zip_code = 'zip' self.order.billing_state = 'state' self.order.billing_country = 'country' self.order.save() def test_01_enforcing_of_name_works(self): self.create_fixtures() MODIFIERS = ['shop.tests.shipping.MockShippingBackend'] with SettingsOverride(SHOP_SHIPPING_BACKENDS=MODIFIERS): self.assertRaises(NotImplementedError, backends_pool.get_shipping_backends_list) def test_02_enforcing_of_namespace_works(self): self.create_fixtures() MODIFIERS = ['shop.tests.shipping.NamedMockShippingBackend'] with SettingsOverride(SHOP_SHIPPING_BACKENDS=MODIFIERS): self.assertRaises(NotImplementedError, backends_pool.get_shipping_backends_list) def test_03_get_order_returns_sensible_nulls(self): self.create_fixtures() class MockRequest(): user = self.user be = ValidMockShippingBackend(shop=ShippingAPI()) order = be.shop.get_order(MockRequest()) self.assertEqual(order, None) def test_04_get_backends_from_pool(self): self.create_fixtures() MODIFIERS = ['shop.tests.shipping.ValidMockShippingBackend'] with SettingsOverride(SHOP_SHIPPING_BACKENDS=MODIFIERS): list = backends_pool.get_shipping_backends_list() self.assertEqual(len(list), 1) def test_05_get_backends_from_empty_pool(self): self.create_fixtures() MODIFIERS = [] with SettingsOverride(SHOP_SHIPPING_BACKENDS=MODIFIERS): list = backends_pool.get_shipping_backends_list() self.assertEqual(len(list), 0) def test_06_get_backends_from_non_path(self): self.create_fixtures() MODIFIERS = ['blob'] with SettingsOverride(SHOP_SHIPPING_BACKENDS=MODIFIERS): self.assertRaises(ImproperlyConfigured, backends_pool.get_shipping_backends_list) def test_07_get_backends_from_non_module(self): self.create_fixtures() MODIFIERS = ['shop.tests.IdontExist.IdontExistEither'] with SettingsOverride(SHOP_SHIPPING_BACKENDS=MODIFIERS): self.assertRaises(ImproperlyConfigured, backends_pool.get_shipping_backends_list) def test_08_get_backends_from_non_class(self): self.create_fixtures() MODIFIERS = ['shop.tests.shipping.IdontExistEither'] with SettingsOverride(SHOP_SHIPPING_BACKENDS=MODIFIERS): self.assertRaises(ImproperlyConfigured, backends_pool.get_shipping_backends_list) def test_09_get_backends_cache_works(self): self.create_fixtures() MODIFIERS = ['shop.tests.shipping.ValidMockShippingBackend'] backends_pool.use_cache = True with SettingsOverride(SHOP_SHIPPING_BACKENDS=MODIFIERS): list = backends_pool.get_shipping_backends_list() self.assertEqual(len(list), 1) list2 = backends_pool.get_shipping_backends_list() self.assertEqual(len(list2), 1) self.assertEqual(list, list2)
class ShopApiTestCase(TestCase): def setUp(self): self.user = User.objects.create(username="******", email="*****@*****.**") self.request = Mock() setattr(self.request, 'user', None) self.order = Order() self.order.order_subtotal = Decimal('10.95') self.order.order_total = Decimal('10.95') self.order.shipping_cost = Decimal('0') self.order.shipping_address_text = 'shipping address example' self.order.billing_address_text = 'billing address example' self.order.save() def test_add_extra_info(self): api = ShopAPI() api.add_extra_info(self.order, 'test') # Assert that an ExtraOrderInfo item was created oei = OrderExtraInfo.objects.get(order=self.order) self.assertEqual(oei.text, 'test') def test_is_order_paid(self): api = ShopAPI() # Ensure deprecated method still works res = api.is_order_payed(self.order) self.assertEqual(res, False) res = api.is_order_paid(self.order) self.assertEqual(res, False) def test_is_order_complete(self): api = ShopAPI() res = api.is_order_completed(self.order) self.assertEqual(res, False) def test_get_order_total(self): api = ShopAPI() res = api.get_order_total(self.order) self.assertEqual(res, Decimal('10.95')) def test_get_order_subtotal(self): api = ShopAPI() res = api.get_order_subtotal(self.order) self.assertEqual(res, Decimal('10.95')) def test_get_order_short_name(self): api = ShopAPI() res = api.get_order_short_name(self.order) self.assertEqual(res, '1-10.95') def test_get_order_unique_id(self): api = ShopAPI() res = api.get_order_unique_id(self.order) self.assertEqual(res, 1) def test_get_order_for_id(self): api = ShopAPI() res = api.get_order_for_id(1) self.assertEqual(res, self.order)
class PayOnDeliveryTestCase(TestCase): def setUp(self): self.user = User.objects.create(username="******", email="*****@*****.**", first_name="Test", last_name="Toto") self.user.save() self.country = Country.objects.create(name='CH') self.address = Address() self.address.client = self.client self.address.address = 'address' self.address.address2 = 'address2' self.address.zip_code = '1234' self.address.state = 'ZH' self.address.country = self.country self.address.is_billing = False self.address.is_shipping = True self.address.save() self.address2 = Address() self.address2.client = self.client self.address2.address = '2address' self.address2.address2 = '2address2' self.address2.zip_code = '21234' self.address2.state = '2ZH' self.address2.country = self.country self.address2.is_billing = True self.address2.is_shipping = False self.address2.save() # The order fixture self.order = Order() self.order.user = self.user self.order.order_subtotal = Decimal('100') # One item worth 100 self.order.order_total = Decimal('120') # plus a test field worth 10 self.order.status = Order.PROCESSING ship_address = self.address bill_address = self.address2 self.order.set_shipping_address(ship_address) self.order.set_billing_address(bill_address) self.order.save() # Orderitems self.orderitem = OrderItem() self.orderitem.order = self.order self.orderitem.product_name = 'Test item' self.orderitem.unit_price = Decimal("100") self.orderitem.quantity = 1 self.orderitem.line_subtotal = Decimal('100') self.orderitem.line_total = Decimal('110') self.orderitem.save() eoif = ExtraOrderItemPriceField() eoif.order_item = self.orderitem eoif.label = 'Fake extra field' eoif.value = Decimal("10") eoif.save() eof = ExtraOrderPriceField() eof.order = self.order eof.label = "Fake Taxes" eof.value = Decimal("10") eof.save() def test01_backend_returns_urls(self): be = PayOnDeliveryBackend(shop=PaymentAPI()) urls = be.get_urls() self.assertNotEqual(urls, None) self.assertEqual(len(urls), 1) def test02_must_be_logged_in_if_setting_is_true(self): with SettingsOverride(SHOP_FORCE_LOGIN=True): resp = self.client.get(reverse('shop:pay-on-delivery')) self.assertEqual(resp.status_code, 302) self.assertTrue('accounts/login/' in resp._headers['location'][1]) def test_order_required_before_payment(self): """ See issue #84 """ # Session only (no order) response = self.client.get(reverse('shop:pay-on-delivery')) self.assertEqual(302, response.status_code) self.assertEqual('http://testserver/shop/cart/', response._headers['location'][1]) # User logged in (no order) username = '******' pw = 'pass' User.objects.create_user(username=username, password=pw, email='*****@*****.**') logged_in = self.client.login(username=username, password=pw) self.assertTrue(logged_in) response = self.client.get(reverse('shop:pay-on-delivery')) self.assertEqual(302, response.status_code) self.assertEqual('http://testserver/shop/cart/', response._headers['location'][1]) self.client.logout() # User logged in and has order self.user.set_password('blah') self.user.save() logged_in = self.client.login(username=self.user.username, password='******') self.assertTrue(logged_in) response = self.client.get(reverse('shop:pay-on-delivery')) self.assertTrue(reverse('shop:thank_you_for_your_order') in response._headers['location'][1])