Example #1
0
 def test_get_flow_options(self):
     build_flow = BuildFlowFactory()
     build_flow.build.plan.role = "release"
     build_flow.build.release = Release(repo=RepositoryFactory())
     options = build_flow._get_flow_options()
     assert options["github_release_notes"][
         "sandbox_date"] == datetime.date.today()
     assert options["github_release_notes"][
         "production_date"] == datetime.date.today() + datetime.timedelta(
             days=6)
Example #2
0
 def setUpClass(cls):
     cls.client, cls.user = cls.make_user_and_client()
     super().setUpClass()
     p1 = PlanFactory(name="Plan1")
     p2 = PlanFactory(name="Plan2")
     r1 = RepositoryFactory(name="Repo1")
     r2 = RepositoryFactory(name="Repo2")
     b1 = BranchFactory(name="Branch1", repo=r1)
     b2 = BranchFactory(name="Branch2", repo=r2)
     bf1 = BuildFlowFactory(flow="Flow1")
     bf2 = BuildFlowFactory(flow="Flow2")
     (p1, p2, r1, r2, b1, b2, bf1, bf2)  # shut up linter
Example #3
0
    def test_robot_task_attribute(self):
        """verify that the task attribute of a TestResult has been
        set for a robot test result

        The importer uses the timestamp of the output file to figure
        out which task generated the file. It then uses the options
        of this task to generate the log files.

        This test creates a few FlowTask objects where one has a start
        time and end time that encompases the mtime of the output
        file. That task should get saved with the test result.
        """

        path = Path(__file__).parent / "robot_with_setup_teardown.xml"
        output_xml_mtime = timezone.make_aware(
            datetime.fromtimestamp(path.stat().st_mtime))
        buildflow = BuildFlowFactory()
        time_offsets = ((-60, -30), (-29, +1), (+2, +10))
        FlowTaskFactory.reset_sequence(value=1)
        for (start_offset, end_offset) in time_offsets:
            time_start = output_xml_mtime + timedelta(seconds=start_offset)
            time_end = output_xml_mtime + timedelta(seconds=end_offset)
            task = FlowTaskFactory(
                build_flow=buildflow,
                time_start=time_start,
                time_end=time_end,
            )
            task.save()

        robot_importer.import_robot_test_results(buildflow, path)
        for result in models.TestResult.objects.all():
            assert result.task is not None
            assert result.task.stepnum == "2"
Example #4
0
 def test_basic_parsing(self):
     buildflow = BuildFlowFactory()
     path = PurePath(__file__).parent / "robot_1.xml"
     robot_importer.import_robot_test_results(buildflow, path)
     test_results = models.TestResult.objects.filter(
         method__name="FakeTestResult")
     assert test_results
Example #5
0
 def test_import_robot_tags(self):
     """Verify that robot tags are added to the database"""
     buildflow = BuildFlowFactory()
     path = PurePath(__file__).parent / "robot_1.xml"
     robot_importer.import_robot_test_results(buildflow, path)
     test_results = models.TestResult.objects.filter(
         method__name="FakeTestResult")
     assert test_results[0].robot_tags == "tag with spaces,w-123456"
Example #6
0
 def test_import_all_tests(self):
     """Verifies that we import all tests in a suite"""
     buildflow = BuildFlowFactory()
     path = PurePath(__file__).parent / "robot_with_failures.xml"
     robot_importer.import_robot_test_results(buildflow, path)
     failing_test_results = models.TestResult.objects.filter(outcome="Fail")
     passing_test_results = models.TestResult.objects.filter(outcome="Pass")
     assert len(failing_test_results) == 3
     assert len(passing_test_results) == 1
Example #7
0
    def test_field_keyword_and_message_passing_test(self):
        """Verify that the failing_keyword field is set correctly for passing tests"""
        buildflow = BuildFlowFactory()
        path = PurePath(__file__).parent / "robot_with_failures.xml"
        robot_importer.import_robot_test_results(buildflow, path)

        test_result = models.TestResult.objects.get(
            method__name="Passing test")
        self.assertEqual(test_result.message, "Life is good, yo.")
        self.assertEqual(test_result.robot_keyword, None)
Example #8
0
 def test_nested_suites(self):
     buildflow = BuildFlowFactory()
     path = PurePath(__file__).parent / "robot_with_nested_suites.xml"
     robot_importer.import_robot_test_results(buildflow, path)
     assert models.TestResult.objects.all(
     ), "Test results should have been created"
     test_result = models.TestResult.objects.get(
         method__name__contains="AAAAA")
     assert test_result.duration == 0.25
     assert test_result.method.name == "AAAAA Test Set Login Url"
     assert test_result.method.testclass.name == "Nested/Cumulusci/Base"
Example #9
0
    def test_field_keyword_and_message(self):
        """Verify that the keyword and message fields are populated"""

        buildflow = BuildFlowFactory()
        path = PurePath(__file__).parent / "robot_with_failures.xml"
        robot_importer.import_robot_test_results(buildflow, path)

        test_result = models.TestResult.objects.get(
            method__name="Failing test 1")
        self.assertEqual(test_result.message, "Danger, Will Robinson!")
        self.assertEqual(test_result.robot_keyword, "Keyword with failure")
Example #10
0
    def test_field_keyword_and_message_nested_keywords(self):
        """Verify that the keyword and message fields are set when failure is in a nested keyword"""
        buildflow = BuildFlowFactory()
        path = PurePath(__file__).parent / "robot_with_failures.xml"
        robot_importer.import_robot_test_results(buildflow, path)

        test_result = models.TestResult.objects.get(
            method__name="Failing test 2")
        self.assertEqual(test_result.message,
                         "I'm sorry, Dave. I'm afraid I can't do that.")
        self.assertEqual(test_result.robot_keyword,
                         "Keyword which calls a failing keyword")
Example #11
0
 def setUpClass(cls):
     super().setUpClass()
     p1 = PlanFactory(name="Plan1")
     p2 = PlanFactory(name="Plan2")
     r1 = RepositoryFactory(name="PublicRepo")
     r2 = RepositoryFactory(name="PrivateRepo")
     public_pr = PlanRepositoryFactory(plan=p1, repo=r1)
     assign_perm("plan.view_builds", Group.objects.get(name="Public"),
                 public_pr)
     pr2 = PlanRepositoryFactory(plan=p2, repo=r2)
     BranchFactory(name="Branch1", repo=r1)
     BranchFactory(name="Branch2", repo=r2)
     private_build = BuildFactory(repo=r2, plan=p2, planrepo=pr2)
     private_bff = BuildFlowFactory(build=private_build)
     public_build = BuildFactory(repo=r2, plan=p2, planrepo=pr2)
     public_bff = BuildFlowFactory(build=public_build)
     BuildFlowFactory(flow="Flow2")
     TestResultFactory(build_flow=private_bff, method__name="Private1")
     TestResultFactory(build_flow=private_bff, method__name="Private2")
     TestResultFactory(build_flow=public_bff, method__name="Public1")
     TestResultFactory(build_flow=public_bff, method__name="Public2")
Example #12
0
 def test_duration_calculations(self):
     buildflow = BuildFlowFactory()
     path = PurePath(__file__).parent / "robot_with_setup_teardown.xml"
     robot_importer.import_robot_test_results(buildflow, path)
     correct = 14.002
     duration = models.TestResult.objects.get(
         method__name="FakeTestResult2").duration
     assert duration == correct
     correct = 15.001
     duration = models.TestResult.objects.get(
         method__name="FakeTestResult_setup_no_teardown").duration
     assert duration == correct
     correct = 20.002
     duration = models.TestResult.objects.get(
         method__name="FakeTestResult_teardown_no_setup").duration
     assert duration == correct
Example #13
0
    def test_execution_errors(self):
        """Verify pre-test execution errors are imported

        If robot has errors before the first test runs (eg: import
        errors) these errors were being thrown away. This test verifies
        that execution errors appear in imported test results.
        """

        buildflow = BuildFlowFactory()
        path = PurePath(__file__).parent / "robot_with_import_errors.xml"
        robot_importer.import_robot_test_results(buildflow, path)

        test_result = models.TestResult.objects.last()
        root = ET.fromstring(test_result.robot_xml)
        msg_elements = root.findall("./errors/msg")
        error_messages = [element.text for element in msg_elements]

        expected_error_messages = [
            "Error in file 'example.robot' on line 2: Library setting requires value.",
            "Error in file 'example.robot' on line 3: Resource setting requires value.",
        ]
        self.assertCountEqual(error_messages, expected_error_messages)
Example #14
0
def test_create_status__fail():
    build, repo = setup_build_with_status("fail")
    # First BuildFlow
    BuildFlowFactory(build=build)
    # Second BuildFlow, this one has a failing test :(
    bf = BuildFlowFactory(build=build)
    bf.tests_fail = 1
    bf.save()

    utils.create_status(build)
    repo.create_status.assert_called_once_with(
        sha=build.commit,
        state="failure",
        target_url=f"initech.co/builds/{build.id}/tests",
        description="⚠ ️1/2 failed",  # each BuildFlow has total_tests == 1
        context=build.plan.context,
    )
Example #15
0
 def test_set_commit_status(self):
     build_flow = BuildFlowFactory()
     build_flow.build.plan.commit_status_template = "{{ 2 + 2 }}"
     build_flow.flow_instance = mock.Mock()
     build_flow.set_commit_status()
     assert build_flow.build.commit_status == "4"