def message(self, request_id, testrun_uuid, sw_product, result, result_files, exception, tested_packages, source_uris, notify_list, email_attachments, build_url): """ @type request_id: C{str} @param request_id: An identifier for the request from the client @type testrun_uuid: C{str} @param testrun_uuid: The unique identifier for the testrun @type sw_product: C{str} @param sw_product: Name of the sw product this testrun belongs to @type result: C{str} @param result: The testrun result @type result_files: C{list} of C{ots.common.dto.results} @param result_files: The Result files @type exception: C{Exception} @param exception: The Exception @type tested_packages: C{ots.common.dto.packages} @param tested_packages: The Test Packages that were run @type source_uris: C{dict} of C{str} : C{str} @param source_uris: Uris of other reporting tools @type notify_list: C{list} @param notify_list: The email notify list @type email_attachments: C{bool} @param email_attachments: Is the email attachment switched on? @type build_url: C{str} @param build_url: The build url @rtype: C{MIMEMultipart} @return: Mail message """ msg = MIMEMultipart() msg["Subject"] = self._subject(request_id, sw_product, result) msg["From"] = self.from_address msg["To"] = ", ".join(notify_list) msg.attach(MIMEText(self._body(request_id, testrun_uuid, sw_product, result, exception, tested_packages, source_uris, build_url))) if result_files and email_attachments: try: attach = attachment(testrun_uuid, result_files) msg.attach(attach) except: LOG.warning("Error creating email attachement:", exc_info = True) return msg
def test_attachment(self): results_1 = Results("foo", "<foo>foo</foo>", environment="foo") results_2 = Results("bar", "<bar>bar</bar>", environment="bar") results_list = [results_1, results_2] a = attachment(111111, results_list) self.assertEquals("OTS_testrun_111111.zip", a.get_filename()) tmp_filename = mktemp() pl = a.get_payload(decode=True) f = open(tmp_filename, "wb") f.write(pl) f.close() z = ZipFile(tmp_filename) self.assertEquals(2, len(z.infolist()))
def test_attachment(self): results_1 = Results("foo", "<foo>foo</foo>", environment = "foo") results_2 = Results("bar", "<bar>bar</bar>", environment = "bar") results_list = [results_1, results_2] a = attachment(111111, results_list) self.assertEquals("OTS_testrun_111111.zip", a.get_filename()) tmp_filename = mktemp() pl = a.get_payload(decode = True) f = open(tmp_filename, "wb") f.write(pl) f.close() z = ZipFile(tmp_filename) self.assertEquals(2, len(z.infolist()))