def test_getPriceWithCurrency(self): # Given sut = Product(basePrice=1542.3, currency="€") # When result = sut.getPriceWithCurrency() # Then self.assertEqual("1542.30 €", result) # Given sut = Product(basePrice=20, currency="$") # When result = sut.getPriceWithCurrency() # Then self.assertEqual("20.00 $", result) # Given sut = Product(basePrice=20, currency=None) # When result = sut.getPriceWithCurrency() # Then self.assertEqual("20.00 [UNKNOWN CURRENCY]", result) # Given sut = Product(basePrice=None, currency="$") # When result = sut.getPriceWithCurrency() # Then self.assertEqual("unknown", result)
def _setProductPayload(self, msgConfig: MessageConfig, product: Product, shop: Shop): if not product: raise AttributeError(f"No 'product' given. Actual value: {product}") if not shop: raise AttributeError(f"No 'shop' given. Actual value: {shop}") fields = [] if product.basePrice: fields.append({"name": "Price", "value": product.getPriceWithCurrency()}) if product.sizes: sizeBlock = [f"{size.sizeEU}" for size in product.sizes if size.isInStock] if sizeBlock: fields.append({"name": "Sizes", "value": "\n".join(sizeBlock)}) self.setPayload(username=msgConfig.username, title=product.name, description=shop.name, link=product.url, thumbnailURL=product.urlThumb, footer="️Webtomator © 2020 dbyte solutions", fields=fields)