Coverage for /var/srv/projects/api.amasfac.comuna18.com/tmp/venv/lib/python3.9/site-packages/sendgrid/helpers/mail/content.py: 35%

30 statements  

« prev     ^ index     » next       coverage.py v6.4.4, created at 2023-07-17 14:22 -0600

1from .validators import ValidateApiKey 

2 

3 

4 

5class Content(object): 

6 """Content to be included in your email. 

7 

8 You must specify at least one mime type in the Contents of your email. 

9 """ 

10 

11 def __init__(self, mime_type, content): 

12 """Create a Content with the specified MIME type and content. 

13 

14 :param mime_type: MIME type of this Content (e.g. "text/plain"). 

15 :type mime_type: string 

16 :param content: The actual content. 

17 :type content: string 

18 """ 

19 self._mime_type = None 

20 self._content = None 

21 self._validator = ValidateApiKey() 

22 

23 if mime_type is not None: 

24 self.mime_type = mime_type 

25 

26 if content is not None: 

27 self.content = content 

28 

29 @property 

30 def mime_type(self): 

31 """The MIME type of the content you are including in your email. 

32 For example, "text/plain" or "text/html" or "text/x-amp-html". 

33 

34 :rtype: string 

35 """ 

36 return self._mime_type 

37 

38 @mime_type.setter 

39 def mime_type(self, value): 

40 """The MIME type of the content you are including in your email. 

41 For example, "text/plain" or "text/html" or "text/x-amp-html". 

42 

43 :param value: The MIME type of the content you are including in your 

44 email. 

45 For example, "text/plain" or "text/html" or "text/x-amp-html". 

46 :type value: string 

47 """ 

48 self._mime_type = value 

49 

50 @property 

51 def content(self): 

52 """The actual content (of the specified mime type). 

53 

54 :rtype: string 

55 """ 

56 return self._content 

57 

58 @content.setter 

59 def content(self, value): 

60 """The actual content (of the specified mime type). 

61 

62 :param value: The actual content (of the specified mime type). 

63 :type value: string 

64 """ 

65 self._validator.validate_message_dict(value) 

66 self._content = value 

67 

68 def get(self): 

69 """ 

70 Get a JSON-ready representation of this Content. 

71 

72 :returns: This Content, ready for use in a request body. 

73 :rtype: dict 

74 """ 

75 content = {} 

76 if self.mime_type is not None: 

77 content["type"] = self.mime_type 

78 

79 if self.content is not None: 

80 content["value"] = self.content 

81 return content