def testSkipsLineItemIfQuantityIsEmpty(self): context = MockContext(id="some ID", title="some title") priceList = PriceList() priceList.append(NamedPrice(Decimal('2.99'), u"price one")) addRequest = [{"id": u'price one', "quantity": ' '}] factory = shop.LineItemFactory(priceList, context, addRequest) lineItems = factory.create() self.assertEqual(0, len(lineItems), "Should return an empty list if quantity is empty!")
def testCastsToFloatsForCostWhenCreatingLineItem(self, IUUID): IUUID.expects_call() context = MockContext(id="some ID", title="some title") priceList = PriceList() priceList.append(NamedPrice(Decimal('2.99'), u"price one")) addRequest = [{"id": u'price one', "quantity": '2'}] factory = shop.LineItemFactory(priceList, context, addRequest) lineItems = factory.create() self.assertEqual(float(Decimal('2.99')), lineItems[0].cost)
def testCreatesSingleLineItem(self, IUUID): IUUID.expects_call() context = MockContext(id="some ID", title="some title") priceList = PriceList() priceList.append(NamedPrice(Decimal('2.99'), u"price one")) addRequest = [{"id": u'price one', "quantity": '2'}] factory = shop.LineItemFactory(priceList, context, addRequest) lineItems = factory.create() self.assertEqual(1, len(lineItems), "Should return a list with one LineItem!") self.assertEqual(2, lineItems[0].quantity) self.assertEqual("some ID-price one", lineItems[0].item_id)
def testCreatesMultipleLineItems(self, IUUID): IUUID.expects_call() context = MockContext(id="some ID", title="some title") priceList = PriceList() priceList.extend([ NamedPrice(Decimal('2.99'), u"price one"), NamedPrice(Decimal('3.99'), u"price two") ]) addRequest = [{ "id": u'price one', "quantity": '2' }, { "id": u'price two', "quantity": '3' }] factory = shop.LineItemFactory(priceList, context, addRequest) lineItems = factory.create() self.assertEqual(2, len(lineItems), "Should return a list with two LineItems!") self.assertEqual(2, lineItems[0].quantity) self.assertEqual("some ID-price one", lineItems[0].item_id) self.assertEqual(3, lineItems[1].quantity) self.assertEqual("some ID-price two", lineItems[1].item_id)