Exemplo n.º 1
0
    def check_event_row(self, ev):
        event_tds = self.selenium.find_elements_by_xpath(
            "//tr[@id='event_%s']/td" % ev.pk)
        sorted_jobs = ev.get_sorted_jobs()
        if sorted_jobs:
            num_boxes = len(
                sorted_jobs
            ) - 1  # each group will have a continuation box, except the last
            for group in sorted_jobs:
                num_boxes += len(group)
            num_boxes += 1  # this is the event description
            self.assertEqual(len(event_tds), num_boxes)

        depends = self.selenium.find_elements_by_xpath(
            '//td[@class="depends"]')
        for dep in depends:
            dep_html = dep.get_attribute('innerHTML')
            self.assertEqual(
                dep_html,
                '<span class="glyphicon glyphicon-arrow-right"></span>')

        ev_tr = self.selenium.find_element_by_id("event_%s" % ev.pk)
        self.assertIn(TimeUtils.sortable_time_str(ev.created),
                      ev_tr.get_attribute("data-date"))
        ev_status = self.check_class("event_status_%s" % ev.pk,
                                     "job_status_%s" % ev.status_slug())
        ev_html = ev_status.get_attribute('innerHTML')
        self.assertIn(str(ev.base.branch.repository.name), ev_html)
        if ev.pull_request:
            self.assertIn(escape(str(ev.pull_request)), ev_html)
        else:
            self.assertIn(str(ev.cause_str), ev_html)

        for job in ev.jobs.all():
            job_elem = self.check_class("job_%s" % job.pk,
                                        "job_status_%s" % job.status_slug())
            html = job_elem.get_attribute("innerHTML")
            self.assertIn(job.recipe.display_name, html)

            if job.invalidated:
                self.assertIn("Invalidated", html)
            else:
                self.assertNotIn("Invalidated", html)

            if job.failed_step:
                self.assertIn(job.failed_step, html)
Exemplo n.º 2
0
 def test_sortable_time_str(self):
     TimeUtils.sortable_time_str(datetime.datetime.now())
Exemplo n.º 3
0
def events_info(events, last_modified=None, events_url=False):
    """
    Creates the information required for displaying events.
    Input:
      events: An iterable of models.Event. Usually a query or just a list.
      last_modified: DateTime: If model.Event.last_modified is before this it won't be included
    Return:
      list of event info dicts
    """
    event_info = []
    for ev in events:
        if last_modified and ev.last_modified <= last_modified:
            continue

        repo_url = reverse("ci:view_repo", args=[ev.base.branch.repository.pk])
        event_url = reverse("ci:view_event", args=[ev.pk])
        repo_link = format_html('<a href="{}">{}</a>', repo_url,
                                ev.base.branch.repository.name)
        pr_url = ''
        pr_desc = ''
        if ev.pull_request:
            pr_url = reverse("ci:view_pr", args=[ev.pull_request.pk])
            pr_desc = clean_str_for_format(str(ev.pull_request))
            icon_link = format_html('<a href="{}"><i class="{}"></i></a>',
                                    ev.pull_request.url,
                                    ev.base.server().icon_class())
            if events_url:
                event_desc = format_html('{} {} <a href="{}">{}</a>',
                                         icon_link, repo_link, event_url,
                                         pr_desc)
            else:
                event_desc = format_html('{} {} <a href="{}">{}</a>',
                                         icon_link, repo_link, pr_url, pr_desc)
        else:
            event_desc = format_html('{} <a href="{}">{}', repo_link,
                                     event_url, ev.base.branch.name)
            if ev.description:
                event_desc = format_html('{} : {}', mark_safe(event_desc),
                                         clean_str_for_format(ev.description))
            event_desc += '</a>'

        info = {
            'id': ev.pk,
            'status': ev.status_slug(),
            'sort_time': TimeUtils.sortable_time_str(ev.created),
            'description': format_html(event_desc),
            'pr_id': 0,
            'pr_title': "",
            'pr_status': "",
            'pr_number': 0,
            'pr_url': "",
            'git_pr_url': "",
            'pr_username': "",
            'pr_name': "",
        }
        if ev.pull_request:
            info["pr_id"] = ev.pull_request.pk
            info["pr_title"] = ev.pull_request.title
            info["pr_status"] = ev.pull_request.status_slug()
            info["pr_number"] = ev.pull_request.number
            info["git_pr_url"] = ev.pull_request.url
            info["pr_url"] = pr_url
            info["pr_username"] = ev.pull_request.username
            info["pr_name"] = pr_desc

        job_info = []
        for job_group in ev.get_sorted_jobs():
            job_group_info = []
            for job in job_group:
                if int(job.seconds.total_seconds()) == 0:
                    job_seconds = ""
                else:
                    job_seconds = str(job.seconds)

                jurl = reverse("ci:view_job", args=[job.pk])

                jinfo = {
                    'id': job.pk,
                    'status': job.status_slug(),
                }
                job_desc = format_html('<a href="{}">{}</a>', jurl,
                                       format_html(job.unique_name()))
                if job_seconds:
                    job_desc += format_html('<br />{}', job_seconds)
                if job.failed_step:
                    job_desc += format_html('<br />{}', job.failed_step)
                if job.running_step:
                    job_desc += format_html('<br />{}', job.running_step)
                if job.invalidated:
                    job_desc += '<br />(Invalidated)'
                jinfo["description"] = job_desc
                job_group_info.append(jinfo)
            job_info.append(job_group_info)
        info['job_groups'] = job_info

        event_info.append(info)

    return event_info