示例#1
0
def suite_csv_stream(request, job, pk):
    """
    Django is designed for short-lived requests.
    Streaming responses will tie a worker process for the entire duration of the response.
    This may result in poor performance.
    Generally speaking, you should perform expensive tasks outside of the
    request-response cycle, rather than resorting to a streamed response.
    https://docs.djangoproject.com/en/1.8/ref/request-response/#django.http.StreamingHttpResponse
    https://docs.djangoproject.com/en/1.8/howto/outputting-csv/
    """
    job = get_object_or_404(TestJob, pk=job)
    test_suite = get_object_or_404(TestSuite, name=pk, job=job)
    check_request_auth(request, job)
    querydict = request.GET
    offset = querydict.get('offset', default=None)
    limit = querydict.get('limit', default=None)

    pseudo_buffer = StreamEcho()
    writer = csv.writer(pseudo_buffer)
    testcases = get_testcases_with_limit(test_suite, limit, offset)
    response = StreamingHttpResponse(
        (writer.writerow(export_testcase(row)) for row in testcases),
        content_type="text/csv")
    filename = "lava_stream_%s.csv" % test_suite.name
    response['Content-Disposition'] = 'attachment; filename="%s"' % filename
    return response
示例#2
0
def suite_csv_stream(request, job, pk):
    """
    Django is designed for short-lived requests.
    Streaming responses will tie a worker process for the entire duration of the response.
    This may result in poor performance.
    Generally speaking, you should perform expensive tasks outside of the
    request-response cycle, rather than resorting to a streamed response.
    https://docs.djangoproject.com/en/1.8/ref/request-response/#django.http.StreamingHttpResponse
    https://docs.djangoproject.com/en/1.8/howto/outputting-csv/
    """
    job = get_object_or_404(TestJob, pk=job)
    test_suite = get_object_or_404(TestSuite, name=pk, job=job)
    check_request_auth(request, job)
    querydict = request.GET
    offset = querydict.get('offset', default=None)
    limit = querydict.get('limit', default=None)

    pseudo_buffer = StreamEcho()
    writer = csv.writer(pseudo_buffer)
    testcases = get_testcases_with_limit(test_suite, limit, offset)
    response = StreamingHttpResponse(
        (writer.writerow(export_testcase(row)) for row in testcases),
        content_type="text/csv")
    filename = "lava_stream_%s.csv" % test_suite.name
    response['Content-Disposition'] = 'attachment; filename="%s"' % filename
    return response
示例#3
0
def testcase_yaml(request, pk):
    testcase = get_object_or_404(TestCase, pk=pk)
    check_request_auth(request, testcase.suite.job)
    response = HttpResponse(content_type='text/yaml')
    filename = "lava_%s.yaml" % testcase.name
    response['Content-Disposition'] = 'attachment; filename="%s"' % filename
    yaml.dump(export_testcase(testcase, with_buglinks=True), response,
              Dumper=yaml.CDumper)
    return response
示例#4
0
文件: api.py 项目: Linaro/lava-server
    def get_testcase_results_csv(self, job_id, suite_name, case_name):
        """
        Name
        ----
        `get_testcase_results_csv` (`job_id`, `suite_name`, `case_name`)

        Description
        -----------
        Get the test case results of given job id, suite and test case name
        in CSV format.

        Arguments
        ---------
        `job_id`: string
            Job id for which the results are required.
        `suite_name`: string
            Name of the suite for which the results are required.
        `case_name`: string
            Name of the test case for which the results are required.

        Return value
        ------------
        This function returns an XML-RPC structures of test case results in
        CSV format, provided the user is authenticated with an username and
        token.
        """

        self._authenticate()
        if not job_id:
            raise xmlrpclib.Fault(400, "Bad request: TestJob id was not "
                                  "specified.")
        try:
            job = TestJob.get_by_job_number(job_id)
            if not job.can_view(self.user):
                raise xmlrpclib.Fault(
                    401, "Permission denied for user to job %s" % job_id)

            output = io.BytesIO()
            writer = csv.DictWriter(
                output,
                quoting=csv.QUOTE_ALL,
                extrasaction='ignore',
                fieldnames=testcase_export_fields())
            writer.writeheader()
            test_suite = job.testsuite_set.get(name=suite_name)
            test_case = test_suite.testcase_set.get(name=case_name)
            writer.writerow(export_testcase(test_case))

        except TestJob.DoesNotExist:
            raise xmlrpclib.Fault(404, "Specified job not found.")
        except TestSuite.DoesNotExist:
            raise xmlrpclib.Fault(404, "Specified test suite not found.")
        except TestCase.DoesNotExist:
            raise xmlrpclib.Fault(404, "Specified test case not found.")

        return output.getvalue()
示例#5
0
    def get_testcase_results_csv(self, job_id, suite_name, case_name):
        """
        Name
        ----
        `get_testcase_results_csv` (`job_id`, `suite_name`, `case_name`)

        Description
        -----------
        Get the test case results of given job id, suite and test case name
        in CSV format.

        Arguments
        ---------
        `job_id`: string
            Job id for which the results are required.
        `suite_name`: string
            Name of the suite for which the results are required.
        `case_name`: string
            Name of the test case for which the results are required.

        Return value
        ------------
        This function returns an XML-RPC structures of test case results in
        CSV format, provided the user is authenticated with an username and
        token.
        """

        self._authenticate()
        if not job_id:
            raise xmlrpclib.Fault(
                400, "Bad request: TestJob id was not "
                "specified.")
        try:
            job = TestJob.get_by_job_number(job_id)
            if not job.can_view(self.user):
                raise xmlrpclib.Fault(
                    401, "Permission denied for user to job %s" % job_id)

            output = io.BytesIO()
            writer = csv.DictWriter(output,
                                    quoting=csv.QUOTE_ALL,
                                    extrasaction='ignore',
                                    fieldnames=testcase_export_fields())
            writer.writeheader()
            test_suite = job.testsuite_set.get(name=suite_name)
            test_case = test_suite.testcase_set.get(name=case_name)
            writer.writerow(export_testcase(test_case))

        except TestJob.DoesNotExist:
            raise xmlrpclib.Fault(404, "Specified job not found.")
        except TestSuite.DoesNotExist:
            raise xmlrpclib.Fault(404, "Specified test suite not found.")
        except TestCase.DoesNotExist:
            raise xmlrpclib.Fault(404, "Specified test case not found.")

        return output.getvalue()
示例#6
0
def testcase_yaml(request, pk):
    testcase = get_object_or_404(TestCase, pk=pk)
    check_request_auth(request, testcase.suite.job)
    response = HttpResponse(content_type='text/yaml')
    filename = "lava_%s.yaml" % testcase.name
    response['Content-Disposition'] = 'attachment; filename="%s"' % filename
    yaml.dump(export_testcase(testcase, with_buglinks=True),
              response,
              Dumper=yaml.CDumper)
    return response
示例#7
0
    def testjob_stream(suites, pseudo_buffer):
        fieldnames = testcase_export_fields()
        writer = csv.DictWriter(pseudo_buffer, fieldnames=fieldnames)
        # writer.writeheader does not return the string while writer.writerow
        # does. Copy writeheader code from csv.py and yield the value.
        yield writer.writerow(dict(zip(fieldnames, fieldnames)))

        for test_suite in suites:
            for test_case in test_suite.testcase_set.all():
                yield writer.writerow(export_testcase(test_case))
示例#8
0
def suite_yaml(request, job, pk):
    job = get_object_or_404(TestJob, pk=job)
    test_suite = get_object_or_404(TestSuite, name=pk, job=job)
    response = HttpResponse(content_type='text/yaml')
    filename = "lava_%s.yaml" % test_suite.name
    response['Content-Disposition'] = 'attachment; filename="%s"' % filename
    yaml_list = []
    for test_case in test_suite.test_cases.all():
        yaml_list.append(export_testcase(test_case))
    yaml.dump(yaml_list, response)
    return response
示例#9
0
def testjob_csv(request, job):
    job = get_object_or_404(TestJob, pk=job)
    response = HttpResponse(content_type="text/csv")
    filename = "lava_%s.csv" % job.id
    response["Content-Disposition"] = 'attachment; filename="%s"' % filename
    writer = csv.DictWriter(response, quoting=csv.QUOTE_ALL, extrasaction="ignore", fieldnames=testcase_export_fields())
    writer.writeheader()
    for test_suite in job.test_suites.all():
        for row in test_suite.test_cases.all():
            writer.writerow(export_testcase(row))
    return response
示例#10
0
def testjob_yaml(request, job):
    job = get_object_or_404(TestJob, pk=job)
    response = HttpResponse(content_type="text/yaml")
    filename = "lava_%s.yaml" % job.id
    response["Content-Disposition"] = 'attachment; filename="%s"' % filename
    yaml_list = []
    for test_suite in job.test_suites.all():
        for test_case in test_suite.test_cases.all():
            yaml_list.append(export_testcase(test_case))
    yaml.dump(yaml_list, response)
    return response
示例#11
0
    def testjob_stream(suites, pseudo_buffer):
        fieldnames = testcase_export_fields()
        writer = csv.DictWriter(pseudo_buffer,
                                fieldnames=fieldnames)
        # writer.writeheader does not return the string while writer.writerow
        # does. Copy writeheader code from csv.py and yield the value.
        yield writer.writerow(dict(zip(fieldnames, fieldnames)))

        for test_suite in suites:
            for test_case in test_suite.testcase_set.all():
                yield writer.writerow(export_testcase(test_case))
示例#12
0
def suite_yaml(request, job, pk):
    job = get_object_or_404(TestJob, pk=job)
    test_suite = get_object_or_404(TestSuite, name=pk, job=job)
    response = HttpResponse(content_type='text/yaml')
    filename = "lava_%s.yaml" % test_suite.name
    response['Content-Disposition'] = 'attachment; filename="%s"' % filename
    yaml_list = []
    for test_case in test_suite.test_cases.all():
        yaml_list.append(export_testcase(test_case))
    yaml.dump(yaml_list, response)
    return response
示例#13
0
 def test_export(self):
     user = self.factory.make_user()
     job = TestJob.from_yaml_and_user(self.factory.make_job_yaml(), user)
     test_suite = TestSuite.objects.get_or_create(name='lava', job=job)[0]
     test_case = TestCase(name='name',
                          suite=test_suite,
                          result=TestCase.RESULT_FAIL)
     self.assertTrue(
         any(
             map(lambda v: v in testcase_export_fields(),
                 export_testcase(test_case).keys())))
示例#14
0
def testjob_yaml(request, job):
    job = get_object_or_404(TestJob, pk=job)
    check_request_auth(request, job)
    response = HttpResponse(content_type='text/yaml')
    filename = "lava_%s.yaml" % job.id
    response['Content-Disposition'] = 'attachment; filename="%s"' % filename
    yaml_list = []
    for test_suite in job.testsuite_set.all():
        for test_case in test_suite.testcase_set.all():
            yaml_list.append(export_testcase(test_case))
    yaml.dump(yaml_list, response)
    return response
示例#15
0
def suite_csv(request, job, pk):
    job = get_object_or_404(TestJob, pk=job)
    test_suite = get_object_or_404(TestSuite, name=pk, job=job)
    response = HttpResponse(content_type='text/csv')
    filename = "lava_%s.csv" % test_suite.name
    response['Content-Disposition'] = 'attachment; filename="%s"' % filename
    writer = csv.DictWriter(response,
                            quoting=csv.QUOTE_ALL,
                            extrasaction='ignore',
                            fieldnames=testcase_export_fields())
    writer.writeheader()
    for row in test_suite.test_cases.all():
        writer.writerow(export_testcase(row))
    return response
示例#16
0
 def test_export(self):
     job = TestJob.from_yaml_and_user(
         self.factory.make_job_yaml(), self.user)
     test_suite = TestSuite.objects.get_or_create(name='lava', job=job)[0]
     test_case = TestCase(
         name='name',
         suite=test_suite,
         result=TestCase.RESULT_FAIL
     )
     self.assertTrue(
         any(
             map(lambda v: v in testcase_export_fields(), export_testcase(test_case).keys())
         )
     )
示例#17
0
    def get_testsuite_results_yaml(self, job_id, suite_name, limit=None,
                                   offset=None):
        """
        Name
        ----
        `get_testsuite_results_yaml` (`job_id`, `suite_name`, `limit=None`, `offset=None`)

        Description
        -----------
        Get the suite results of given job id and suite name in YAML format.

        Arguments
        ---------
        `job_id`: string
            Job id for which the results are required.
        `suite_name`: string
            Name of the suite for which the results are required.
        `limit`: int
            Limit the number of test cases fetched.
        `offset`: int
            Start fetching test cases from a specific point.

        Return value
        ------------
        This function returns an XML-RPC structures of suite results in YAML
        format, provided the user is authenticated with an username and token.
        """

        self._authenticate()
        if not job_id:
            raise xmlrpclib.Fault(400, "Bad request: TestJob id was not "
                                  "specified.")
        try:
            job = TestJob.get_by_job_number(job_id)
            if not job.can_view(self.user):
                raise xmlrpclib.Fault(
                    401, "Permission denied for user to job %s" % job_id)
            yaml_list = []
            test_suite = job.testsuite_set.get(name=suite_name)
            for test_case in get_testcases_with_limit(test_suite,
                                                      limit, offset):
                yaml_list.append(export_testcase(test_case))

        except TestJob.DoesNotExist:
            raise xmlrpclib.Fault(404, "Specified job not found.")
        except TestSuite.DoesNotExist:
            raise xmlrpclib.Fault(404, "Specified test suite not found.")

        return yaml.dump(yaml_list)
示例#18
0
    def get_testcase_results_yaml(self, job_id, suite_name, case_name):
        """
        Name
        ----
        `get_testcase_results_yaml` (`job_id`, `suite_name`, `case_name`)

        Description
        -----------
        Get the test case results of given job id, suite and test case name
        in YAML format.

        Arguments
        ---------
        `job_id`: string
            Job id for which the results are required.
        `suite_name`: string
            Name of the suite for which the results are required.
        `case_name`: string
            Name of the test case for which the results are required.

        Return value
        ------------
        This function returns an XML-RPC structures of test case results in
        YAML format, provided the user is authenticated with an username and
        token.
        """

        self._authenticate()
        if not job_id:
            raise xmlrpclib.Fault(
                400, "Bad request: TestJob id was not "
                "specified.")
        try:
            job = TestJob.get_by_job_number(job_id)
            if not job.can_view(self.user):
                raise xmlrpclib.Fault(
                    401, "Permission denied for user to job %s" % job_id)
            test_suite = job.testsuite_set.get(name=suite_name)
            test_case = test_suite.testcase_set.get(name=case_name)
            yaml_list = [export_testcase(test_case)]

        except TestJob.DoesNotExist:
            raise xmlrpclib.Fault(404, "Specified job not found.")
        except TestSuite.DoesNotExist:
            raise xmlrpclib.Fault(404, "Specified test suite not found.")
        except TestCase.DoesNotExist:
            raise xmlrpclib.Fault(404, "Specified test case not found.")

        return yaml.dump(yaml_list)
示例#19
0
def testjob_csv(request, job):
    job = get_object_or_404(TestJob, pk=job)
    check_request_auth(request, job)
    response = HttpResponse(content_type='text/csv')
    filename = "lava_%s.csv" % job.id
    response['Content-Disposition'] = 'attachment; filename="%s"' % filename
    writer = csv.DictWriter(response,
                            quoting=csv.QUOTE_ALL,
                            extrasaction='ignore',
                            fieldnames=testcase_export_fields())
    writer.writeheader()
    for test_suite in job.testsuite_set.all():
        for row in test_suite.testcase_set.all():
            writer.writerow(export_testcase(row))
    return response
示例#20
0
def suite_csv(request, job, pk):
    job = get_object_or_404(TestJob, pk=job)
    test_suite = get_object_or_404(TestSuite, name=pk, job=job)
    response = HttpResponse(content_type='text/csv')
    filename = "lava_%s.csv" % test_suite.name
    response['Content-Disposition'] = 'attachment; filename="%s"' % filename
    writer = csv.DictWriter(
        response,
        quoting=csv.QUOTE_ALL,
        extrasaction='ignore',
        fieldnames=testcase_export_fields())
    writer.writeheader()
    for row in test_suite.test_cases.all():
        writer.writerow(export_testcase(row))
    return response
示例#21
0
文件: api.py 项目: Linaro/lava-server
    def get_testcase_results_yaml(self, job_id, suite_name, case_name):
        """
        Name
        ----
        `get_testcase_results_yaml` (`job_id`, `suite_name`, `case_name`)

        Description
        -----------
        Get the test case results of given job id, suite and test case name
        in YAML format.

        Arguments
        ---------
        `job_id`: string
            Job id for which the results are required.
        `suite_name`: string
            Name of the suite for which the results are required.
        `case_name`: string
            Name of the test case for which the results are required.

        Return value
        ------------
        This function returns an XML-RPC structures of test case results in
        YAML format, provided the user is authenticated with an username and
        token.
        """

        self._authenticate()
        if not job_id:
            raise xmlrpclib.Fault(400, "Bad request: TestJob id was not "
                                  "specified.")
        try:
            job = TestJob.get_by_job_number(job_id)
            if not job.can_view(self.user):
                raise xmlrpclib.Fault(
                    401, "Permission denied for user to job %s" % job_id)
            test_suite = job.testsuite_set.get(name=suite_name)
            test_cases = test_suite.testcase_set.filter(name=case_name)
            yaml_list = [export_testcase(test_case) for test_case in test_cases]

        except TestJob.DoesNotExist:
            raise xmlrpclib.Fault(404, "Specified job not found.")
        except TestSuite.DoesNotExist:
            raise xmlrpclib.Fault(404, "Specified test suite not found.")
        except TestCase.DoesNotExist:
            raise xmlrpclib.Fault(404, "Specified test case not found.")

        return yaml.dump(yaml_list)
示例#22
0
def suite_yaml(request, job, pk):
    job = get_object_or_404(TestJob, pk=job)
    check_request_auth(request, job)
    test_suite = get_object_or_404(TestSuite, name=pk, job=job)
    querydict = request.GET
    offset = querydict.get('offset', default=None)
    limit = querydict.get('limit', default=None)
    response = HttpResponse(content_type='text/yaml')
    filename = "lava_%s.yaml" % test_suite.name
    response['Content-Disposition'] = 'attachment; filename="%s"' % filename
    yaml_list = []
    testcases = get_testcases_with_limit(test_suite, limit, offset)
    for test_case in testcases:
        yaml_list.append(export_testcase(test_case))
    yaml.dump(yaml_list, response, Dumper=yaml.CDumper)
    return response
示例#23
0
def suite_yaml(request, job, pk):
    job = get_object_or_404(TestJob, pk=job)
    check_request_auth(request, job)
    test_suite = get_object_or_404(TestSuite, name=pk, job=job)
    querydict = request.GET
    offset = querydict.get('offset', default=None)
    limit = querydict.get('limit', default=None)
    response = HttpResponse(content_type='text/yaml')
    filename = "lava_%s.yaml" % test_suite.name
    response['Content-Disposition'] = 'attachment; filename="%s"' % filename
    yaml_list = []
    testcases = get_testcases_with_limit(test_suite, limit, offset)
    for test_case in testcases:
        yaml_list.append(export_testcase(test_case))
    yaml.dump(yaml_list, response, Dumper=yaml.CDumper)
    return response
示例#24
0
def suite_csv(request, job, pk):
    job = get_object_or_404(TestJob, pk=job)
    check_request_auth(request, job)
    test_suite = get_object_or_404(TestSuite, name=pk, job=job)
    querydict = request.GET
    offset = querydict.get('offset', default=None)
    limit = querydict.get('limit', default=None)
    response = HttpResponse(content_type='text/csv')
    filename = "lava_%s.csv" % test_suite.name
    response['Content-Disposition'] = 'attachment; filename="%s"' % filename
    writer = csv.DictWriter(response,
                            quoting=csv.QUOTE_ALL,
                            extrasaction='ignore',
                            fieldnames=testcase_export_fields())
    writer.writeheader()
    testcases = get_testcases_with_limit(test_suite, limit, offset)
    for row in testcases:
        writer.writerow(export_testcase(row))
    return response
示例#25
0
def suite_csv(request, job, pk):
    job = get_object_or_404(TestJob, pk=job)
    check_request_auth(request, job)
    test_suite = get_object_or_404(TestSuite, name=pk, job=job)
    querydict = request.GET
    offset = querydict.get('offset', default=None)
    limit = querydict.get('limit', default=None)
    response = HttpResponse(content_type='text/csv')
    filename = "lava_%s.csv" % test_suite.name
    response['Content-Disposition'] = 'attachment; filename="%s"' % filename
    writer = csv.DictWriter(
        response,
        quoting=csv.QUOTE_ALL,
        extrasaction='ignore',
        fieldnames=testcase_export_fields())
    writer.writeheader()
    testcases = get_testcases_with_limit(test_suite, limit, offset)
    for row in testcases:
        writer.writerow(export_testcase(row))
    return response
示例#26
0
    def get_testjob_results_yaml(self, job_id):
        """
        Name
        ----
        `get_testjob_results_yaml` (`job_id`)

        Description
        -----------
        Get the job results of given job id in the YAML format.

        Arguments
        ---------
        `job_id`: string
            Job id for which the results are required.

        Return value
        ------------
        This function returns an XML-RPC structures of job results in YAML
        format, provided the user is authenticated with an username and token.
        """

        self._authenticate()
        if not job_id:
            raise xmlrpclib.Fault(
                400, "Bad request: TestJob id was not "
                "specified.")
        try:
            job = TestJob.get_by_job_number(job_id)
            if not job.can_view(self.user):
                raise xmlrpclib.Fault(
                    401, "Permission denied for user to job %s" % job_id)
            yaml_list = []
            for test_suite in job.testsuite_set.all():
                for test_case in test_suite.testcase_set.all():
                    yaml_list.append(export_testcase(test_case))

        except TestJob.DoesNotExist:
            raise xmlrpclib.Fault(404, "Specified job not found.")

        return yaml.dump(yaml_list)
示例#27
0
文件: api.py 项目: Linaro/lava-server
    def get_testjob_results_yaml(self, job_id):
        """
        Name
        ----
        `get_testjob_results_yaml` (`job_id`)

        Description
        -----------
        Get the job results of given job id in the YAML format.

        Arguments
        ---------
        `job_id`: string
            Job id for which the results are required.

        Return value
        ------------
        This function returns an XML-RPC structures of job results in YAML
        format, provided the user is authenticated with an username and token.
        """

        self._authenticate()
        if not job_id:
            raise xmlrpclib.Fault(400, "Bad request: TestJob id was not "
                                  "specified.")
        try:
            job = TestJob.get_by_job_number(job_id)
            if not job.can_view(self.user):
                raise xmlrpclib.Fault(
                    401, "Permission denied for user to job %s" % job_id)
            yaml_list = []
            for test_suite in job.testsuite_set.all():
                for test_case in test_suite.testcase_set.all():
                    yaml_list.append(export_testcase(test_case))

        except TestJob.DoesNotExist:
            raise xmlrpclib.Fault(404, "Specified job not found.")

        return yaml.dump(yaml_list)
示例#28
0
 def test_case_stream():
     for test_suite in suites:
         for test_case in test_suite.testcase_set.all():
             yield yaml.dump([export_testcase(test_case)],
                             Dumper=yaml.CDumper)
示例#29
0
 def test_case_stream():
     for test_suite in suites:
         for test_case in test_suite.testcase_set.all():
             yield yaml.dump([export_testcase(test_case)],
                             Dumper=yaml.CDumper)