Exemple #1
0
 def email(self, request, pk=None):
     """
     This method produces the body of email notification for the build.
     By default it uses the project settings for HTML and template.
     These settings can be overwritten by using GET parameters:
      * output - sets the output format (text/plan, text/html)
      * template - sets the template used (id of existing template or
                   "default" for default SQUAD templates)
     """
     output_format = request.query_params.get("output", "text/plain")
     template_id = request.query_params.get("template", None)
     template = None
     if template_id != "default":
         template = self.get_object().project.custom_email_template
     if template_id is not None:
         try:
             template = EmailTemplate.objects.get(pk=template_id)
         except EmailTemplate.DoesNotExist:
             pass
     status = self.get_object().status
     notification = Notification(status)
     produce_html = self.get_object().project.html_mail
     if output_format == "text/html":
         produce_html = True
     txt, html = notification.message(produce_html, template)
     if len(html) > 0:
         return HttpResponse(html, content_type=output_format)
     return HttpResponse(txt, content_type=output_format)
Exemple #2
0
def prepare_report(delayed_report_id):
    try:
        delayed_report = DelayedReport.objects.get(pk=delayed_report_id)
    except DelayedReport.DoesNotExist:
        logger.error("Cannot find report: %s" % delayed_report_id)
        return None

    build_object = delayed_report.build
    if not hasattr(build_object, "status"):
        delayed_report.status_code = status.HTTP_404_NOT_FOUND
        delayed_report.error_message = yaml.dump({
            "message":
            "Requested build status %s doesn't exist" % build_object.id
        })
        delayed_report.data_retention_days = 0
        delayed_report.save()
        return delayed_report

    pr_status = build_object.status
    notification = Notification(pr_status, delayed_report.baseline)
    produce_html = build_object.project.html_mail
    if delayed_report.output_format == "text/html":
        produce_html = True
    try:
        txt, html = notification.message(produce_html, delayed_report.template)
        delayed_report.output_text = txt
        delayed_report.output_html = html
        delayed_report.output_subject = notification.create_subject(
            delayed_report.template)
    except TemplateSyntaxError as e:
        data = {"lineno": e.lineno, "message": e.message}
        if delayed_report.template is not None:
            data.update({
                "txt": delayed_report.template.plain_text,
                "html": delayed_report.template.html
            })
        return update_delayed_report(delayed_report, data,
                                     status.HTTP_400_BAD_REQUEST)
    except TypeError as te:
        data = {"message": str(te)}
        if delayed_report.template is not None:
            data.update({
                "txt": delayed_report.template.plain_text,
                "html": delayed_report.template.html
            })
        return update_delayed_report(delayed_report, data,
                                     status.HTTP_400_BAD_REQUEST)

    delayed_report.status_code = status.HTTP_200_OK
    delayed_report.error_message = None
    delayed_report.save()
    if delayed_report.email_recipient:
        notify_delayed_report_email.delay(delayed_report.pk)
    if delayed_report.callback:
        notify_delayed_report_callback.delay(delayed_report.pk)
    return delayed_report
Exemple #3
0
def prepare_report(delayed_report_id):
    try:
        delayed_report = DelayedReport.objects.get(pk=delayed_report_id)
    except DelayedReport.DoesNotExist:
        logger.error("Cannot find report: %s" % delayed_report_id)
        return None

    build_object = delayed_report.build
    if not hasattr(build_object, "status"):
        delayed_report.status_code = status.HTTP_404_NOT_FOUND
        delayed_report.error_message = yaml.dump({"message": "Requested build status %s doesn't exist" % build_object.id})
        delayed_report.data_retention_days = 0
        delayed_report.save()
        return delayed_report

    pr_status = build_object.status
    notification = Notification(pr_status, delayed_report.baseline)
    produce_html = build_object.project.html_mail
    if delayed_report.output_format == "text/html":
        produce_html = True
    try:
        txt, html = notification.message(produce_html, delayed_report.template)
        delayed_report.output_text = txt
        delayed_report.output_html = html
        delayed_report.output_subject = notification.create_subject(delayed_report.template)
    except TemplateSyntaxError as e:
        data = {
            "lineno": e.lineno,
            "message": e.message
        }
        if delayed_report.template is not None:
            data.update({
                "txt": delayed_report.template.plain_text,
                "html": delayed_report.template.html
            })
        return update_delayed_report(delayed_report, data, status.HTTP_400_BAD_REQUEST)
    except TypeError as te:
        data = {"message": str(te)}
        if delayed_report.template is not None:
            data.update({
                "txt": delayed_report.template.plain_text,
                "html": delayed_report.template.html
            })
        return update_delayed_report(delayed_report, data, status.HTTP_400_BAD_REQUEST)

    delayed_report.status_code = status.HTTP_200_OK
    delayed_report.error_message = None
    delayed_report.save()
    if delayed_report.email_recipient:
        notify_delayed_report_email.delay(delayed_report.pk)
    if delayed_report.callback:
        notify_delayed_report_callback.delay(delayed_report.pk)
    return delayed_report
Exemple #4
0
 def email(self, request, pk=None):
     """
     This method produces the body of email notification for the build.
     By default it uses the project settings for HTML and template.
     These settings can be overwritten by using GET parameters:
      * output - sets the output format (text/plan, text/html)
      * template - sets the template used (id of existing template or
                   "default" for default SQUAD templates)
     """
     output_format = request.query_params.get("output", "text/plain")
     template_id = request.query_params.get("template", None)
     template = None
     if template_id != "default":
         template = self.get_object().project.custom_email_template
     if template_id is not None:
         try:
             template = EmailTemplate.objects.get(pk=template_id)
         except EmailTemplate.DoesNotExist:
             pass
     if hasattr(self.get_object(), "status"):
         pr_status = self.get_object().status
         notification = Notification(pr_status)
         produce_html = self.get_object().project.html_mail
         if output_format == "text/html":
             produce_html = True
         try:
             txt, html = notification.message(produce_html, template)
             if len(html) > 0:
                 return HttpResponse(html, content_type=output_format)
             return HttpResponse(txt, content_type=output_format)
         except TemplateSyntaxError as e:
             data = {"lineno": e.lineno, "message": e.message}
             if template is not None:
                 data.update({
                     "txt": template.plain_text,
                     "html": template.html
                 })
             return Response(data,
                             status=status.HTTP_500_INTERNAL_SERVER_ERROR)
         except TypeError as te:
             data = {"message": str(te)}
             if template is not None:
                 data.update({
                     "txt": template.plain_text,
                     "html": template.html
                 })
             return Response(data,
                             status=status.HTTP_500_INTERNAL_SERVER_ERROR)
     else:
         return Response({}, status=status.HTTP_404_NOT_FOUND)
Exemple #5
0
    def test_delegates_diff_to_test_comparison_object(self, diff):
        the_diff = {}
        diff.return_value = the_diff

        group = Group.objects.create(slug='mygroup')
        project = group.projects.create(slug='myproject')
        build1 = project.builds.create(version='1')
        build2 = project.builds.create(version='2')

        notification = Notification(build2, build1)

        self.assertIs(the_diff, notification.diff)