~xubuntu-dev/ubuntu-cdimage/xubuntu-base

« back to all changes in this revision

Viewing changes to lib/cdimage/tests/test_mail.py

  • Committer: Stéphane Graber
  • Date: 2015-06-17 21:02:28 UTC
  • Revision ID: stgraber@ubuntu.com-20150617210228-sv2eqrdchhje4zjw
And when we thought we were done...

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
    get_notify_addresses,
36
36
    send_mail,
37
37
)
38
 
from cdimage.tests.helpers import TestCase, touch
 
38
from cdimage.tests.helpers import TestCase, mkfile, touch
39
39
 
40
40
 
41
41
class TestNotify(TestCase):
48
48
        self.assertIsNone(_notify_addresses_path(self.config))
49
49
 
50
50
        path = os.path.join(self.temp_dir, "etc", "notify-addresses")
51
 
        os.makedirs(os.path.dirname(path))
52
51
        touch(path)
53
52
        self.assertEqual(path, _notify_addresses_path(self.config))
54
53
 
55
54
        path = os.path.join(self.temp_dir, "production", "notify-addresses")
56
 
        os.makedirs(os.path.dirname(path))
57
55
        touch(path)
58
56
        self.assertEqual(path, _notify_addresses_path(self.config))
59
57
 
62
60
 
63
61
    def test_get_notify_addresses_all_matches_any_project(self):
64
62
        path = os.path.join(self.temp_dir, "production", "notify-addresses")
65
 
        os.makedirs(os.path.dirname(path))
66
 
        with open(path, "w") as f:
 
63
        with mkfile(path) as f:
67
64
            print("ALL\tfoo@example.org bar@example.org", file=f)
68
65
        self.assertEqual(
69
66
            ["foo@example.org", "bar@example.org"],
77
74
 
78
75
    def test_get_notify_addresses_projects_match_exactly(self):
79
76
        path = os.path.join(self.temp_dir, "production", "notify-addresses")
80
 
        os.makedirs(os.path.dirname(path))
81
 
        with open(path, "w") as f:
 
77
        with mkfile(path) as f:
82
78
            print("ubuntu\tubuntu@example.org", file=f)
83
79
            print("kubuntu\tkubuntu@example.org", file=f)
84
80
        self.assertEqual(
91
87
 
92
88
    def test_send_mail_dry_run_from_file(self):
93
89
        path = os.path.join(self.temp_dir, "body")
94
 
        with open(path, "w") as body:
 
90
        with mkfile(path) as body:
95
91
            print("Body", file=body)
96
92
            print("Text", file=body)
97
93
        self.capture_logging()
130
126
    @mock.patch("subprocess.Popen")
131
127
    def test_send_mail_from_file(self, mock_popen):
132
128
        path = os.path.join(self.temp_dir, "body")
133
 
        with open(path, "w") as body:
 
129
        with mkfile(path) as body:
134
130
            print("Body", file=body)
135
131
            print("Text", file=body)
136
132
        with open(path) as body: