test_message_mime()   C
last analyzed

Complexity

Conditions 8

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 8
c 1
b 0
f 0
dl 0
loc 12
rs 6.6666
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
4
"""Tests for `email_to` package."""
5
6
import pytest
0 ignored issues
show
introduced by
Unable to import 'pytest'
Loading history...
7
8
9
import email_to
10
11
12
@pytest.fixture
13
def message():
14
    """ Simple message """
15
    msg = email_to.Message('# A Test Message', style='h1 { color: blue }')
16
    msg.add('This message is only a test of the alert system')
17
    return msg
18
19
20
def test_build_message(message):
0 ignored issues
show
Comprehensibility Bug introduced by
message is re-defining a name which is already available in the outer-scope (previously defined on line 13).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
21
    """ Test that a message can be created and added to directly """
22
    msg = message
23
24
    msg_string = str(msg)
25
    assert '# A Test Message' in msg_string
26
    assert 'This message is only a test of the alert system' in msg_string
27
28
    msg_html = msg.html
29
    assert '<html>' in msg_html
30
    assert '<head></head>' in msg_html
31
    assert '<body>' in msg_html
32
    assert 'style="color:blue">' in msg_html
33
    assert 'A Test Message' in msg_html
34
    assert '<p>This message is only a test of the alert system' in msg_html
35
36
37
def test_empty_message():
38
    """ Test that a message passed an empty body gets created """
39
    msg = email_to.Message()
40
    msg_string = str(msg)
41
    assert msg_string == ''
42
43
    msg_html = msg.html
0 ignored issues
show
Unused Code introduced by
The variable msg_html seems to be unused.
Loading history...
44
    assert msg.html == ''
45
46
47
def test_message_mime(message):
0 ignored issues
show
Comprehensibility Bug introduced by
message is re-defining a name which is already available in the outer-scope (previously defined on line 13).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
48
    """ Test that a message can form a valid MIMEMultiPart object """
49
    mime = message.mime()
50
    mime_string = str(mime)
51
    assert 'Content-Type' in mime_string
52
    assert 'multipart/alternative' in mime_string
53
    #assert 'From' in mime_string
54
    assert 'MIME-Version:' in mime_string
55
    assert 'Content-Type: text/plain; charset="us-ascii"' in mime_string
56
    assert '# A Test Message' in mime_string
57
    assert 'Content-Type: text/html; charset="us-ascii"' in mime_string
58
    assert '<h1 style="color:blue">A Test Message</h1>' in mime_string
59