def test_aggregate_query(self): """Test for different aggregate function. """ test_product = Product(Name='test soap') test_product.save() test_product2 = Product(Name='test brush') test_product2.save() pricebook = Pricebook.objects.get(Name="Standard Price Book") PricebookEntry(Product2=test_product, Pricebook2=pricebook, UseStandardPrice=False, UnitPrice=Decimal(100)).save() PricebookEntry(Product2=test_product2, Pricebook2=pricebook, UseStandardPrice=False, UnitPrice=Decimal(80)).save() try: x_products = PricebookEntry.objects.filter( Name__startswith='test ') result = x_products.aggregate(Sum('UnitPrice'), Count('UnitPrice'), Avg('UnitPrice'), Min('UnitPrice')) self.assertDictEqual( result, { 'UnitPrice__sum': 180, 'UnitPrice__count': 2, 'UnitPrice__avg': 90.0, 'UnitPrice__min': 80 }) finally: # dependent PricebookEntries are just deleted automatically by SF test_product.delete() test_product2.delete()
def test_decimal_precision(self): """ Ensure that the precision on a DecimalField of a record saved to or retrieved from SalesForce is equal. """ product = Product(Name="Test Product") product.save() # The price for a product must be set in the standard price book. # http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_pricebookentry.htm pricebook = Pricebook.objects.get(Name="Standard Price Book") saved_pricebook_entry = PricebookEntry(Product2=product, Pricebook2=pricebook, UnitPrice=Decimal('1234.56'), UseStandardPrice=False) saved_pricebook_entry.save() retrieved_pricebook_entry = PricebookEntry.objects.get( pk=saved_pricebook_entry.pk) try: self.assertEqual(saved_pricebook_entry.UnitPrice, retrieved_pricebook_entry.UnitPrice) finally: retrieved_pricebook_entry.delete() product.delete()
def test_decimal_precision(self): """Verify the same precision of saved and retrived DecimalField """ product = Product(Name="Test Product") product.save() # The price for a product must be set in the standard price book. # http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_pricebookentry.htm pricebook = Pricebook.objects.get(Name="Standard Price Book") saved_pricebook_entry = PricebookEntry(Product2=product, Pricebook2=pricebook, UnitPrice=Decimal('1234.56'), UseStandardPrice=False) saved_pricebook_entry.save() retrieved_pricebook_entry = PricebookEntry.objects.get(pk=saved_pricebook_entry.pk) try: self.assertEqual(saved_pricebook_entry.UnitPrice, retrieved_pricebook_entry.UnitPrice) finally: retrieved_pricebook_entry.delete() product.delete()
def test_decimal_precision(self): """ Ensure that the precision on a DecimalField of a record saved to or retrieved from SalesForce is equal. """ product = Product(Name="Test Product") product.save() # The price for a product must be set in the standard price book. # http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_pricebookentry.htm pricebook = Pricebook.objects.get(Name="Standard Price Book") saved_pricebook_entry = PricebookEntry(Product2Id=product, Pricebook2Id=pricebook, UnitPrice=decimal.Decimal('1234.56'), UseStandardPrice=False) saved_pricebook_entry.save() retrieved_pricebook_entry = PricebookEntry.objects.get(pk=saved_pricebook_entry.pk) try: self.assertEqual(saved_pricebook_entry.UnitPrice, retrieved_pricebook_entry.UnitPrice) finally: retrieved_pricebook_entry.delete() product.delete()
def test_aggregate_query(self): """Test for different aggregate function. """ test_product = Product(Name='test soap') test_product.save() test_product2 = Product(Name='test brush') test_product2.save() pricebook = Pricebook.objects.get(Name="Standard Price Book") PricebookEntry(Product2=test_product, Pricebook2=pricebook, UseStandardPrice=False, UnitPrice=Decimal(100)).save() PricebookEntry(Product2=test_product2, Pricebook2=pricebook, UseStandardPrice=False, UnitPrice=Decimal(80)).save() try: x_products = PricebookEntry.objects.filter(Name__startswith='test ') result = x_products.aggregate(Sum('UnitPrice'), Count('UnitPrice'), Avg('UnitPrice'), Min('UnitPrice')) self.assertDictEqual(result, {'UnitPrice__sum': 180, 'UnitPrice__count': 2, 'UnitPrice__avg': 90.0, 'UnitPrice__min': 80}) finally: # dependent PricebookEntries are just deleted automatically by SF test_product.delete() test_product2.delete()