def test_add_attachment_to_result_for_case_success_valid_file_extensions(
            self, attachment_file, exp_response_code):
        result = Result(
            comment="comment in result",
            elapsed="2m",
            version="2",
        )
        result_added = self.client.add_result_for_case(result, self.run.id,
                                                       self.case.id)

        response, act_response_code = self.client.add_attachment_to_result_for_case(
            {
                'attachment':
                self.api_page.generate_attachment(f'{attachment_file}')
            }, result_added.id, self.case.id)

        self.api_page.assert_equality(exp_response_code, act_response_code)

        self.api_page.assert_field_in_object("attachment_id", response)

        attachment_content = self.client.get_attachment(response.attachment_id)

        if 'json' in attachment_file:
            file_content = self.api_page.generate_attachment(
                f'{attachment_file}').read().decode("utf-8")
            self.api_page.assert_equality(json.dumps(attachment_content),
                                          file_content)
        else:
            file_content = self.api_page.generate_attachment(
                f'{attachment_file}').read().decode("utf-8")
            self.api_page.assert_equality(attachment_content,
                                          str(file_content))
    def test_add_attachment_to_result_with_invalid_attachments(self):
        result = Result(comment="comment in result", elapsed="2m", version="2")
        result_added = self.client.add_result_for_case(result, self.run.id,
                                                       self.case.id)

        attachment1 = self.api_page.generate_attachment('disallowed.js')
        attachment2 = self.api_page.generate_attachment('disallowed.sql')

        response, act_response_code = self.client.add_attachment_to_result_for_case(
            {'attachment': attachment1},
            result_added.id,
            self.case.id,
            check_errors=False)
        self.api_page.assert_equality(400, act_response_code)
        self.api_page.assert_equality(
            response['error'],
            self.attachments.errors.restricted_to_upload_malicious_file)

        response, act_response_code = self.client.add_attachment_to_result_for_case(
            {'attachment': attachment2},
            result_added.id,
            self.case.id,
            check_errors=False)
        self.api_page.assert_equality(400, act_response_code)
        self.api_page.assert_equality(
            response['error'],
            self.attachments.errors.restricted_to_upload_malicious_file)
Exemple #3
0
    def test_c4077_get_results(self):
        case_id = self.cases[1].id
        original_run = Run(name="A Test Run", case_ids=[case_id], include_all=False)
        created_run = self.client.add_run(original_run, self.project.id)

        tests = self.client.get_tests(created_run.id)
        assert len(tests) == 1
        test_id = tests[0].id

        statuses = [Statuses.failed, Statuses.failed, Statuses.retest, Statuses.passed]
        original_results = []
        expected_results = {}
        for index, status in enumerate(statuses):
            comment = f"Result number {index}"
            result = Result(status_id=status, test_id=test_id, comment=comment)
            original_results.append(result)
            expected_results[comment] = result

        self.client.add_results(original_results, created_run.id)

        results = self.client.get_results(test_id)
        assert len(results) == len(expected_results)
        for result in results:
            expected = expected_results.pop(result.comment)
            assert result.status_id == expected.status_id
            assert result.test_id == expected.test_id
            assert result.comment == expected.comment
 def get_results_for_case(self, run_id, case_id):
     response = self.client.send_get(
         f'get_results_for_case/{run_id}/{case_id}')
     results = []
     for result in response:
         results.append(Result(**result))
     return results
    def test_add_attachment_to_result_for_case_without_attachment(self):
        result = Result(
            comment="comment in result",
            elapsed="2m",
            version="2",
        )
        result_added = self.client.add_result_for_case(result, self.run.id,
                                                       self.case.id)

        response, act_response_code = self.client.add_attachment_to_result_for_case(
            None, result_added.id, self.case.id, check_errors=False)
        self.api_page.assert_equality(act_response_code, 400)
Exemple #6
0
    def test_c4074_add_result_for_case(self):
        case_id = self.cases[1].id
        original_run = Run(name="A Test Run", include_all=True)
        created_run = self.client.add_run(original_run, self.project.id)

        result = Result(status_id=Statuses.failed, elapsed="1m 45s")
        created_result = self.client.add_result_for_case(result, created_run.id, case_id)

        assert created_result.status_id == Statuses.failed
        assert created_result.elapsed == result.elapsed
        test_id = created_result.test_id

        test = self.client.get_test(test_id)
        assert test.case_id == case_id
        assert test.status_id == Statuses.failed
Exemple #7
0
    def test_c4073_add_result(self):
        case_id = self.cases[0].id
        original_run = Run(name="A Test Run", case_ids=[case_id], include_all=False)
        created_run = self.client.add_run(original_run, self.project.id)

        tests = self.client.get_tests(created_run.id)
        assert len(tests) == 1
        test_id = tests[0].id

        result = Result(status_id=Statuses.passed, elapsed="1m 45s")
        created = self.client.add_result(result, test_id)

        assert created.elapsed == result.elapsed
        assert created.status_id == Statuses.passed
        assert created.test_id == test_id
Exemple #8
0
    def test_c4075_add_results(self):
        original_run = Run(name="A Test Run", include_all=True)
        created_run = self.client.add_run(original_run, self.project.id)

        tests = self.client.get_tests(created_run.id)

        results = []
        statuses = [Statuses.passed, Statuses.failed, Statuses.blocked]
        expected_results = {}
        for status, test in zip(statuses, tests):
            results.append(Result(status_id=status, test_id=test.id))
            expected_results[test.id] = status
        created_results = self.client.add_results(results, created_run.id)

        assert len(created_results) == len(results)
        assert {result.test_id: result.status_id for result in created_results} == expected_results
    def test_add_attachment_to_result_read_only(self):
        result = Result(
            comment="comment in result",
            elapsed="2m",
            version="2",
        )
        result_added = self.client.add_result_for_case(result, self.run.id,
                                                       self.case.id)

        with pytest.raises(APIError) as e_info:
            user = self.add_user_with_permissions(permission="Read-only")
            make_client(user.email_address,
                        user.password).add_attachment_to_result(
                            {'attachment': 'content'}, result_added.id)

        error = e_info.value
        assert error.status_code == 403
        assert error.error == 'You are not allowed to add attachments (insufficient permissions).'
    def test_add_attachment_to_result_invalid_attachment(
            self, attachment_file, exp_response_code):
        result = Result(
            comment="comment in result",
            elapsed="2m",
            version="2",
        )
        result_added = self.client.add_result_for_case(result, self.run.id,
                                                       self.case.id)

        attachment = self.api_page.generate_attachment(f'{attachment_file}')

        response, act_response_code = self.client.add_attachment_to_result(
            {'attachment': attachment}, result_added.id, check_errors=False)
        self.api_page.assert_equality(exp_response_code, act_response_code)
        self.api_page.assert_equality(
            response['error'],
            self.attachments.errors.restricted_to_upload_malicious_file)
    def test_add_attachment_to_result_no_access(self):
        result = Result(
            comment="comment in result",
            elapsed="2m",
            version="2",
        )
        result_added = self.client.add_result_for_case(result, self.run.id,
                                                       self.case.id)

        with pytest.raises(APIError) as e_info:
            user = self.add_user_with_project_permissions(
                project_id=self.project_new.id, permission="No Access")
            make_client(user.email_address,
                        user.password).add_attachment_to_result(
                            {'attachment': 'content'}, result_added.id)

        error = e_info.value
        assert error.status_code == 403
        assert error.error == 'The requested project does not exist or you do not have the permissions to access it.'
    def test_add_attachment_to_result_for_case_multiple_success(
            self, attachment_file, exp_response_code):
        result = Result(
            comment="comment in result",
            elapsed="2m",
            version="2",
        )
        result_added = self.client.add_result_for_case(result, self.run.id,
                                                       self.case.id)

        attachment_files_list = attachment_file.split(",")
        for file in attachment_files_list:
            response, act_response_code = self.client.add_attachment_to_result_for_case(
                {'attachment': self.api_page.generate_attachment(f'{file}')},
                result_added.id, self.case.id)
            self.api_page.assert_equality(exp_response_code, act_response_code)
            self.api_page.assert_field_in_object("attachment_id", response)

        attachment_content = self.client.get_attachments_for_case(self.case.id)
        self.api_page.assert_attachment_content_names_in_attachment_file(
            attachment_content, attachment_file)
    def test_add_attachment_to_result_for_case_success(self):
        result = Result(
            comment="comment in result",
            elapsed="2m",
            version="2",
        )
        result_added = self.client.add_result_for_case(result, self.run.id,
                                                       self.case.id)

        from pathlib import Path, PurePosixPath
        filename = PurePosixPath('../data/logo.png')
        # will be converted to valid one on Windows
        file_path = str(Path(filename))

        files = {'attachment': open(file_path, 'rb')}
        response = self.client.add_attachment_to_result_for_case(
            files, result_added.id, self.case.id)

        self.api_page.assert_field_in_object("attachment_id", response[0])

        attachment_content = self.client.get_attachment(
            response[0].attachment_id)
        self.api_page.assert_object(attachment_content)
Exemple #14
0
    def test_c4079_get_results_for_run(self):
        original_run = Run(name="A Test Run", include_all=True)
        created_run = self.client.add_run(original_run, self.project.id)

        statuses = [Statuses.retest, Statuses.failed, Statuses.retest, Statuses.passed]
        original_results = []
        expected_results = {}
        counter = 0
        for status in statuses:
            for case in self.cases:
                comment = f"Result number {counter}"
                counter += 1
                result = Result(status_id=status, comment=comment, case_id=case.id)
                original_results.append(result)
                expected_results[comment] = result

        self.client.add_results_for_cases(original_results, created_run.id)

        results = self.client.get_results_for_run(created_run.id)
        assert len(results) == len(expected_results)
        for result in results:
            expected = expected_results.pop(result.comment)
            assert result.status_id == expected.status_id
            assert result.comment == expected.comment
Exemple #15
0
 def add_result(self, result, test_id):
     response = self.client.send_post(f'add_result/{test_id}', result)
     return Result(**response)
Exemple #16
0
 def add_result_for_case(self, result, run_id, case_id):
     response = self.client.send_post(
         f'add_result_for_case/{run_id}/{case_id}', result)
     return Result(**response)
Exemple #17
0
 def add_results_for_cases(self, results, run_id):
     result_dict = dict(results=results)
     response = self.client.send_post(f'add_results_for_cases/{run_id}',
                                      result_dict)
     return [Result(**args) for args in response]
Exemple #18
0
 def get_results(self, test_id):
     response = self.client.send_get(f'get_results/{test_id}')
     results = []
     for result in response:
         results.append(Result(**result))
     return results