def make_call(x_type, amount=None): GROUP = 'PAYMENT_AUTHORIZENET' TRANKEY = config_get(GROUP, 'TRANKEY').value LOGIN = config_get(GROUP, 'LOGIN').value WE_ARE_LIVE = config_get(GROUP, 'LIVE').value TEST_URL = config_get(GROUP, 'CONNECTION_TEST').value LIVE_URL = config_get(GROUP, 'CONNECTION').value THE_URL = LIVE_URL if WE_ARE_LIVE else TEST_URL payment = cd['payment'] cc = payment.credit_card data = { 'x_card_num': cc.display_cc, 'x_trans_id': payment.transaction_id, 'x_login': LOGIN, 'x_tran_key': TRANKEY, 'x_delim_data': 'TRUE', 'x_delim_char': '|', 'x_type': x_type } if amount: data['x_amount'] = amount req = urllib2.Request(url=THE_URL, data=urlencode(data)) f = urllib2.urlopen(req) response = f.read() response_code = int(response.split('|')[0]) success = response_code == 1 return (success, response)
def testPercent(self): """Test percent tax without shipping""" cache_delete() tax = config_get('TAX','MODULE') tax.update('tax.modules.percent') pcnt = config_get('TAX', 'PERCENT') pcnt.update('10') shp = config_get('TAX', 'TAX_SHIPPING') shp.update(False) order = make_test_order('US', 'TX') order.recalculate_total(save=False) price = order.total subtotal = order.sub_total tax = order.tax self.assertEqual(subtotal, Decimal('100.00')) self.assertEqual(tax, Decimal('10.00')) # 100 + 10 shipping + 10 tax self.assertEqual(price, Decimal('120.00')) taxes = order.taxes.all() self.assertEqual(1, len(taxes)) self.assertEqual(taxes[0].tax, Decimal('10.00')) self.assertEqual(taxes[0].description, r'10%')
def test_checkout(self): """ Run through a full checkout process """ cache_delete() tax = config_get('TAX','MODULE') tax.update('tax.modules.percent') pcnt = config_get('TAX', 'PERCENT') pcnt.update('10') shp = config_get('TAX', 'TAX_SHIPPING') shp.update(False) self.test_cart_adding() response = self.client.post(url('satchmo_checkout-step1'), get_step1_post_data(self.US)) self.assertRedirects(response, url('DUMMY_satchmo_checkout-step2'), status_code=302, target_status_code=200) data = { 'credit_type': 'Visa', 'credit_number': '4485079141095836', 'month_expires': '1', 'year_expires': '2015', 'ccv': '552', 'shipping': 'FlatRate'} response = self.client.post(url('DUMMY_satchmo_checkout-step2'), data) self.assertRedirects(response, url('DUMMY_satchmo_checkout-step3'), status_code=302, target_status_code=200) response = self.client.get(url('DUMMY_satchmo_checkout-step3')) amount = smart_str('Shipping + ' + moneyfmt(Decimal('4.00'))) self.assertContains(response, amount, count=1, status_code=200) amount = smart_str('Tax + ' + moneyfmt(Decimal('4.60'))) self.assertContains(response, amount, count=1, status_code=200) amount = smart_str('Total = ' + moneyfmt(Decimal('54.60'))) self.assertContains(response, amount, count=1, status_code=200) response = self.client.post(url('DUMMY_satchmo_checkout-step3'), {'process' : 'True'}) self.assertRedirects(response, url('DUMMY_satchmo_checkout-success'), status_code=302, target_status_code=200) self.assertEqual(len(mail.outbox), 1) # Log in as a superuser user = User.objects.create_user('fredsu', '*****@*****.**', 'passwd') user.is_staff = True user.is_superuser = True user.save() self.client.login(username='******', password='******') # Test invoice, packing slip and shipping label generation order_id = Order.objects.all()[0].id response = self.client.get('/admin/print/invoice/%d/' % order_id) self.assertEqual(response.status_code, 200) response = self.client.get('/admin/print/packingslip/%d/' % order_id) self.assertEqual(response.status_code, 200) response = self.client.get('/admin/print/shippinglabel/%d/' % order_id) self.assertEqual(response.status_code, 200)
def test_checkout(self): """ Run through a full checkout process """ cache_delete() tax = config_get('TAX','MODULE') tax.update('tax.modules.percent') pcnt = config_get('TAX', 'PERCENT') pcnt.update('10') shp = config_get('TAX', 'TAX_SHIPPING') shp.update(False) self.test_cart_adding() response = self.client.post(url('satchmo_checkout-step1'), get_step1_post_data(self.US)) self.assertRedirects(response, url('DUMMY_satchmo_checkout-step2'), status_code=302, target_status_code=200) data = { 'credit_type': 'Visa', 'credit_number': '4485079141095836', 'month_expires': '1', 'year_expires': '2014', 'ccv': '552', 'shipping': 'FlatRate'} response = self.client.post(url('DUMMY_satchmo_checkout-step2'), data) self.assertRedirects(response, url('DUMMY_satchmo_checkout-step3'), status_code=302, target_status_code=200) response = self.client.get(url('DUMMY_satchmo_checkout-step3')) amount = smart_str('Shipping + ' + moneyfmt(Decimal('4.00'))) self.assertContains(response, amount, count=1, status_code=200) amount = smart_str('Tax + ' + moneyfmt(Decimal('4.60'))) self.assertContains(response, amount, count=1, status_code=200) amount = smart_str('Total = ' + moneyfmt(Decimal('54.60'))) self.assertContains(response, amount, count=1, status_code=200) response = self.client.post(url('DUMMY_satchmo_checkout-step3'), {'process' : 'True'}) self.assertRedirects(response, url('DUMMY_satchmo_checkout-success'), status_code=302, target_status_code=200) self.assertEqual(len(mail.outbox), 1) # Log in as a superuser user = User.objects.create_user('fredsu', '*****@*****.**', 'passwd') user.is_staff = True user.is_superuser = True user.save() self.client.login(username='******', password='******') # Test pdf generation order_id = Order.objects.all()[0].id response = self.client.get('/admin/print/invoice/%d/' % order_id) self.assertContains(response, 'reportlab', status_code=200) response = self.client.get('/admin/print/packingslip/%d/' % order_id) self.assertContains(response, 'reportlab', status_code=200) response = self.client.get('/admin/print/shippinglabel/%d/' % order_id) self.assertContains(response, 'reportlab', status_code=200)
def _set_percent_taxer(percent): cache_delete() tax = config_get('TAX','MODULE') tax.update('tax.modules.percent') pcnt = config_get('TAX', 'PERCENT') pcnt.update(percent) shp = config_get('TAX', 'TAX_SHIPPING_PERCENT') shp.update(False) return shp
def _set_percent_taxer(percent): cache_delete() tax = config_get('TAX','MODULE') tax.update('tax.modules.percent') pcnt = config_get('TAX', 'PERCENT') pcnt.update(percent) shp = config_get('TAX', 'TAX_SHIPPING') shp.update(False) return shp
def test_checkout(self): """ Run through a full checkout process """ cache_delete() tax = config_get("TAX", "MODULE") tax.update("tax.modules.percent") pcnt = config_get("TAX", "PERCENT") pcnt.update("10") shp = config_get("TAX", "TAX_SHIPPING") shp.update(False) self.test_cart_adding() response = self.client.post(url("satchmo_checkout-step1"), get_step1_post_data(self.US)) self.assertRedirects(response, url("DUMMY_satchmo_checkout-step2"), status_code=302, target_status_code=200) data = { "credit_type": "Visa", "credit_number": "4485079141095836", "month_expires": "1", "year_expires": "2014", "ccv": "552", "shipping": "FlatRate", } response = self.client.post(url("DUMMY_satchmo_checkout-step2"), data) self.assertRedirects(response, url("DUMMY_satchmo_checkout-step3"), status_code=302, target_status_code=200) response = self.client.get(url("DUMMY_satchmo_checkout-step3")) amount = smart_str("Shipping + " + moneyfmt(Decimal("4.00"))) self.assertContains(response, amount, count=1, status_code=200) amount = smart_str("Tax + " + moneyfmt(Decimal("4.60"))) self.assertContains(response, amount, count=1, status_code=200) amount = smart_str("Total = " + moneyfmt(Decimal("54.60"))) self.assertContains(response, amount, count=1, status_code=200) response = self.client.post(url("DUMMY_satchmo_checkout-step3"), {"process": "True"}) self.assertRedirects(response, url("DUMMY_satchmo_checkout-success"), status_code=302, target_status_code=200) self.assertEqual(len(mail.outbox), 1) # Log in as a superuser user = User.objects.create_user("fredsu", "*****@*****.**", "passwd") user.is_staff = True user.is_superuser = True user.save() self.client.login(username="******", password="******") # Test pdf generation order_id = Order.objects.all()[0].id response = self.client.get("/admin/print/invoice/%d/" % order_id) self.assertContains(response, "reportlab", status_code=200) response = self.client.get("/admin/print/packingslip/%d/" % order_id) self.assertContains(response, "reportlab", status_code=200) response = self.client.get("/admin/print/shippinglabel/%d/" % order_id) self.assertContains(response, "reportlab", status_code=200)
def testDuplicateAdminAreas(self): """Test the situation where we have multiple adminareas with the same name""" cache_delete() tax = config_get('TAX','MODULE') tax.update('tax.modules.area') order = make_test_order('GB', 'Manchester') order.recalculate_total(save=False) price = order.total subtotal = order.sub_total tax = order.tax self.assertEqual(subtotal, Decimal('100.00')) self.assertEqual(tax, Decimal('20.00')) # 100 + 10 shipping + 20 tax self.assertEqual(price, Decimal('130.00')) taxes = order.taxes.all() self.assertEqual(2, len(taxes)) t1 = taxes[0] t2 = taxes[1] self.assert_('Shipping' in (t1.description, t2.description)) if t1.description == 'Shipping': tship = t1 tmain = t2 else: tship = t2 tmain = t1 self.assertEqual(tmain.tax, Decimal('20.00')) self.assertEqual(tship.tax, Decimal('0.00'))
def testNoArea(self): """Test No-Area tax module""" cache_delete() tax = config_get('TAX', 'MODULE') tax.update('satchmoutils.tax.modules.noarea') order = make_test_order(self.IT, '') order.recalculate_total(save=False) price = order.total subtotal = order.sub_total tax = order.tax self.assertEqual(subtotal, Decimal('50.00')) self.assertEqual(tax, Decimal('12.60')) # 50 + 10 shipping + 12.6 (21% on 60) tax self.assertEqual(price, Decimal('72.60')) taxes = order.taxes.all() self.assertEqual(2, len(taxes)) t1 = taxes[0] t2 = taxes[1] self.assert_('Shipping' in (t1.description, t2.description)) if t1.description == 'Shipping': tship = t1 tmain = t2 else: tship = t2 tmain = t1 self.assertEqual(tmain.tax, Decimal('10.50')) self.assertEqual(tship.tax, Decimal('2.10'))
def setUp(self): self.site = Site.objects.get_current() self.old_language_code = settings.LANGUAGE_CODE settings.LANGUAGE_CODE = 'it-it' self.IT = Country.objects.get(iso2_code__iexact="IT") tax = config_get('TAX', 'MODULE') tax.update('satchmoutils.tax.modules.noarea')
def test_send_org_emails(self): url = reverse('exmo2010:send_mail', args=[self.org.monitoring.pk]) post_data = {'comment': u'Содержание', 'subject': u'Тема', 'dst_orgs_noreg': '1'} server_address = config_get('EmailServer', 'DEFAULT_FROM_EMAIL') server_email_address = '*****@*****.**' server_address.update(u'Имя хоста <{}>'.format(server_email_address)) # WHEN I submit email form response = self.client.post(url, post_data, follow=True) # THEN response status_code should be 200 (OK) self.assertEqual(response.status_code, 200) # AND one email should be sent self.assertEqual(len(mail.outbox), 1) # AND email message should have expected headers message = mail.outbox[0] self.assertEqual(message.from_email, server_address) self.assertEqual(message.subject, u'Тема') self.assertEqual(message.to, [self.org.email]) # AND should have headers for Message Delivery Notification and ID self.assertEqual(message.extra_headers['Disposition-Notification-To'], server_email_address) self.assertEqual(message.extra_headers['Return-Receipt-To'], server_email_address) self.assertEqual(message.extra_headers['X-Confirm-Reading-To'], server_email_address) self.assertEqual(message.extra_headers['Message-ID'], '<%s@%s>' % (self.org.inv_code, DNS_NAME)) # TODO: move out this into new TestCase # AND invitation status should change from 'Not sent' to 'Sent' for org in Organization.objects.all(): self.assertEqual(org.inv_status, 'SNT')
def test_checkout_minimums(self): """ Validate we can add some items to the cart """ min_order = config_get("PAYMENT", "MINIMUM_ORDER") # start with no min. min_order.update("0.00") producturl = urlresolvers.reverse("satchmo_product", kwargs={"product_slug": "dj-rocks"}) response = self.client.get(producturl) self.assertContains(response, "Django Rocks shirt", count=2, status_code=200) cartadd = urlresolvers.reverse("satchmo_cart_add") response = self.client.post(cartadd, {"productname": "dj-rocks", "1": "L", "2": "BL", "quantity": "2"}) carturl = urlresolvers.reverse("satchmo_cart") self.assertRedirects(response, carturl, status_code=302, target_status_code=200) response = self.client.get(carturl) self.assertContains(response, "Django Rocks shirt (Large/Blue)", count=1, status_code=200) response = self.client.get(url("satchmo_checkout-step1")) self.assertContains(response, "Billing Information", count=1, status_code=200) # now check for min order not met min_order.update("100.00") response = self.client.get(url("satchmo_checkout-step1")) self.assertContains(response, "This store requires a minimum order", count=1, status_code=200) # add a bunch of shirts, to make the min order response = self.client.post(cartadd, {"productname": "dj-rocks", "1": "L", "2": "BL", "quantity": "10"}) self.assertRedirects(response, carturl, status_code=302, target_status_code=200) response = self.client.get(url("satchmo_checkout-step1")) self.assertContains(response, "Billing Information", count=1, status_code=200)
def testNoArea(self): """Test No-Area tax module""" cache_delete() tax = config_get('TAX','MODULE') tax.update('satchmoutils.tax.modules.noarea') order = make_test_order(self.IT, '') order.recalculate_total(save=False) price = order.total subtotal = order.sub_total tax = order.tax self.assertEqual(subtotal, Decimal('50.00')) self.assertEqual(tax, Decimal('12.60')) # 50 + 10 shipping + 12.6 (21% on 60) tax self.assertEqual(price, Decimal('72.60')) taxes = order.taxes.all() self.assertEqual(2, len(taxes)) t1 = taxes[0] t2 = taxes[1] self.assert_('Shipping' in (t1.description, t2.description)) if t1.description == 'Shipping': tship = t1 tmain = t2 else: tship = t2 tmain = t1 self.assertEqual(tmain.tax, Decimal('10.50')) self.assertEqual(tship.tax, Decimal('2.10'))
def setUp(self): self.site = Site.objects.get_current() self.old_language_code = settings.LANGUAGE_CODE settings.LANGUAGE_CODE = 'it-it' self.IT = Country.objects.get(iso2_code__iexact = "IT") tax = config_get('TAX','MODULE') tax.update('satchmoutils.tax.modules.noarea')
def make_urlpatterns(): patterns = [] for key in config_value('PAYMENT', 'MODULES'): cfg = config_get(key, 'MODULE') modulename = cfg.editor_value urlmodule = "%s.urls" % modulename patterns.append(url(config_value(key, 'URL_BASE'), [urlmodule])) return tuple(patterns)
def testAreaCountries(self): """Test Area tax module""" cache_delete() tax = config_get('TAX','MODULE') tax.update('tax.modules.area') order = make_test_order('DE', '', include_non_taxed=True) order.recalculate_total(save=False) price = order.total subtotal = order.sub_total tax = order.tax self.assertEqual(subtotal, Decimal('105.00')) self.assertEqual(tax, Decimal('20.00')) # 100 + 10 shipping + 20 tax self.assertEqual(price, Decimal('135.00')) taxes = order.taxes.all() self.assertEqual(2, len(taxes)) t1 = taxes[0] t2 = taxes[1] self.assert_('Shipping' in (t1.description, t2.description)) if t1.description == 'Shipping': tship = t1 tmain = t2 else: tship = t2 tmain = t1 self.assertEqual(tmain.tax, Decimal('20.00')) self.assertEqual(tship.tax, Decimal('0.00')) order = make_test_order('CH', '') order.recalculate_total(save=False) price = order.total subtotal = order.sub_total tax = order.tax self.assertEqual(subtotal, Decimal('100.00')) self.assertEqual(tax, Decimal('16.00')) # 100 + 10 shipping + 16 tax self.assertEqual(price, Decimal('126.00')) taxes = order.taxes.all() self.assertEqual(2, len(taxes)) t1 = taxes[0] t2 = taxes[1] self.assert_('Shipping' in (t1.description, t2.description)) if t1.description == 'Shipping': tship = t1 tmain = t2 else: tship = t2 tmain = t1 self.assertEqual(tmain.tax, Decimal('16.00')) self.assertEqual(tship.tax, Decimal('0.00'))
def payment_label(value): """convert a payment key into its translated text""" payments = config_get("PAYMENT", "MODULES") for mod in payments.value: config = config_get_group(mod) if config.KEY.value == value: return translation.ugettext(config.LABEL) return value.capitalize()
def test_cart_adding_errors_out_of_stock(self): # If no_stock_checkout is False, you should not be able to order a # product that is out of stock. setting = config_get('PRODUCT','NO_STOCK_CHECKOUT') setting.update(False) response = self.client.post(prefix + '/cart/add/', {'productname': 'neat-book', '3': 'soft', 'quantity': '1'}, follow=True) url = prefix + '/product/neat-book-soft/' self.assertRedirects(response, url, status_code=302, target_status_code=200) self.assertContains(response, "A really neat book (Soft cover)' is out of stock.", count=1)
def test_cart_adding_errors_out_of_stock(self): # If no_stock_checkout is False, you should not be able to order a # product that is out of stock. setting = config_get("PRODUCT", "NO_STOCK_CHECKOUT") setting.update(False) response = self.client.post( prefix + "/cart/add/", {"productname": "neat-book", "3": "soft", "quantity": "1"}, follow=True ) url = prefix + "/product/neat-book-soft/" self.assertRedirects(response, url, status_code=302, target_status_code=200) self.assertContains(response, "A really neat book (Soft cover)' is out of stock.", count=1)
def setUp(self): self.US = Country.objects.get(iso2_code__iexact='US') self.site = Site.objects.get_current() tax = config_get('TAX', 'MODULE') tax.update('tax.modules.no') c = Contact(first_name="Jim", last_name="Tester", role=ContactRole.objects.get(pk='Customer'), email="*****@*****.**") c.save() ad = AddressBook(contact=c, description="home", street1="test", state="OR", city="Portland", country=self.US, is_default_shipping=True, is_default_billing=True) ad.save() o = Order(contact=c, shipping_cost=Decimal('6.00'), site=self.site) o.save() small = Order(contact=c, shipping_cost=Decimal('6.00'), site=self.site) small.save() p = Product.objects.get(slug='neat-book-soft') price = p.unit_price item1 = OrderItem(order=o, product=p, quantity='1', unit_price=price, line_item_price=price) item1.save() item1s = OrderItem(order=small, product=p, quantity='1', unit_price=price, line_item_price=price) item1s.save() p = Product.objects.get(slug='neat-book-hard') price = p.unit_price item2 = OrderItem(order=o, product=p, quantity='1', unit_price=price, line_item_price=price) item2.save() self.order = o self.small = small rebuild_pricing()
def test_registration_view(self): """ Test that the registration view rejects invalid submissions, and creates a new user and redirects after a valid submission. """ if 'south' in settings.INSTALLED_APPS and 'satchmo_store.contact' in settings.INSTALLED_APPS: # South prevents some initial data loading for the test database from satchmo_store.contact.models import ContactRole if not ContactRole.objects.filter(pk='Customer').count(): ContactRole('Customer', name='Customer').save() try: from livesettings import config_get config_get('SHOP', 'ACCOUNT_VERIFICATION').update('EMAIL') except: pass # Invalid data fails. response = self.client.post(reverse('registration_register'), data={ 'username': '******', # Will fail on username uniqueness. 'email': '*****@*****.**', 'first_name': 'foo', 'last_name': 'foo', 'password1': 'foo', 'password2': 'foo' }) self.assertEqual(response.status_code, 200) self.failUnless(response.context['form']) self.failUnless(response.context['form'].errors) response = self.client.post(reverse('registration_register'), data={ 'username': '******', 'email': '*****@*****.**', 'first_name': 'foo', 'last_name': 'foo', 'password1': 'foo', 'password2': 'foo' }) self.assertEqual(response.status_code, 302) self.assertEqual(response['Location'], 'http://testserver%s' % reverse('registration_complete')) self.assertEqual(RegistrationProfile.objects.count(), 3)
def test_list_get(self): events = [] for ix in range(2): events.append(BaseEventResourceTest.make_event_fixture()) featured_event = livesettings.config_get("EVENTS", "FEATURED_EVENT_ID") events[0].id = featured_event.value events[0].save() featured_event.update(events[0].id) resp = self.client.get(self.uri, data=self.auth_params) self.assertResponseCode(resp, 200) self.assertResponseMetaList(resp, 1)
def testPercentShipping(self): """Test percent tax with shipping""" cache_delete() tax = config_get('TAX','MODULE') tax.update('tax.modules.percent') pcnt = config_get('TAX', 'PERCENT') pcnt.update('10') shp = config_get('TAX', 'TAX_SHIPPING') shp.update(False) order = make_test_order('US', 'TX') shp.update(True) order.recalculate_total(save=False) price = order.total tax = order.tax self.assertEqual(tax, Decimal('11.00')) # 100 + 10 shipping + 11 tax self.assertEqual(price, Decimal('121.00')) taxes = order.taxes.all() self.assertEqual(2, len(taxes)) t1 = taxes[0] t2 = taxes[1] self.assert_('Shipping' in (t1.description, t2.description)) if t1.description == 'Shipping': tship = t1 tmain = t2 else: tship = t2 tmain = t1 self.assertEqual(tmain.tax, Decimal('10.00')) self.assertEqual(tmain.description, r'10%') self.assertEqual(tship.tax, Decimal('1.00')) self.assertEqual(tship.description, 'Shipping')
def test_list_get(self): events = [] for ix in range(2): events.append(BaseEventResourceTest.make_event_fixture()) featured_event = livesettings.config_get('EVENTS', 'FEATURED_EVENT_ID') events[0].id = featured_event.value events[0].save() featured_event.update(events[0].id) resp = self.client.get(self.uri, data=self.auth_params) self.assertResponseCode(resp, 200) self.assertResponseMetaList(resp, 1)
def test_cart_removing(self): """ Validate we can remove an item """ setting = config_get('PRODUCT','NO_STOCK_CHECKOUT') setting.update(True) self.test_cart_adding(retest=True) response = self.client.post(prefix + '/cart/remove/', {'cartitem': '1'}) #self.assertRedirects(response, prefix + '/cart/', # status_code=302, target_status_code=200) response = self.client.get(prefix+'/cart/') self.assertContains(response, "Your cart is empty.", count=1, status_code=200)
def make_call(x_type, amount=None): GROUP = 'PAYMENT_AUTHORIZENET' TRANKEY = config_get(GROUP, 'TRANKEY').value LOGIN = config_get(GROUP, 'LOGIN').value WE_ARE_LIVE = config_get(GROUP, 'LIVE').value TEST_URL = config_get(GROUP, 'CONNECTION_TEST').value LIVE_URL = config_get(GROUP, 'CONNECTION').value THE_URL = LIVE_URL if WE_ARE_LIVE else TEST_URL data = { 'x_login': LOGIN, 'x_tran_key': TRANKEY, 'x_delim_data': 'TRUE', 'x_delim_char': '|', 'x_type': x_type, 'x_method': 'CC', 'x_card_num': cd['credit_number'], 'x_card_code': cd['ccv'], 'x_exp_date': cd['month_expires'] + cd['year_expires'][-2:], 'x_first_name': cd['first_name'], 'x_last_name': cd['last_name'], 'x_address': cd['street1'], 'x_city': smart_str(cd['city']), 'x_state': cd['state'], 'x_zip': cd['postal_code'], 'x_country': cd['country'] } if cd['amount']: data['x_amount'] = cd['amount'] req = urllib2.Request(url=THE_URL, data=urlencode(data)) f = urllib2.urlopen(req) response = f.read() response_code = int(response.split('|')[0]) success = response_code == 1 return (success, response)
def test_cart_removing(self): """ Validate we can remove an item """ setting = config_get('PRODUCT','NO_STOCK_CHECKOUT') setting.update(True) self.test_cart_adding(retest=True) response = self.client.get(prefix+'/cart/') cartitem_id = response.context[0]['cart'].cartitem_set.all()[0].id response = self.client.post(prefix + '/cart/remove/', {'cartitem': str(cartitem_id)}) #self.assertRedirects(response, prefix + '/cart/', # status_code=302, target_status_code=200) response = self.client.get(prefix+'/cart/') self.assertContains(response, "Your cart is empty.", count=1, status_code=200)
def test_cart_removing(self): """ Validate we can remove an item """ setting = config_get("PRODUCT", "NO_STOCK_CHECKOUT") setting.update(True) self.test_cart_adding(retest=True) response = self.client.get(prefix + "/cart/") cartitem_id = response.context[0]["cart"].cartitem_set.all()[0].id response = self.client.post(prefix + "/cart/remove/", {"cartitem": str(cartitem_id)}) # self.assertRedirects(response, prefix + '/cart/', # status_code=302, target_status_code=200) response = self.client.get(prefix + "/cart/") self.assertContains(response, "Your cart is empty.", count=1, status_code=200)
def setUp(self): self.US = Country.objects.get(iso2_code__iexact="US") self.site = Site.objects.get_current() tax = config_get("TAX", "MODULE") tax.update("tax.modules.no") c = Contact( first_name="Jim", last_name="Tester", role=ContactRole.objects.get(pk="Customer"), email="*****@*****.**" ) c.save() ad = AddressBook( contact=c, description="home", street1="test", state="OR", city="Portland", country=self.US, is_default_shipping=True, is_default_billing=True, ) ad.save() o = Order(contact=c, shipping_cost=Decimal("6.00"), site=self.site) o.save() small = Order(contact=c, shipping_cost=Decimal("6.00"), site=self.site) small.save() p = Product.objects.get(slug="neat-book-soft") price = p.unit_price item1 = OrderItem(order=o, product=p, quantity="1", unit_price=price, line_item_price=price) item1.save() item1s = OrderItem(order=small, product=p, quantity="1", unit_price=price, line_item_price=price) item1s.save() p = Product.objects.get(slug="neat-book-hard") price = p.unit_price item2 = OrderItem(order=o, product=p, quantity="1", unit_price=price, line_item_price=price) item2.save() self.order = o self.small = small rebuild_pricing()
def test_send_org_emails(self): url = reverse('exmo2010:send_mail', args=[self.org.monitoring.pk]) post_data = { 'comment': u'Содержание', 'subject': u'Тема', 'dst_orgs_noreg': '1' } server_address = config_get('EmailServer', 'DEFAULT_FROM_EMAIL') server_email_address = '*****@*****.**' server_address.update(u'Имя хоста <{}>'.format(server_email_address)) # WHEN I submit email form response = self.client.post(url, post_data, follow=True) # THEN response status_code should be 200 (OK) self.assertEqual(response.status_code, 200) # AND one email should be sent self.assertEqual(len(mail.outbox), 1) # AND email message should have expected headers message = mail.outbox[0] self.assertEqual(message.from_email, server_address) self.assertEqual(message.subject, u'Тема') self.assertEqual(message.to, [self.org.email]) # AND should have headers for Message Delivery Notification and ID self.assertEqual(message.extra_headers['Disposition-Notification-To'], server_email_address) self.assertEqual(message.extra_headers['Return-Receipt-To'], server_email_address) self.assertEqual(message.extra_headers['X-Confirm-Reading-To'], server_email_address) self.assertEqual(message.extra_headers['Message-ID'], '<%s@%s>' % (self.org.inv_code, DNS_NAME)) # TODO: move out this into new TestCase # AND invitation status should change from 'Not sent' to 'Sent' for org in Organization.objects.all(): self.assertEqual(org.inv_status, 'SNT')
def test_two_checkouts_dont_duplicate_contact(self): """ Two checkouts with the same email address do not duplicate contacts Ticket #1264 [Invalid] """ tax = config_get("TAX", "MODULE") tax.update("tax.modules.percent") pcnt = config_get("TAX", "PERCENT") pcnt.update("10") shp = config_get("TAX", "TAX_SHIPPING") shp.update(False) # First checkout self.test_cart_adding() response = self.client.post(url("satchmo_checkout-step1"), get_step1_post_data(self.US)) self.assertRedirects(response, url("DUMMY_satchmo_checkout-step2"), status_code=302, target_status_code=200) data = { "credit_type": "Visa", "credit_number": "4485079141095836", "month_expires": "1", "year_expires": "2014", "ccv": "552", "shipping": "FlatRate", } response = self.client.post(url("DUMMY_satchmo_checkout-step2"), data) self.assertRedirects(response, url("DUMMY_satchmo_checkout-step3"), status_code=302, target_status_code=200) response = self.client.get(url("DUMMY_satchmo_checkout-step3")) amount = smart_str("Shipping + " + moneyfmt(Decimal("4.00"))) self.assertContains(response, amount, count=1, status_code=200) amount = smart_str("Tax + " + moneyfmt(Decimal("4.60"))) self.assertContains(response, amount, count=1, status_code=200) amount = smart_str("Total = " + moneyfmt(Decimal("54.60"))) self.assertContains(response, amount, count=1, status_code=200) response = self.client.post(url("DUMMY_satchmo_checkout-step3"), {"process": "True"}) self.assertRedirects(response, url("DUMMY_satchmo_checkout-success"), status_code=302, target_status_code=200) # Second checkout self.test_cart_adding() response = self.client.post(url("satchmo_checkout-step1"), get_step1_post_data(self.US)) self.assertRedirects(response, url("DUMMY_satchmo_checkout-step2"), status_code=302, target_status_code=200) data = { "credit_type": "Visa", "credit_number": "4485079141095836", "month_expires": "1", "year_expires": "2014", "ccv": "552", "shipping": "FlatRate", } response = self.client.post(url("DUMMY_satchmo_checkout-step2"), data) self.assertRedirects(response, url("DUMMY_satchmo_checkout-step3"), status_code=302, target_status_code=200) response = self.client.get(url("DUMMY_satchmo_checkout-step3")) amount = smart_str("Shipping + " + moneyfmt(Decimal("4.00"))) self.assertContains(response, amount, count=1, status_code=200) amount = smart_str("Tax + " + moneyfmt(Decimal("4.60"))) self.assertContains(response, amount, count=1, status_code=200) amount = smart_str("Total = " + moneyfmt(Decimal("54.60"))) self.assertContains(response, amount, count=1, status_code=200) response = self.client.post(url("DUMMY_satchmo_checkout-step3"), {"process": "True"}) self.assertRedirects(response, url("DUMMY_satchmo_checkout-success"), status_code=302, target_status_code=200) self.assertEqual(len(mail.outbox), 2) qs = Contact.objects.filter(email="*****@*****.**") # We expects that the contact do not duplicate self.assertEqual(len(qs), 1)
def test_two_checkouts_dont_duplicate_contact(self): """ Two checkouts with the same email address do not duplicate contacts Ticket #1264 [Invalid] """ tax = config_get('TAX','MODULE') tax.update('tax.modules.percent') pcnt = config_get('TAX', 'PERCENT') pcnt.update('10') shp = config_get('TAX', 'TAX_SHIPPING') shp.update(False) # First checkout self.test_cart_adding() response = self.client.post(url('satchmo_checkout-step1'), get_step1_post_data(self.US)) self.assertRedirects(response, url('DUMMY_satchmo_checkout-step2'), status_code=302, target_status_code=200) data = { 'credit_type': 'Visa', 'credit_number': '4485079141095836', 'month_expires': '1', 'year_expires': '2014', 'ccv': '552', 'shipping': 'FlatRate'} response = self.client.post(url('DUMMY_satchmo_checkout-step2'), data) self.assertRedirects(response, url('DUMMY_satchmo_checkout-step3'), status_code=302, target_status_code=200) response = self.client.get(url('DUMMY_satchmo_checkout-step3')) amount = smart_str('Shipping + ' + moneyfmt(Decimal('4.00'))) self.assertContains(response, amount, count=1, status_code=200) amount = smart_str('Tax + ' + moneyfmt(Decimal('4.60'))) self.assertContains(response, amount, count=1, status_code=200) amount = smart_str('Total = ' + moneyfmt(Decimal('54.60'))) self.assertContains(response, amount, count=1, status_code=200) response = self.client.post(url('DUMMY_satchmo_checkout-step3'), {'process' : 'True'}) self.assertRedirects(response, url('DUMMY_satchmo_checkout-success'), status_code=302, target_status_code=200) # Second checkout self.test_cart_adding() response = self.client.post(url('satchmo_checkout-step1'), get_step1_post_data(self.US)) self.assertRedirects(response, url('DUMMY_satchmo_checkout-step2'), status_code=302, target_status_code=200) data = { 'credit_type': 'Visa', 'credit_number': '4485079141095836', 'month_expires': '1', 'year_expires': '2014', 'ccv': '552', 'shipping': 'FlatRate'} response = self.client.post(url('DUMMY_satchmo_checkout-step2'), data) self.assertRedirects(response, url('DUMMY_satchmo_checkout-step3'), status_code=302, target_status_code=200) response = self.client.get(url('DUMMY_satchmo_checkout-step3')) amount = smart_str('Shipping + ' + moneyfmt(Decimal('4.00'))) self.assertContains(response, amount, count=1, status_code=200) amount = smart_str('Tax + ' + moneyfmt(Decimal('4.60'))) self.assertContains(response, amount, count=1, status_code=200) amount = smart_str('Total = ' + moneyfmt(Decimal('54.60'))) self.assertContains(response, amount, count=1, status_code=200) response = self.client.post(url('DUMMY_satchmo_checkout-step3'), {'process' : 'True'}) self.assertRedirects(response, url('DUMMY_satchmo_checkout-success'), status_code=302, target_status_code=200) self.assertEqual(len(mail.outbox), 2) qs = Contact.objects.filter(email="*****@*****.**") # We expects that the contact do not duplicate self.assertEqual(len(qs), 1)
def setUp(self): cfg = config_get('NEWSLETTER', 'MODULE') cfg.update('satchmo_ext.newsletter.simple') self.client = Client()
# -*- coding: utf-8 -*- import os import urlparse from decimal import Decimal from django.conf import settings from django.utils.translation import ugettext_lazy as _ from livesettings import config_register, BooleanValue, StringValue, \ MultipleStringValue, ConfigurationGroup, PositiveIntegerValue, \ DecimalValue, config_get BILLING_GROUP = ConfigurationGroup('BILLING', _('Billing Settings'), ordering=0) SERVER_MODULES = config_get('SERVER', 'MODULES') SERVER_MODULES.add_choice(('nibblebill', _('Billings'))) SERVER_MODULES.add_choice(('nibblebill', _('Billings'))) ##SERVER_GROUP = ConfigurationGroup('xml_cdr', ## _('CDR XML Module Settings'), ## requires=SERVER_MODULES, ## ordering = 104) config_register(DecimalValue( BILLING_GROUP, 'BALANCE_CASH', description = _('Beginning balance'), help_text = _("The initial balance in the new user registration such as 0.25 USD"), default = Decimal('0.25') )) config_register(PositiveIntegerValue(
from satchmo_store.shop.models import Config from livesettings import config_get_group, config_value from l10n.models import Country from vcms.www.registration.models import AdminRegistrationProfile from vcms.www.views.html import _get_page_parameters from updates_registration.views import UpdatesRegistrationForm, UpdatesRegistrationFormManager import imp import logging log = logging.getLogger('vcms.store.views') # Add the Administrator verification method to the # site settings "Account Verification" option. from livesettings import config_get from satchmo_store.shop.config import SHOP_GROUP ACCOUNT_VERIFICATION = config_get(SHOP_GROUP, 'ACCOUNT_VERIFICATION') ACCOUNT_VERIFICATION.add_choice(('ADMINISTRATOR', _('Administrator'))) # Get the registration form class to use for this configuration #REGISTER_MODULE = '/'.join(settings.REGISTER_FORM.split('.')[:-1]) # imp.find_module requires the '.' to be '/' in order to find the module #REGISTER_CLASS = settings.REGISTER_FORM.split('.')[-1] #REGISTER_FORM = getattr(imp.load_module(REGISTER_CLASS, *imp.find_module(REGISTER_MODULE)), REGISTER_CLASS) REGISTER_MODULE = '.'.join(settings.REGISTER_FORM.split('.')[:-1]) REGISTER_CLASS = settings.REGISTER_FORM.split('.')[-1] mod = __import__(REGISTER_MODULE, globals(), locals(), ['forms'], -1) REGISTER_FORM = getattr(mod, REGISTER_CLASS) def get_queryset_states_provinces(country_id): """ Returns a queryset containing the active states/provinces for the given country.
from satchmo_store.shop.models import Config from livesettings import config_get_group, config_value from l10n.models import Country from vcms.www.registration.models import AdminRegistrationProfile from vcms.www.views.html import _get_page_parameters from updates_registration.views import UpdatesRegistrationForm, UpdatesRegistrationFormManager import imp import logging log = logging.getLogger('vcms.store.views') # Add the Administrator verification method to the # site settings "Account Verification" option. from livesettings import config_get from satchmo_store.shop.config import SHOP_GROUP ACCOUNT_VERIFICATION = config_get(SHOP_GROUP, 'ACCOUNT_VERIFICATION') ACCOUNT_VERIFICATION.add_choice(('ADMINISTRATOR', _('Administrator'))) # Get the registration form class to use for this configuration #REGISTER_MODULE = '/'.join(settings.REGISTER_FORM.split('.')[:-1]) # imp.find_module requires the '.' to be '/' in order to find the module #REGISTER_CLASS = settings.REGISTER_FORM.split('.')[-1] #REGISTER_FORM = getattr(imp.load_module(REGISTER_CLASS, *imp.find_module(REGISTER_MODULE)), REGISTER_CLASS) REGISTER_MODULE = '.'.join(settings.REGISTER_FORM.split('.')[:-1]) REGISTER_CLASS = settings.REGISTER_FORM.split('.')[-1] mod = __import__(REGISTER_MODULE, globals(), locals(), ['forms'], -1) REGISTER_FORM = getattr(mod, REGISTER_CLASS) def get_queryset_states_provinces(country_id): """
def test_checkout_minimums(self): """ Validate we can add some items to the cart """ min_order = config_get('PAYMENT', 'MINIMUM_ORDER') #start with no min. min_order.update("0.00") producturl = urlresolvers.reverse("satchmo_product", kwargs={'product_slug': 'dj-rocks'}) response = self.client.get(producturl) self.assertContains(response, "Django Rocks shirt", count=2, status_code=200) cartadd = urlresolvers.reverse('satchmo_cart_add') response = self.client.post(cartadd, { "productname": "dj-rocks", "1": "L", "2": "BL", "quantity": '2' }) carturl = urlresolvers.reverse('satchmo_cart') self.assertRedirects(response, carturl, status_code=302, target_status_code=200) response = self.client.get(carturl) self.assertContains(response, "Django Rocks shirt (Large/Blue)", count=1, status_code=200) response = self.client.get(url('satchmo_checkout-step1')) self.assertContains(response, "Billing Information", count=1, status_code=200) # now check for min order not met min_order.update("100.00") response = self.client.get(url('satchmo_checkout-step1')) self.assertContains(response, "This store requires a minimum order", count=1, status_code=200) # add a bunch of shirts, to make the min order response = self.client.post(cartadd, { "productname": "dj-rocks", "1": "L", "2": "BL", "quantity": '10' }) self.assertRedirects(response, carturl, status_code=302, target_status_code=200) response = self.client.get(url('satchmo_checkout-step1')) self.assertContains(response, "Billing Information", count=1, status_code=200)
def setUp(self): self.client = Client() self.IT = Country.objects.get(iso2_code__iexact="IT") cache_delete() tax = config_get('TAX', 'MODULE') tax.update('satchmoutils.tax.modules.noarea')
def setUp(self): cache_delete() tax = config_get('TAX', 'MODULE') tax.update('satchmoutils.tax.modules.noarea')
def setup_test_solr(): settings.SOLR_DATA_CORE = 'data_test' settings.SOLR_DATASETS_CORE = 'datasets_test' config_get('PERF', 'TASK_THROTTLE').update(0.0) solr.delete(settings.SOLR_DATA_CORE, '*:*') solr.delete(settings.SOLR_DATASETS_CORE, '*:*')
# -*- coding: utf-8 -*- import os import urlparse from decimal import Decimal from django.conf import settings from django.utils.translation import ugettext_lazy as _ from livesettings import config_register, BooleanValue, StringValue, \ MultipleStringValue, ConfigurationGroup, PositiveIntegerValue, \ DecimalValue, config_get BILLING_GROUP = ConfigurationGroup('BILLING', _('Billing Settings'), ordering=0) SERVER_MODULES = config_get('SERVER', 'MODULES') SERVER_MODULES.add_choice(('nibblebill', _('Billings'))) SERVER_MODULES.add_choice(('nibblebill', _('Billings'))) ##SERVER_GROUP = ConfigurationGroup('xml_cdr', ## _('CDR XML Module Settings'), ## requires=SERVER_MODULES, ## ordering = 104) config_register( DecimalValue( BILLING_GROUP, 'BALANCE_CASH', description=_('Beginning balance'), help_text=_( "The initial balance in the new user registration such as 0.25 USD"
def test_custom_product(self): """ Verify that the custom product is working as expected. """ pm = config_get("PRODUCT", "PRODUCT_TYPES") pm.update( [ "product::ConfigurableProduct", "product::ProductVariation", "product::CustomProduct", "product::SubscriptionProduct", ] ) response = self.client.get(prefix + "/") self.assertContains(response, "Computer", count=1) response = self.client.get(prefix + "/product/satchmo-computer/") self.assertContains(response, "Memory", count=1) self.assertContains(response, "Case", count=1) self.assertContains(response, "Monogram", count=1) response = self.client.post( prefix + "/cart/add/", {"productname": "satchmo-computer", "5": "1.5gb", "6": "mid", "custom_monogram": "CBM", "quantity": "1"}, ) self.assertRedirects(response, prefix + "/cart/", status_code=302, target_status_code=200) response = self.client.get(prefix + "/cart/") self.assertContains(response, '/satchmo-computer/">satchmo computer', count=1, status_code=200) self.assertContains(response, smart_str("%s168.00" % config_value("LANGUAGE", "CURRENCY")), count=3) self.assertContains( response, smart_str("Monogram: CBM %s10.00" % config_value("LANGUAGE", "CURRENCY")), count=1 ) self.assertContains( response, smart_str("Case - External Case: Mid %s10.00" % config_value("LANGUAGE", "CURRENCY")), count=1 ) self.assertContains( response, smart_str("Memory - Internal RAM: 1.5 GB %s25.00" % config_value("LANGUAGE", "CURRENCY")), count=1, ) response = self.client.post(url("satchmo_checkout-step1"), get_step1_post_data(self.US)) self.assertRedirects(response, url("DUMMY_satchmo_checkout-step2"), status_code=302, target_status_code=200) data = { "credit_type": "Visa", "credit_number": "4485079141095836", "month_expires": "1", "year_expires": "2012", "ccv": "552", "shipping": "FlatRate", } response = self.client.post(url("DUMMY_satchmo_checkout-step2"), data) self.assertRedirects(response, url("DUMMY_satchmo_checkout-step3"), status_code=302, target_status_code=200) response = self.client.get(url("DUMMY_satchmo_checkout-step3")) self.assertContains( response, smart_str("satchmo computer - %s168.00" % config_value("LANGUAGE", "CURRENCY")), count=1, status_code=200, ) response = self.client.post(url("DUMMY_satchmo_checkout-step3"), {"process": "True"}) self.assertRedirects(response, url("DUMMY_satchmo_checkout-success"), status_code=302, target_status_code=200) self.assertEqual(len(mail.outbox), 1)
def test_two_checkouts_dont_duplicate_contact(self): """ Two checkouts with the same email address do not duplicate contacts Ticket #1264 [Invalid] """ tax = config_get('TAX','MODULE') tax.update('tax.modules.percent') pcnt = config_get('TAX', 'PERCENT') pcnt.update('10') shp = config_get('TAX', 'TAX_SHIPPING') shp.update(False) # First checkout self.test_cart_adding() response = self.client.post(url('satchmo_checkout-step1'), get_step1_post_data(self.US)) self.assertRedirects(response, url('DUMMY_satchmo_checkout-step2'), status_code=302, target_status_code=200) data = { 'credit_type': 'Visa', 'credit_number': '4485079141095836', 'month_expires': '1', 'year_expires': '2015', 'ccv': '552', 'shipping': 'FlatRate'} response = self.client.post(url('DUMMY_satchmo_checkout-step2'), data) self.assertRedirects(response, url('DUMMY_satchmo_checkout-step3'), status_code=302, target_status_code=200) response = self.client.get(url('DUMMY_satchmo_checkout-step3')) amount = smart_str('Shipping + ' + moneyfmt(Decimal('4.00'))) self.assertContains(response, amount, count=1, status_code=200) amount = smart_str('Tax + ' + moneyfmt(Decimal('4.60'))) self.assertContains(response, amount, count=1, status_code=200) amount = smart_str('Total = ' + moneyfmt(Decimal('54.60'))) self.assertContains(response, amount, count=1, status_code=200) response = self.client.post(url('DUMMY_satchmo_checkout-step3'), {'process' : 'True'}) self.assertRedirects(response, url('DUMMY_satchmo_checkout-success'), status_code=302, target_status_code=200) # Second checkout self.test_cart_adding() response = self.client.post(url('satchmo_checkout-step1'), get_step1_post_data(self.US)) self.assertRedirects(response, url('DUMMY_satchmo_checkout-step2'), status_code=302, target_status_code=200) data = { 'credit_type': 'Visa', 'credit_number': '4485079141095836', 'month_expires': '1', 'year_expires': '2015', 'ccv': '552', 'shipping': 'FlatRate'} response = self.client.post(url('DUMMY_satchmo_checkout-step2'), data) self.assertRedirects(response, url('DUMMY_satchmo_checkout-step3'), status_code=302, target_status_code=200) response = self.client.get(url('DUMMY_satchmo_checkout-step3')) amount = smart_str('Shipping + ' + moneyfmt(Decimal('4.00'))) self.assertContains(response, amount, count=1, status_code=200) amount = smart_str('Tax + ' + moneyfmt(Decimal('4.60'))) self.assertContains(response, amount, count=1, status_code=200) amount = smart_str('Total = ' + moneyfmt(Decimal('54.60'))) self.assertContains(response, amount, count=1, status_code=200) response = self.client.post(url('DUMMY_satchmo_checkout-step3'), {'process' : 'True'}) self.assertRedirects(response, url('DUMMY_satchmo_checkout-success'), status_code=302, target_status_code=200) self.assertEqual(len(mail.outbox), 2) qs = Contact.objects.filter(email="*****@*****.**") # We expects that the contact do not duplicate self.assertEqual(len(qs), 1)
def setUp(self): self.client = Client() self.IT = Country.objects.get(iso2_code__iexact = "IT") cache_delete() tax = config_get('TAX','MODULE') tax.update('satchmoutils.tax.modules.noarea')
def setUp(self): cache_delete() tax = config_get('TAX','MODULE') tax.update('satchmoutils.tax.modules.noarea')