Exemplo n.º 1
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
Exemplo n.º 2
0
    def test_get_or_create_release(self):
        tag = "release-tag"
        repo = RepositoryFactory(name="Test Repo")
        push_payload = {"head_commit": {"id": "asdf1234"}}

        actual = views.get_or_create_release(push_payload, tag, repo)
        assert actual is not None
Exemplo n.º 3
0
    def test_get_or_create_branch(self):
        branch_name = "test-branch"
        branch = BranchFactory(name=branch_name, is_removed=True)
        repo = RepositoryFactory(name="Test Repo")

        actual = views.get_or_create_branch(branch_name, repo)
        assert actual is not None
Exemplo n.º 4
0
    def test_planrepo_find_on_build_init(self):
        repo = RepositoryFactory()
        plan = PlanFactory()
        planrepo = PlanRepositoryFactory(plan=plan, repo=repo)

        build = Build(repo=repo, plan=plan)
        assert build.planrepo == planrepo
Exemplo n.º 5
0
def planrepos(db):
    repo = RepositoryFactory()
    plan1 = PlanFactory(role="scratch")
    plan2 = PlanFactory(role="qa")
    planrepo1 = PlanRepositoryFactory(repo=repo, plan=plan1)
    planrepo2 = PlanRepositoryFactory(repo=repo, plan=plan2)
    return planrepo1, planrepo2
Exemplo n.º 6
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)
Exemplo n.º 7
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")
Exemplo n.º 8
0
 def setUpTestData(cls):
     cls.client = Client()
     cls.superuser = StaffSuperuserFactory()
     cls.user = UserFactory()
     cls.repo = RepositoryFactory()
     cls.plan1 = PlanFactory()
     cls.plan1.role = "scratch"
     cls.plan1.save()
     cls.plan2 = PlanFactory()
     cls.plan2.role = "qa"
     cls.plan2.save()
     cls.planrepo1 = PlanRepositoryFactory(repo=cls.repo, plan=cls.plan1)
     cls.planrepo2 = PlanRepositoryFactory(repo=cls.repo, plan=cls.plan2)
     super(TestCreateOrgViews, cls).setUpTestData()
Exemplo n.º 9
0
 def test_lock_set(self, run, lock_org, scratch_org_limits,
                   reset_database_connection):
     build_timeout = 100
     repo = RepositoryFactory(name="myrepo")
     OrgFactory(name="myorg", repo=repo, scratch=False)
     plan = PlanFactory(name="myplan",
                        org="myorg",
                        build_timeout=build_timeout)
     build = BuildFactory(repo=repo, plan=plan)
     PlanRepositoryFactory(repo=repo, plan=plan)
     check_queued_build(build.id)
     print(lock_org.mock_calls)
     assert lock_org.mock_calls
     assert lock_org.mock_calls[0][1][2] == build_timeout
Exemplo n.º 10
0
 def setUpTestData(cls):
     cls.client = Client()
     cls.superuser = StaffSuperuserFactory()
     cls.user = UserFactory()
     cls.plan = PlanFactory(name="Plan1")
     cls.plan.dashboard = "last"
     cls.plan.trigger = "tag"
     cls.plan.regex = "beta"
     cls.plan.save()
     cls.repo = RepositoryFactory(name="PublicRepo")
     cls.planrepo = PlanRepositoryFactory(plan=cls.plan, repo=cls.repo)
     cls.branch = BranchFactory(name="test-branch", repo=cls.repo)
     cls.build = BuildFactory(
         branch=cls.branch, repo=cls.repo, plan=cls.plan, planrepo=cls.planrepo
     )
     super(TestRepositoryViews, cls).setUpTestData()
Exemplo n.º 11
0
    def test_scheduled_build_init(self):
        repo = RepositoryFactory()
        branch = BranchFactory(name="branch", repo=repo)
        schedule = PlanScheduleFactory(branch=branch)
        plan = PlanFactory()

        planrepo = PlanRepositoryFactory(plan=plan, repo=repo)

        build = Build(
            repo=branch.repo,
            plan=plan,
            branch=branch,
            commit="shashasha",
            schedule=schedule,
            build_type="scheduled",
        )
        assert build.planrepo == planrepo
Exemplo n.º 12
0
    def setUpClass(cls):
        super().setUpClass()
        cls.superuser = StaffSuperuserFactory()
        cls.user = UserFactory()
        cls.client = APIClient()

        repo = RepositoryFactory(name="repo1")
        master = BranchFactory(name="master")

        today = timezone.make_aware(dateutil.parser.parse("01:00:00"),
                                    timezone.get_current_timezone())
        cls.today = today.strftime("%Y-%m-%d %H:%M:%S")

        # create some data that spans several days, plus one for today
        tz = timezone.get_current_timezone()
        for date in (
                cls.today,
                "2020-Jan-01",
                "2020-Jan-02",
                "2020-Jan-02",
                "2020-Jan-03",
                "2020-Jan-03",
                "2020-Jan-03",
        ):
            time_end = timezone.make_aware(
                dateutil.parser.parse(f"{date} 01:00:00"), tz)
            TestResultFactory(
                method__testclass__test_type="Robot",
                build_flow__build__repo=repo,
                build_flow__build__branch=master,
                build_flow__time_end=time_end,
                method__name="Test 1",
                outcome="Pass",
                source_file="/tmp/example.robot",
                robot_keyword="Some keyword",
                robot_tags="",
                duration=0.1,
                message="",
            )
Exemplo n.º 13
0
    def _testrun_build(self, run_build, scratch_org_limits, org_is_scratch,
                       no_lock):
        repo = RepositoryFactory(name="myrepo")
        branch = BranchFactory(name="mybranch", repo=repo)
        plan = PlanFactory(name="myplan",
                           org="myorg",
                           build_timeout=BUILD_TIMEOUT)
        PlanRepositoryFactory(repo=repo, plan=plan)
        user = UserFactory(username="******")
        org = OrgFactory(name="myorg", repo=repo, scratch=org_is_scratch)
        os.environ["DYNO"] = "worker.42"
        build_pk = None

        def side_effect(build_id):
            nonlocal build_pk
            build_pk = build_id

        run_build.side_effect = side_effect
        scratch_org_limits.return_value = mock.Mock()
        scratch_org_limits.return_value.remaining = settings.SCRATCH_ORG_RESERVE + 5
        c = Command()
        c.handle("myrepo",
                 "mybranch",
                 "commit",
                 "myplan",
                 "username",
                 no_lock=no_lock)
        assert build_pk
        build = Build.objects.get(pk=build_pk)
        assert not build.task_id_check  # wasn't queued
        assert build.build_type == "manual-command"
        assert build.user == user
        assert build.repo == repo
        assert build.branch == branch
        assert build.plan == plan
        assert build.org == org
Exemplo n.º 14
0
    def setUpClass(cls):
        super().setUpClass()
        cls.superuser = StaffSuperuserFactory()
        cls.user = UserFactory()
        cls.client = APIClient()

        repo1 = RepositoryFactory(name="repo1")
        repo2 = RepositoryFactory(name="repo2")
        master = BranchFactory(name="master")
        feature = BranchFactory(name="feature/robot")

        # The default for queries is today's date, so we need to use that
        # when creating results
        time_end = timezone.make_aware(dateutil.parser.parse("01:00:00"),
                                       timezone.get_current_timezone())
        cls.today = time_end.strftime("%Y-%m-%d %H:%M:%S")

        # One apex test, just to make sure it doesn't appear in any test results
        TestResultFactory(
            build_flow__time_end=time_end,
            method__testclass__test_type="Apex",
            outcome="Pass",
            duration=0.1,
        )

        # ... and several robot tests, some passing, some failing
        # oof. This is one place where I think black made the code much
        # less readable than my hand-edited version.
        for (
                repo,
                source,
                outcome,
                branch,
                test_name,
                tags,
                robot_keyword,
                message,
        ) in (
            (repo1, "file1.robot", "Pass", master, "Passing 1", None, None,
             None),
            (repo1, "file1.robot", "Pass", master, "Passing 2", None, None,
             None),
            (
                repo2,
                "file2.robot",
                "Fail",
                feature,
                "Failing 1",
                "",
                "KW1",
                "epic fail",
            ),
            (
                repo2,
                "file2.robot",
                "Fail",
                feature,
                "Failing 2",
                "",
                "KW1",
                "epic fail",
            ),
            (
                repo2,
                "file3.robot",
                "Fail",
                feature,
                "Failing 3",
                "",
                "KW2",
                "epic fail",
            ),
            (
                repo2,
                "file3.robot",
                "Fail",
                feature,
                "Failing 4",
                "t1,t2",
                "KW3",
                "ʃıɐɟ ɔıdǝ",
            ),
        ):
            TestResultFactory(
                method__testclass__test_type="Robot",
                build_flow__build__repo=repo,
                build_flow__build__branch=branch,
                build_flow__time_end=time_end,
                method__name=test_name,
                outcome=outcome,
                source_file=source,
                robot_keyword=robot_keyword,
                duration=0.1,
                robot_tags=tags,
                message=message,
            )