def render_image_background(email: EmailStr, content_loss: float, style_loss: float, total_variation_loss: float, content_img: np.ndarray, style_img: np.ndarray) -> None: """ background method to apply style transfer and send by email Args: email (EmailStr): receiver email content_loss (float): the content loss weight for style transfer model style_loss (float): the style loss weight for style transfer model total_variation_loss (float): the total variation loss weight for content_img (np.ndarray): content image style_img (np.ndarray): style image """ # apply style transfer model result: Image = style_transfer.render_image(content_img, style_img, content_layer, style_layers, style_loss, content_loss, total_variation_loss, epochs_without_variation, epochs_with_variation, steps_per_epoch) # send image by email msg = ('Thanks for using HStyle!\nwe added the Rendered Image' ', We hope u are satisfied from our service') mail_service.send_image_by_email(result, msg, email)
def test_send_image_by_email_mimetext_constructor( mock_mimetext: mock.MagicMock, _) -> None: """ Test method of mail service Args: mock_mimetext (mock.MagicMock): mock """ # Arrange img: Image = Image.new('RGB', (60, 30), color = 'red') text: str = 'test' email: str = '*****@*****.**' # Act mail_service.send_image_by_email(img, text, email) # Assert assert mock_mimetext.call_args is None
def test_send_image_by_email_smtp_constructor( mock_smtp: mock.MagicMock) -> None: """ Test method of mail service Args: mock_smtp (mock.MagicMock): mock """ # Arrange img: Image = Image.new('RGB', (60, 30), color = 'red') text: str = 'test' email: str = '*****@*****.**' # Act mail_service.send_image_by_email(img, text, email) # Assert assert mock_smtp.call_args == (('smtp.gmail.com', 587),)
def test_send_image_by_email_called_login( mock_smtp: mock.MagicMock) -> None: """ Test method of mail service Args: mock_smtp (mock.MagicMock): mock """ # Arrange img: Image = Image.new('RGB', (60, 30), color = 'red') text: str = 'test' email: str = '*****@*****.**' # Act mail_service.send_image_by_email(img, text, email) # Assert name, args, kwargs = mock_smtp.method_calls.pop(1) assert name == '().login' assert args == ('*****@*****.**', 'HStyle1234') assert kwargs == {}
def test_send_image_by_email_called_sendmail( mock_smtp: mock.MagicMock) -> None: """ Test method of mail service Args: mock_smtp (mock.MagicMock): mock """ # Arrange img: Image = Image.new('RGB', (60, 30), color = 'red') text: str = 'test' email: str = '*****@*****.**' # Act mail_service.send_image_by_email(img, text, email) # Assert name, args, kwargs = mock_smtp.method_calls.pop(2) assert name == '().sendmail' assert args[0] == 'HStyle Service' assert args[1] == '*****@*****.**' assert kwargs == {}