Created
November 25, 2021 19:22
-
-
Save thiagoferreiraw/63a71ff083ee3f924a229ebd9118094a to your computer and use it in GitHub Desktop.
united tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cairosvg | |
@mock.patch("cairosvg.svg2png", wraps=cairosvg.svg2png) | |
def test_create_png_from_svg_template(self, spy_svg2png): | |
with BytesIO() as output_file: | |
image.create_png_from_svg_template( | |
"utils/tests/svg_template.svg", | |
{"_WIDTH": 159, "_HEIGHT": 161, "_TEXT": "Hello World!"}, | |
output_file, | |
) | |
self.assertTrue(spy_svg2png.called) | |
generated_svg = spy_svg2png.call_args[0][0] | |
self.assertEqual( | |
generated_svg, | |
'<svg xmlns="http://www.w3.org/2000/svg" pointer-events="none" ' | |
' width="159" height="161"> <rect width="159" height="161"></rect> ' | |
' <text text-anchor="middle" y="50%" x="50%" dy="0.35em" ' | |
'pointer-events="auto" fill="#ffffff" font-family="{font-family}"> ' | |
"Hello World! </text>" | |
"</svg>", | |
) | |
@patch("cairosvg.svg2png", wraps=cairosvg.svg2png) | |
def test_create_promotional_image(self, spy_svg2png): | |
self.assertFalse(self.coupon.marketing_image) # initial state | |
create_promotional_image(self.coupon.id) | |
# Checking the image was created | |
self.coupon.refresh_from_db() | |
self.assertTrue(self.coupon.marketing_image) | |
self.assertIn( | |
f"coupons/{self.coupon.id}/marketing_image/", | |
self.coupon.marketing_image.url, | |
) | |
# Also checking we have the coupon code inside the svg: | |
generated_svg = spy_svg2png.call_args[0][0] | |
self.assertIn(self.coupon.code, generated_svg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment