Пример #1
0
 def test_update_tasks_no_recipients(self, mock_diff_tasks, mock_send_mail):
     self.write_ubuntu_structure()
     self.config["PROJECT"] = "ubuntu"
     self.config["DIST"] = "raring"
     self.config["IMAGE_TYPE"] = "daily-live"
     output = GerminateOutput(self.config, self.temp_dir)
     os.makedirs(output.tasks_output_dir("ubuntu"))
     output.update_tasks("20130319")
     self.assertEqual(0, mock_send_mail.call_count)
     task_mail_path = os.path.join(self.temp_dir, "etc", "task-mail")
     touch(task_mail_path)
     output.update_tasks("20130319")
     self.assertEqual(0, mock_send_mail.call_count)
Пример #2
0
    def test_update_tasks_sends_mail(self, mock_send_mail):
        original_call = subprocess.call

        def call_side_effect(command, *args, **kwargs):
            if (len(command) >= 4 and command[:2] == ["diff", "-u"] and
                    "stdout" in kwargs):
                old = os.path.basename(command[2])
                new = os.path.basename(command[3])
                original_call(
                    ["printf", "%s\\n", "--- %s" % old], *args, **kwargs)
                original_call(
                    ["printf", "%s\\n", "+++ %s" % new], *args, **kwargs)
                return 1
            else:
                return original_call(command, *args, **kwargs)

        self.write_ubuntu_structure()
        self.config["PROJECT"] = "ubuntu"
        self.config["CAPPROJECT"] = "Ubuntu"
        self.config["DIST"] = "raring"
        self.config["IMAGE_TYPE"] = "daily-live"
        output_dir = os.path.join(
            self.temp_dir, "scratch", "ubuntu", "raring", "daily-live",
            "tasks")
        touch(os.path.join(output_dir, "required"))
        touch(os.path.join(output_dir, "minimal"))
        touch(os.path.join(output_dir, "standard"))
        touch(os.path.join("%s-previous" % output_dir, "minimal"))
        touch(os.path.join("%s-previous" % output_dir, "standard"))
        task_mail_path = os.path.join(self.temp_dir, "etc", "task-mail")
        with mkfile(task_mail_path) as task_mail:
            print("*****@*****.**", file=task_mail)
        mock_send_mail.side_effect = partial(
            self.send_mail_to_file, os.path.join(self.temp_dir, "mail"))
        output = GerminateOutput(self.config, self.temp_dir)
        with mock.patch("subprocess.call", side_effect=call_side_effect):
            output.update_tasks("20130319")
        with open(os.path.join(self.temp_dir, "mail")) as mail:
            self.assertEqual(dedent("""\
                To: [email protected]
                Subject: Task changes for Ubuntu daily-live/raring on 20130319
                X-Generated-By: update-tasks

                --- minimal
                +++ minimal
                --- standard
                +++ standard
                """), mail.read())
Пример #3
0
 def test_update_tasks_no_mail(self, mock_diff_tasks):
     self.write_ubuntu_structure()
     self.config["PROJECT"] = "ubuntu"
     self.config["DIST"] = "trusty"
     self.config["IMAGE_TYPE"] = "daily-live"
     output_dir = os.path.join(self.temp_dir, "scratch", "ubuntu", "trusty",
                               "daily-live", "tasks")
     touch(os.path.join(output_dir, "required"))
     touch(os.path.join(output_dir, "minimal"))
     output = GerminateOutput(self.config, self.temp_dir)
     output.update_tasks("20130319")
     self.assertCountEqual(["required", "minimal"],
                           os.listdir(
                               os.path.join(self.temp_dir, "debian-cd",
                                            "tasks", "auto", "daily-live",
                                            "ubuntu", "trusty")))
     self.assertCountEqual(["required", "minimal"],
                           os.listdir("%s-previous" % output_dir))