def test_tiered_superuser_bug(self): """Test that superuser does not get tiered price by mistake. #1282""" product = Product.objects.get(slug="PY-Rocks") self.tieruser.is_superuser = True self.tieruser.save() set_current_user(self.tieruser) self.assertEqual(product.unit_price, Decimal("19.50"))
def test_no_tier_user(self): """Check price when user doesn't have a tier""" product = Product.objects.get(slug='PY-Rocks') set_current_user(self.stduser) self.assertEqual(product.unit_price, Decimal("19.50")) # test that a negative answer is cached in threadlocals self.assertEqual(get_thread_variable('TIER_%i' % self.stduser.id), [])
def test_tiered_staffmember_bug(self): """Test that a staff member does not get tiered price by mistake. #1282""" product = Product.objects.get(slug='PY-Rocks') self.tieruser.is_staff = True self.tieruser.save() set_current_user(self.tieruser) self.assertEqual(product.unit_price, Decimal("19.50"))
def test_tieredprice_no_tier_user(self): """Test setting an explicit tieredprice on a product, but no tier for user""" product = Product.objects.get(slug='PY-Rocks') tp = TieredPrice(product=product, pricingtier=self.tier, quantity='1', price=Decimal('5.00')) tp.save() set_current_user(self.stduser) self.assertEqual(product.unit_price, Decimal("19.50"))
def test_tieredprice(self): """Test setting an explicit tieredprice on a product""" product = Product.objects.get(slug="PY-Rocks") tp = TieredPrice(product=product, pricingtier=self.tier, quantity="1", price=Decimal("10.00")) tp.save() set_current_user(self.tieruser) self.assertEqual(product.unit_price, Decimal("10.00"))
def test_no_tier_user(self): """Check price when user doesn't have a tier""" product = Product.objects.get(slug="PY-Rocks") set_current_user(self.stduser) self.assertEqual(product.unit_price, Decimal("19.50")) # test that a negative answer is cached in threadlocals self.assertEqual(get_thread_variable("TIER_%i" % self.stduser.id), [])
def _edit_post(author, postid, struct, publish): try: post = Post.objects.get(tag_uri=postid) if not post.blog.is_author(author): log.debug("Author '%s' cannot delete post: %s", author.user.username, postid) raise PermissionDeniedException() log.debug("Author '%s' editing post: %s", author.user.username, postid) post = mt_edit_post(struct, post) title = struct.get('title', None) if title is not None: post.headline = title excerpt = struct.get('description', None) if excerpt is not None: post.raw_excerpt = excerpt if publish: post.status = POST_PUBLISHED else: post.status = POST_DRAFT post.set_categories_by_name(struct.get('categories', [])) threadlocals.set_current_user(author.user) post.save() return True except Post.DoesNotExist: log.debug("Could not find post: %s", postid) raise ResourceNotFoundException()
def test_tieredprice(self): """Test setting an explicit tieredprice on a product""" product = Product.objects.get(slug='PY-Rocks') tp = TieredPrice(product=product, pricingtier=self.tier, quantity='1', price=Decimal('10.00')) tp.save() set_current_user(self.tieruser) # should be the new explicit price self.assertEqual(product.unit_price, Decimal("10.00"))
def test_tiered_user(self): """Test that a tiered user gets the tiered price""" product = Product.objects.get(slug='PY-Rocks') set_current_user(self.tieruser) # 10% discount from 19.50 # This test is failing when I run the full test suite but # it runs fine if I do python manage.py test tieredpricing # I suspect it's a threadlocals issue and a testing issue not that # anything is broken. CBM 2-22-2010 self.assertEqual(product.unit_price, Decimal("17.550"))
def test_multiple_pricing_tiers(self): """Test that a user belonging to more pricing tiers gets a tiered price, namely the lower of them. #1294""" tiergroup2 = Group(name="tiertest2") tiergroup2.save() self.tieruser.groups.add(tiergroup2) self.tieruser.save() self.tier = PricingTier(group=tiergroup2, title="Test Tier 2", discount_percent=Decimal("20.0")) self.tier.save() product = Product.objects.get(slug="PY-Rocks") set_current_user(self.tieruser) self.assertEqual(product.unit_price, Decimal("15.60"))
def test_tieredprice(self): """Test setting an explicit tieredprice on a product""" product = Product.objects.get(slug='PY-Rocks') tp = TieredPrice(product=product, pricingtier=self.tier, quantity='1', price=Decimal('10.00')) tp.save() set_current_user(self.tieruser) # should be the new explicit price # This test is failing when I run the full test suite but # it runs fine if I do python manage.py test tieredpricing # I suspect it's a threadlocals issue and a testing issue not that # anything is broken. CBM 2-22-2010 self.assertEqual(product.unit_price, Decimal("10.00"))
def test_multiple_pricing_tiers(self): """Test that a user belonging to more pricing tiers gets a tiered price, namely the lower of them. #1294""" tiergroup2 = Group(name="tiertest2") tiergroup2.save() self.tieruser.groups.add(tiergroup2) self.tieruser.save() self.tier = PricingTier(group=tiergroup2, title="Test Tier 2", discount_percent=Decimal('20.0')) self.tier.save() product = Product.objects.get(slug='PY-Rocks') set_current_user(self.tieruser) self.assertEqual(product.unit_price, Decimal("15.60"))
def test_tiered_user_dynamic_update(self): """ Test that adding a user to tiered group or removing him is reflected immediately (without waiting for server restart) """ product = Product.objects.get(slug="PY-Rocks") set_current_user(self.tieruser) _ = product.unit_price tiergroup = Group.objects.get(name="tiertest") self.tieruser.groups.remove(tiergroup) self.assertEqual(product.unit_price, Decimal("19.50")) self.tieruser.groups.add(tiergroup) self.assertEqual(product.unit_price, Decimal("17.550")) tiergroup.user_set.clear() self.assertEqual(product.unit_price, Decimal("19.50"))
def test_tiered_user_dynamic_update(self): """ Test that adding a user to tiered group or removing him is reflected immediately (without waiting for server restart) """ product = Product.objects.get(slug='PY-Rocks') set_current_user(self.tieruser) _ = product.unit_price tiergroup = Group.objects.get(name="tiertest") self.tieruser.groups.remove(tiergroup) self.assertEqual(product.unit_price, Decimal("19.50")) self.tieruser.groups.add(tiergroup) self.assertEqual(product.unit_price, Decimal("17.550")) tiergroup.user_set.clear() self.assertEqual(product.unit_price, Decimal("19.50"))
def _new_post(author, blogid, struct, publish): blog = Blog.objects.by_slug(blogid) if not blog: raise ResourceNotFoundException() if not blog.is_author(author): raise PermissionDeniedException() if publish: status = POST_PUBLISHED else: status = POST_DRAFT title = struct.get('title', None) if title is None: title = datetime.datetime.now().isoformat() rawdate = struct['dateCreated'] dt = date_from_iso8601(rawdate) post = Post(headline = title, create_date = dt, status = status, blog = blog, ) post = mt_edit_post(struct, post) excerpt = struct.get('description', None) if excerpt is not None: post.raw_excerpt = excerpt threadlocals.set_current_user(author.user) post.save() post.set_categories_by_name(struct.get('categories', [])) return post.tag_uri
def test_simple_tier(self): """Check quantity price for a standard product using the default price""" product = Product.objects.get(slug='PY-Rocks') set_current_user(None) self.assertEqual(product.unit_price, Decimal("19.50"))
def process_request(self, request): set_thread_variable('request', request) set_current_user(request.user)
def tearDown(self): set_current_user(self.original_user)
def process_response(self, request, response): set_thread_variable('request', None) set_current_user(None) return response
def test_tiered_user(self): """Test that a tiered user gets the tiered price""" product = Product.objects.get(slug='PY-Rocks') set_current_user(self.tieruser) self.assertEqual(product.unit_price, Decimal("17.550"))
def test_no_tier_user(self): """Check price when user doesn't have a tier""" product = Product.objects.get(slug='PY-Rocks') set_current_user(self.stduser) self.assertEqual(product.unit_price, Decimal("19.50"))
def setUp(self): self.original_user = get_current_user() self.user = User.objects.create(username='******') set_current_user(self.user) self.test_instance = TestCustomRelatedName.objects.create(name='foo')
def test_tiered_user(self): """Test that a tiered user gets the tiered price""" product = Product.objects.get(slug='PY-Rocks') set_current_user(self.tieruser) # 10% discount from 19.50 self.assertEqual(product.unit_price, Decimal("17.550"))
def __call__(self, request): set_thread_variable('request', request) set_current_user(request.user) return self.get_response(request)
def setUp(self): self.original_user = get_current_user() self.user = User.objects.create(username='******') set_current_user(self.user) self.test_instance = TestDefaultAuditedModel.objects.create(name='foo')