def setUp(self): # clear out cache from previous runs keyedcache.cache_delete() g1 = ConfigurationGroup('req2', 'Requirements 2', ordering=1000) self.g1 = g1 choices1 = config_register( MultipleStringValue(BASE_GROUP, 'rc1', ordering=1)) self.g1c1 = config_register( IntegerValue(g1, 'c1', requires=choices1, ordering=3)) self.g1c2 = config_register( IntegerValue(g1, 'c2', requires=choices1, ordering=4)) self.g1c3 = config_register(IntegerValue(g1, 'c3', ordering=5)) choices1.update('c1') g2 = ConfigurationGroup('req3', 'Requirements 3', ordering=1000) self.g2 = g2 choices2 = config_register( StringValue(BASE_GROUP, 'choices2', ordering=1)) self.g2c1 = config_register( IntegerValue(g2, 'c1', requires=choices2, ordering=3)) self.g2c2 = config_register( IntegerValue(g2, 'c2', requires=choices2, ordering=4)) self.g2c3 = config_register( IntegerValue(g2, 'c3', requires=choices2, ordering=5)) choices2.update('c1')
def setUp(self): # clear out cache from previous runs keyedcache.cache_delete() g1 = ConfigurationGroup('reqval', 'Requirements 3', ordering=1000) self.g1 = g1 choices1 = config_register(MultipleStringValue(BASE_GROUP, 'valchoices', ordering=1)) self.g1c1 = config_register(IntegerValue(g1, 'c1', requires=choices1, requiresvalue='foo', ordering=3)) self.g1c2 = config_register(IntegerValue(g1, 'c2', requires=choices1, requiresvalue='bar', ordering=4)) self.g1c3 = config_register(IntegerValue(g1, 'c3', ordering=5)) choices1.update('foo') g2 = ConfigurationGroup('reqval2', 'Requirements 4', ordering=1000) self.g2 = g2 choices2 = config_register(StringValue(BASE_GROUP, 'valchoices2', ordering=1, choices=(('a','test a'),('b', 'test b'),('c', 'test c')))) self.g2c1 = config_register(IntegerValue(g2, 'c1', requires=choices2, requiresvalue='a', ordering=3)) self.g2c2 = config_register(IntegerValue(g2, 'c2', requires=choices2, requiresvalue='b', ordering=4)) self.g2c3 = config_register(IntegerValue(g2, 'c3', requires=choices2, requiresvalue='c', ordering=5)) choices2.update('a')
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 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 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): from django.contrib.auth.models import Permission, User from django.contrib.contenttypes.models import ContentType # Users with different permissions # staff member user1 = User.objects.create_user('warehouseman', '*****@*****.**', 'secret') user1.is_staff = True user1.save() # developper with limited permissions user2 = User.objects.create_user('cautious_developer', '*****@*****.**', 'secret') user2.is_staff = True user2.user_permissions.add(Permission.objects.get(codename='change_setting', \ content_type=ContentType.objects.get(app_label='livesettings', model='setting'))) user2.save() # superuser user3 = User.objects.create_user('superuser', '*****@*****.**', 'secret') user3.is_superuser = True user3.save() keyedcache.cache_delete() # Example config config_register(IntegerValue(BASE_GROUP, 'SingleItem', default=0))
def setUp(self): # clear out cache from previous runs keyedcache.cache_delete() g1 = ConfigurationGroup('req2', 'Requirements 2', ordering=1000) self.g1 = g1 choices1 = config_register(MultipleStringValue(BASE_GROUP, 'rc1', ordering=1)) self.g1c1 = config_register(IntegerValue(g1, 'c1', requires=choices1, ordering=3)) self.g1c2 = config_register(IntegerValue(g1, 'c2', requires=choices1, ordering=4)) self.g1c3 = config_register(IntegerValue(g1, 'c3', ordering=5)) choices1.update('c1') g2 = ConfigurationGroup('req3', 'Requirements 3', ordering=1000) self.g2 = g2 choices2 = config_register(StringValue(BASE_GROUP, 'choices2', ordering=1)) self.g2c1 = config_register(IntegerValue(g2, 'c1', requires=choices2, ordering=3)) self.g2c2 = config_register(IntegerValue(g2, 'c2', requires=choices2, ordering=4)) self.g2c3 = config_register(IntegerValue(g2, 'c3', requires=choices2, ordering=5)) choices2.update('c1')
def setUp(self): # clear out cache from previous runs keyedcache.cache_delete() g1 = ConfigurationGroup('reqval', 'Requirements 3', ordering=1000) self.g1 = g1 choices1 = config_register(MultipleStringValue(BASE_GROUP, 'valchoices', ordering=1)) self.g1c1 = config_register(IntegerValue(g1, 'c1', requires=choices1, requiresvalue='foo', ordering=3)) self.g1c2 = config_register(IntegerValue(g1, 'c2', requires=choices1, requiresvalue='bar', ordering=4)) self.g1c3 = config_register(IntegerValue(g1, 'c3', ordering=5)) choices1.update('foo') g2 = ConfigurationGroup('reqval2', 'Requirements 4', ordering=1000) self.g2 = g2 choices2 = config_register(StringValue(BASE_GROUP, 'valchoices2', ordering=1, choices=(('a', 'test a'), ('b', 'test b'), ('c', 'test c')))) self.g2c1 = config_register(IntegerValue(g2, 'c1', requires=choices2, requiresvalue='a', ordering=3)) self.g2c2 = config_register(IntegerValue(g2, 'c2', requires=choices2, requiresvalue='b', ordering=4)) self.g2c3 = config_register(IntegerValue(g2, 'c3', requires=choices2, requiresvalue='c', ordering=5)) choices2.update('a')
def setUp(self): # clear out cache from previous runs keyedcache.cache_delete() g = ConfigurationGroup('modules', 'module test') self.g = g self.c = config_register(ModuleValue(g, 'test'))
def setUp(self): # clear out cache from previous runs keyedcache.cache_delete() g = ConfigurationGroup('modules','module test') self.g = g self.c = config_register(ModuleValue(g, 'test'))
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): # clear out cache from previous runs keyedcache.cache_delete() g = ConfigurationGroup('test2', 'test2') self.g = g config_register(StringValue(g, 's1')) config_register(IntegerValue(g, 's2', default=10)) config_register(IntegerValue(g, 's3', default=10))
def setUp(self): # clear out cache from previous runs keyedcache.cache_delete() g = ConfigurationGroup('test2','test2') self.g = g config_register(StringValue(g, 's1')) config_register(IntegerValue(g, 's2', default=10)) config_register(IntegerValue(g, 's3', default=10))
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 setUp(self): # clear out cache from previous runs keyedcache.cache_delete() g = ConfigurationGroup('test3', 'test3') self.g = g c1 = config_register(BooleanValue(g, 's1', default=True)) c2 = config_register(IntegerValue(g, 's2', default=10)) c2.update(100)
def setUp(self): # Every test needs a client cache_delete() self.client = Client() self.US = Country.objects.get(iso2_code__iexact="US") current_site = Site.objects.get_current() cache_key = "cat-%s-%s" % (current_site.id, get_language()) cache.delete(cache_key) rebuild_pricing()
def setUp(self): # Every test needs a client cache_delete() self.client = Client() self.US = Country.objects.get(iso2_code__iexact = "US") rebuild_pricing() current_site = Site.objects.get_current() cache_key = "cat-%s-%s" % (current_site.id, get_language()) cache.delete(cache_key)
def catch_sites(*args, **kwargs): """Listen to sites modifications due to cache flushing""" #keyedcache.cache_delete('SITE', children=True) import keyedcache #print keyedcache.CACHED_KEYS #import pdb; pdb.set_trace() # We can not rely on the domain name of the modified/deleted site when testing. Because it is 'testserver'. # The following would be better, but does not work: keyedcache.cache_delete('SITE', host=kwargs['instance'].domain, children=True)
def setUp(self): # clear out cache from previous runs keyedcache.cache_delete() g = ConfigurationGroup('test3','test3') self.g = g c1 = config_register(BooleanValue(g, 's1', default=True)) c2 = config_register(IntegerValue(g, 's2', default=10)) c2.update(100)
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 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 setUp(self): # clear out cache from previous runs keyedcache.cache_delete() g1 = ConfigurationGroup('m1', 'Multiple Group 1', ordering=1000) self.g1 = g1 self.g1c1 = config_register(MultipleStringValue(g1, 'c1', choices=((1, 'one'), (2, 'two'), (3, 'three'))))
def setUp(self): # clear out cache from previous runs keyedcache.cache_delete() g1 = ConfigurationGroup('m1', 'Multiple Group 1', ordering=1000) self.g1 = g1 self.g1c1 = config_register(MultipleStringValue(g1, 'c1', choices=((1,'one'),(2,'two'),(3,'three'))))
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 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') shp.update(False) return shp
def testOrderSuccess(self): """Test cert creation on order success""" cache_delete() order = make_test_order('US', '') order.order_success() certs = order.giftcertificates.all() self.assertEqual(len(certs), 1) c = certs[0] self.assertEqual(c.balance, Decimal('20.00')) self.assertEqual(c.recipient_email, '*****@*****.**') self.assertEqual(c.message, 'hello there')
def setUp(self): # clear out cache from previous runs keyedcache.cache_delete() choices1 = config_register(MultipleStringValue(BASE_GROUP, 'groupchoice', ordering=1)) choices2 = config_register(MultipleStringValue(BASE_GROUP, 'groupchoice2', ordering=1)) g1 = ConfigurationGroup('groupreq', 'Requirements 4', ordering=1000, requires=choices1) self.g1 = g1 self.g1c1 = config_register(IntegerValue(g1, 'c1', ordering=3)) self.g1c2 = config_register(IntegerValue(g1, 'c2', requires=choices2, requiresvalue='bar', ordering=4)) self.g1c3 = config_register(IntegerValue(g1, 'c3', ordering=5))
def setUp(self): keyedcache.cache_delete() tieruser = User.objects.create_user('timmy', '*****@*****.**', '12345') stduser = User.objects.create_user('tommy', '*****@*****.**', '12345') tieruser.save() stduser.save() self.tieruser = tieruser self.stduser = stduser tiergroup = Group(name="tiertest") tiergroup.save() tieruser.groups.add(tiergroup) tieruser.save() self.tier = PricingTier(group=tiergroup, title="Test Tier", discount_percent=Decimal('10.0')) self.tier.save()
def setUp(self): keyedcache.cache_delete() # remove users stored by previous requests into threadlocals set_thread_variable("request", None) tieruser = User.objects.create_user("timmy", "*****@*****.**", "12345") stduser = User.objects.create_user("tommy", "*****@*****.**", "12345") tieruser.save() stduser.save() self.tieruser = tieruser self.stduser = stduser tiergroup = Group(name="tiertest") tiergroup.save() tieruser.groups.add(tiergroup) tieruser.save() self.tier = PricingTier(group=tiergroup, title="Test Tier", discount_percent=Decimal("10.0")) self.tier.save()
def setUp(self): from django.contrib.auth.models import User from django.utils.datastructures import SortedDict # The following hack works like completely replaced ConfigurationSettings internal state only, if # no the same group name is used inside and outside the test. self.saved_conf_inst = ConfigurationSettings._ConfigurationSettings__instance.settings ConfigurationSettings.__dict__['_ConfigurationSettings__instance'].settings = SortedDict() keyedcache.cache_delete() # set new users and values user = User.objects.create_user('admin', '*****@*****.**', 'secret') user.is_superuser = True user.save() self.client.login(username='******', password='******') GROUP2 = ConfigurationGroup('Group2', 'g') value = IntegerValue(GROUP2, 'SingleItem') config_register(value)
def delete_cache(self): data = self.cleaned_data if data['kill_all'] == "Y": keyedcache.cache_delete() result = "Deleted all keys" elif data['tag']: keyedcache.cache_delete(data['tag'], children=data['children']) if data['children'] == "Y": result = "Deleted %s and children" % data['tag'] else: result = "Deleted %s" % data['tag'] else: result = "Nothing selected to delete" log.debug(result) return result
def setUp(self): # clear out cache from previous runs keyedcache.cache_delete() g1 = ConfigurationGroup('req1', 'Requirements 1', ordering=1000) self.g1 = g1 bool1 = config_register(BooleanValue(g1, 'bool1', default=False, ordering=1)) bool2 = config_register(BooleanValue(g1, 'bool2', ordering=2)) self.g1c1 = config_register(IntegerValue(g1, 'c1', requires=bool1, ordering=3)) self.g1c2 = config_register(IntegerValue(g1, 'c2', requires=bool2, ordering=4)) self.g1c3 = config_register(IntegerValue(g1, 'c3', ordering=5)) bool2.update(True)
def testDelete(self): keyedcache.cache_set('del', value=True) for x in range(0, 10): keyedcache.cache_set('del', 'x', x, value=True) for y in range(0, 5): keyedcache.cache_set('del', 'x', x, 'y', y, value=True) # check to make sure all the values are in the cache self.assertTrue(keyedcache.cache_get('del', default=False)) for x in range(0, 10): self.assertTrue(keyedcache.cache_get('del', 'x', x, default=False)) for y in range(0, 5): self.assertTrue( keyedcache.cache_get('del', 'x', x, 'y', y, default=False)) # try to delete just one killed = keyedcache.cache_delete('del', 'x', 1) self.assertEqual(["del::x::1"], killed) self.assertFalse(keyedcache.cache_get('del', 'x', 1, default=False)) # but the others are still there self.assertTrue(keyedcache.cache_get('del', 'x', 2, default=False)) # now kill all of del::x::1 killed = keyedcache.cache_delete('del', 'x', 1, children=True) for y in range(0, 5): self.assertFalse( keyedcache.cache_get('del', 'x', 1, 'y', y, default=False)) # but del::x::2 and children are there self.assertTrue( keyedcache.cache_get('del', 'x', 2, 'y', 1, default=False)) # kill the rest killed = keyedcache.cache_delete('del', children=True) self.assertFalse(keyedcache.cache_get('del', default=False)) for x in range(0, 10): self.assertFalse(keyedcache.cache_get('del', 'x', x, default=False)) for y in range(0, 5): self.assertFalse( keyedcache.cache_get('del', 'x', x, 'y', y, default=False))
def setUp(self): keyedcache.cache_delete() choices = config_register(MultipleStringValue(BASE_GROUP, 'collect', ordering=1)) self.choices = choices g1 = ConfigurationGroup('coll1', 'Collection 1') g2 = ConfigurationGroup('coll2', 'Collection 2') g3 = ConfigurationGroup('coll3', 'Collection 3') g1c1 = config_register(StringValue(g1, 'test')) g1c2 = config_register(StringValue(g1, 'test1')) g2c1 = config_register(StringValue(g2, 'test')) g3c1 = config_register(StringValue(g3, 'test')) g1c1.update('set a') g1c2.update('set b') g2c1.update('set a') g3c1.update('set d') choices.update(['coll1', 'coll3'])
def setUp(self): keyedcache.cache_delete() # remove users stored by previous requests into threadlocals set_thread_variable('request', None) tieruser = User.objects.create_user('timmy', '*****@*****.**', '12345') stduser = User.objects.create_user('tommy', '*****@*****.**', '12345') tieruser.save() stduser.save() self.tieruser = tieruser self.stduser = stduser tiergroup = Group(name="tiertest") tiergroup.save() tieruser.groups.add(tiergroup) tieruser.save() self.tier = PricingTier(group=tiergroup, title="Test Tier", discount_percent=Decimal('10.0')) self.tier.save()
def setUp(self): keyedcache.cache_delete() choices = config_register(MultipleStringValue(BASE_GROUP, 'collect', ordering=1)) self.choices = choices g1 = ConfigurationGroup('coll1', 'Collection 1') g2 = ConfigurationGroup('coll2', 'Collection 2') g3 = ConfigurationGroup('coll3', 'Collection 3') g1c1 = config_register(StringValue(g1, 'test')) g1c2 = config_register(StringValue(g1, 'test1')) g2c1 = config_register(StringValue(g2, 'test')) g3c1 = config_register(StringValue(g3, 'test')) g1c1.update('set a') g1c2.update('set b') g2c1.update('set a') g3c1.update('set d') choices.update(['coll1','coll3'])
def setUp(self): # clear out cache from previous runs keyedcache.cache_delete() djangosettings.LIVESETTINGS_OPTIONS = { 1 : { 'DB' : False, 'SETTINGS' : { 'overgroup' : { 's2' : '100', 'choices' : '["one","two","three"]' } } } } g = ConfigurationGroup('overgroup','Override Group') self.g = g config_register(StringValue(g, 's1')) config_register(IntegerValue(g, 's2', default=10)) config_register(IntegerValue(g, 's3', default=10)) config_register(MultipleStringValue(g, 'choices'))
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 setUp(self): # clear out cache from previous runs keyedcache.cache_delete() djangosettings.LIVESETTINGS_OPTIONS = { 1: { 'DB': False, 'SETTINGS': { 'overgroup': { 's2': '100', 'choices': '["one","two","three"]' } } } } g = ConfigurationGroup('overgroup', 'Override Group') self.g = g config_register(StringValue(g, 's1')) config_register(IntegerValue(g, 's2', default=10)) config_register(IntegerValue(g, 's3', default=10)) config_register(MultipleStringValue(g, 'choices'))
def testDelete(self): keyedcache.cache_set('del', value=True) for x in range(0, 10): keyedcache.cache_set('del', 'x', x, value=True) for y in range(0, 5): keyedcache.cache_set('del', 'x', x, 'y', y, value=True) # check to make sure all the values are in the cache self.assertTrue(keyedcache.cache_get('del', default=False)) for x in range(0, 10): self.assertTrue(keyedcache.cache_get('del', 'x', x, default=False)) for y in range(0, 5): self.assertTrue(keyedcache.cache_get('del', 'x', x, 'y', y, default=False)) # try to delete just one killed = keyedcache.cache_delete('del', 'x', 1) self.assertEqual(["del::x::1"], killed) self.assertFalse(keyedcache.cache_get('del', 'x', 1, default=False)) # but the others are still there self.assertTrue(keyedcache.cache_get('del', 'x', 2, default=False)) # now kill all of del::x::1 killed = keyedcache.cache_delete('del', 'x', 1, children=True) for y in range(0, 5): self.assertFalse(keyedcache.cache_get('del', 'x', 1, 'y', y, default=False)) # but del::x::2 and children are there self.assertTrue(keyedcache.cache_get('del', 'x', 2, 'y', 1, default=False)) # kill the rest killed = keyedcache.cache_delete('del', children=True) self.assertFalse(keyedcache.cache_get('del', default=False)) for x in range(0, 10): self.assertFalse(keyedcache.cache_get('del', 'x', x, default=False)) for y in range(0, 5): self.assertFalse(keyedcache.cache_get('del', 'x', x, 'y', y, default=False))
def testDelete(self): keyedcache.cache_set("del", value=True) for x in range(0, 10): keyedcache.cache_set("del", "x", x, value=True) for y in range(0, 5): keyedcache.cache_set("del", "x", x, "y", y, value=True) # check to make sure all the values are in the cache self.assert_(keyedcache.cache_get("del", default=False)) for x in range(0, 10): self.assert_(keyedcache.cache_get("del", "x", x, default=False)) for y in range(0, 5): self.assert_(keyedcache.cache_get("del", "x", x, "y", y, default=False)) # try to delete just one killed = keyedcache.cache_delete("del", "x", 1) self.assertEqual([keyedcache.CACHE_PREFIX + "::del::x::1"], killed) self.assertFalse(keyedcache.cache_get("del", "x", 1, default=False)) # but the others are still there self.assert_(keyedcache.cache_get("del", "x", 2, default=False)) # now kill all of del::x::1 killed = keyedcache.cache_delete("del", "x", 1, children=True) for y in range(0, 5): self.assertFalse(keyedcache.cache_get("del", "x", 1, "y", y, default=False)) # but del::x::2 and children are there self.assert_(keyedcache.cache_get("del", "x", 2, "y", 1, default=False)) # kill the rest killed = keyedcache.cache_delete("del", children=True) self.assertFalse(keyedcache.cache_get("del", default=False)) for x in range(0, 10): self.assertFalse(keyedcache.cache_get("del", "x", x, default=False)) for y in range(0, 5): self.assertFalse(keyedcache.cache_get("del", "x", x, "y", y, default=False))
def setUp(self): # clear out cache from previous runs keyedcache.cache_delete() g1 = ConfigurationGroup('group1', 'Group 1', ordering=-1001) g2 = ConfigurationGroup('group2', 'Group 2', ordering=-1002) g3 = ConfigurationGroup('group3', 'Group 3', ordering=-1003) self.g1 = g1 self.g2 = g2 self.g3 = g3 self.g1c1 = config_register(IntegerValue(g1, 'c1')) self.g1c2 = config_register(IntegerValue(g1, 'c2')) self.g1c3 = config_register(IntegerValue(g1, 'c3')) self.g2c1 = config_register(IntegerValue(g2, 'c1')) self.g2c2 = config_register(IntegerValue(g2, 'c2')) self.g2c3 = config_register(IntegerValue(g2, 'c3')) self.g3c1 = config_register(IntegerValue(g3, 'c1')) self.g3c2 = config_register(IntegerValue(g3, 'c2')) self.g3c3 = config_register(IntegerValue(g3, 'c3'))
def save(self, force_insert=False, force_update=False): keyedcache.cache_delete("Config", self.site.id) # ensure the default country is in shipping countries mycountry = self.country if mycountry: if not self.sales_country: log.debug("%s: No sales_country set, adding country of store, '%s'", self, mycountry) self.sales_country = mycountry # This code doesn't work when creating a new site. At the time of creation, all of the necessary relationships # aren't setup. I modified the load_store code so that it would create this relationship manually when running # with sample data. This is a bit of a django limitation so I'm leaving this in here for now. - CBM # salescountry = self.sales_country # try: # need = self.shipping_countries.get(pk=salescountry.pk) # except Country.DoesNotExist: # log.debug("%s: Adding default country '%s' to shipping countries", self, salescountry.iso2_code) # self.shipping_countries.add(salescountry) else: log.warn("%s: has no country set", self) super(Config, self).save(force_insert=force_insert, force_update=force_update) keyedcache.cache_set("Config", self.site.id, value=self)
def tearDown(self): keyedcache.cache_delete()
def tearDown(self): cache_delete()
def tearDown(self): cache_delete() rebuild_pricing()
def tearDown(self): cache_delete() settings.LANGUAGE_CODE = self.old_language_code
def setUp(self): keyedcache.cache_delete() wide = config_register( LongStringValue(BASE_GROUP, 'LONG', ordering=1, default="woot")) self.wide = wide self.wide.update('*' * 1000)