Esempio n. 1
0
    def test_activate(self, mock_clients, mock_results, mock_allowed):
        mock_allowed.return_value = (False, None)
        mock_clients.return_value = False
        mock_results.return_value = False
        user = utils.create_user_with_token(name="username")
        ev = self.create_event_with_jobs()
        start_session_url = reverse('ci:start_session', args=[user.pk])
        self.get(start_session_url)
        job = ev.jobs.first()
        job.active = False
        job.save()
        url = reverse('ci:view_job', args=[job.pk])
        self.get(url)
        self.check_job(job)
        with self.assertRaises(Exception):
            self.selenium.find_element_by_id("job_active_form")

        mock_allowed.return_value = (True, user)
        mock_results.return_value = True

        self.get(url)
        self.check_job(job)
        elem = self.selenium.find_element_by_id("job_active_form")
        elem.submit()
        self.wait_for_load()
        self.wait_for_js(wait=5)
        self.check_job(job)
Esempio n. 2
0
    def test_invalidate_invalid(self, mock_clients, mock_results, mock_allowed):
        mock_allowed.return_value = (False, None)
        mock_clients.return_value = False
        mock_results.return_value = False
        ev = self.create_event_with_jobs()
        user = utils.create_user_with_token(name="username")
        start_session_url = reverse('ci:start_session', args=[user.pk])
        self.get(start_session_url)
        job = ev.jobs.first()
        url = reverse('ci:view_job', args=[job.pk])
        self.get(url)
        self.check_job(job)
        # not allowed to cancel
        with self.assertRaises(Exception):
            self.selenium.find_element_by_id("invalidate")

        # OK now
        mock_allowed.return_value = (True, user)
        mock_results.return_value = True
        self.get(url)
        self.check_job(job)
        self.selenium.find_element_by_id("invalidate")

        # job now active, shouldn't be able to invalidate
        job.active = False
        job.save()
        self.get(url)
        self.check_job(job)
        with self.assertRaises(Exception):
            self.selenium.find_element_by_id("invalidate")
Esempio n. 3
0
 def create_records(self, recipe, branch):
     info = {}
     info["owner"] = test_utils.create_user(name=recipe["repository_owner"])
     info["build_user"] = test_utils.create_user_with_token(name=recipe["build_user"])
     info["repository"] = test_utils.create_repo(user=info["owner"], name=recipe["repository_name"])
     info["branch"] = test_utils.create_branch(repo=info["repository"], name=branch)
     return info
Esempio n. 4
0
 def setUp(self):
     self.client = Client()
     self.factory = RequestFactory()
     self.server = utils.create_git_server(
         host_type=settings.GITSERVER_BITBUCKET)
     self.user = utils.create_user_with_token(server=self.server)
     utils.simulate_login(self.client.session, self.user)
     self.gapi = self.server.api()
Esempio n. 5
0
 def test_bad_user(self):
     """
     Make sure we only get recipes for the correct build user
     This shouldn't create an event or any jobs.
     """
     c1_data, c2_data, pr = self.create_pr_data()
     other_build_user = utils.create_user_with_token(name="bad_build_user")
     pr.build_user = other_build_user
     self.set_counts()
     pr.save()
     self.compare_counts()
Esempio n. 6
0
    def create_default_recipes(self, recipes_dir, server_type=settings.GITSERVER_GITHUB):
        hostname = "github.com"
        if server_type == settings.GITSERVER_GITLAB:
            hostname = "gitlab.com"

        self.recipe_file = self.create_recipe_in_repo("recipe_all.cfg", "recipe.cfg", hostname=hostname)
        self.recipe_pr_file = self.create_recipe_in_repo("pr_dep.cfg", "pr_dep.cfg", hostname=hostname)
        self.recipe_push_file = self.create_recipe_in_repo("push_dep.cfg", "push_dep.cfg", hostname=hostname)
        self.server = test_utils.create_git_server(host_type=server_type)
        self.build_user = test_utils.create_user_with_token(name="moosebuild", server=self.server)
        self.owner = test_utils.create_user(name="idaholab", server=self.server)
        self.repo = test_utils.create_repo(name="civet", user=self.owner)
        self.branch = test_utils.create_branch(name="devel", repo=self.repo)
        return self.load_recipes(recipes_dir)
Esempio n. 7
0
    def create_default_recipes(self, server_type=settings.GITSERVER_GITHUB):
        self.set_counts()
        self.server = utils.create_git_server(host_type=server_type)
        self.build_user = utils.create_user_with_token(name="moosebuild",
                                                       server=self.server)
        self.owner = utils.create_user(name="owner", server=self.server)
        self.repo = utils.create_repo(name="repo", user=self.owner)
        self.branch = utils.create_branch(name="devel", repo=self.repo)
        pr = utils.create_recipe(name="PR Base",
                                 user=self.build_user,
                                 repo=self.repo)
        pr1 = utils.create_recipe(name="PR With Dep",
                                  user=self.build_user,
                                  repo=self.repo)
        pr1.depends_on.add(pr)
        push = utils.create_recipe(name="Push Base",
                                   user=self.build_user,
                                   repo=self.repo,
                                   branch=self.branch,
                                   cause=models.Recipe.CAUSE_PUSH)
        push1 = utils.create_recipe(name="Push With Dep",
                                    user=self.build_user,
                                    repo=self.repo,
                                    branch=self.branch,
                                    cause=models.Recipe.CAUSE_PUSH)
        push1.depends_on.add(push)
        alt_pr = utils.create_recipe(
            name="Alt PR with dep",
            user=self.build_user,
            repo=self.repo,
            cause=models.Recipe.CAUSE_PULL_REQUEST_ALT)
        alt_pr.depends_on.add(pr)

        utils.create_recipe(name="Manual",
                            user=self.build_user,
                            repo=self.repo,
                            branch=self.branch,
                            cause=models.Recipe.CAUSE_MANUAL)
        self.compare_counts(
            recipes=6,
            deps=3,
            current=6,
            num_push_recipes=2,
            num_pr_recipes=2,
            num_manual_recipes=1,
            num_pr_alt_recipes=1,
            users=2,
            repos=1,
            branches=1,
        )
Esempio n. 8
0
    def create_events(self):
        self.set_counts()
        self.build_user = utils.create_user_with_token(name="moosebuild")
        self.owner = utils.create_user(name="idaholab")
        self.repo = utils.create_repo(name="civet", user=self.owner)
        self.branch = utils.create_branch(name="devel", repo=self.repo)
        pre = utils.create_recipe(name="Precheck", user=self.build_user, repo=self.repo)
        test = utils.create_recipe(name="Test", user=self.build_user, repo=self.repo)
        test1 = utils.create_recipe(name="Test1", user=self.build_user, repo=self.repo)
        test.depends_on.add(pre)
        test1.depends_on.add(pre)
        merge = utils.create_recipe(name="Merge", user=self.build_user, repo=self.repo)
        merge.depends_on.add(test)
        merge.depends_on.add(test1)
        pr = utils.create_pr(title="{a, b} & <c> … somereallylongwordthatshouldgettruncated", repo=self.repo)
        pr.username = '******'
        pr.save()
        for commit in ['1234', '2345', '3456']:
            e = utils.create_event(user=self.owner, commit1=commit, branch1=self.branch, branch2=self.branch)
            e.pull_request = pr
            e.description = "some description"
            e.save()
            j = utils.create_job(recipe=pre, event=e, user=self.build_user)
            j.seconds = datetime.timedelta(seconds=10)
            j.failed_step = 'failed step'
            j.running_step = '3/5'
            j.save()
            utils.create_job(recipe=test, event=e, user=self.build_user)
            utils.create_job(recipe=test1, event=e, user=self.build_user)
            utils.create_job(recipe=merge, event=e, user=self.build_user)

        self.compare_counts(recipes=4,
                deps=4,
                current=4,
                jobs=12,
                active=12,
                num_pr_recipes=4,
                events=3,
                users=2,
                repos=1,
                branches=1,
                commits=3,
                prs=1)
Esempio n. 9
0
 def test_cancel_valid(self, mock_results, mock_clients, mock_allowed):
     user = utils.create_user_with_token(name="username")
     ev = self.create_event_with_jobs()
     mock_allowed.return_value = (True, user)
     mock_results.return_value = True
     mock_clients.return_value = False
     start_session_url = reverse('ci:start_session', args=[user.pk])
     self.get(start_session_url)
     job = ev.jobs.first()
     job.status = models.JobStatus.SUCCESS
     job.save()
     client_views.get_job_info(job)
     url = reverse('ci:view_job', args=[job.pk])
     self.get(url)
     self.check_job(job)
     cancel_elem = self.selenium.find_element_by_id("cancel")
     cancel_elem.submit()
     self.wait_for_js()
     self.check_job(job)
Esempio n. 10
0
    def test_cancel_invalid(self, mock_results, mock_clients, mock_allowed):
        ev = self.create_event_with_jobs()
        user = utils.create_user_with_token(name="username")
        start_session_url = reverse('ci:start_session', args=[user.pk])
        self.get(start_session_url)
        mock_allowed.return_value = (False, None)
        mock_clients.return_value = True
        mock_results.return_value = False
        job = ev.jobs.first()
        url = reverse('ci:view_job', args=[job.pk])
        self.get(url)
        self.check_job(job)
        # not allowed to cancel
        with self.assertRaises(Exception):
            self.selenium.find_element_by_id("cancel")

        mock_allowed.return_value = (True, user)
        mock_results.return_value = True
        # should work now
        client_views.get_job_info(job)
        self.get(url)
        self.check_job(job)
        self.selenium.find_element_by_id("cancel")

        job.complete = True
        job.save()
        self.get(url)
        self.check_job(job)
        # job is complete, can't cancel
        with self.assertRaises(Exception):
            self.selenium.find_element_by_id("cancel")

        job.complete = False
        job.active = False
        job.save()
        self.get(url)
        self.check_job(job)
        # job is not active, can't cancel
        with self.assertRaises(Exception):
            self.selenium.find_element_by_id("cancel")