def test_scratch_org__as_user_allowed(self, client, planrepos): user = UserFactory() assign_perm("plan.run_plan", user, planrepos[0]) client.force_login(user) response = client.get(reverse("create_org_scratch")) assert response.status_code == 200
def test_qa_org__as_user_allowed(self, client, planrepos): user = UserFactory() assign_perm("plan.run_plan", user, planrepos[1]) # logged in w/o perms client.force_login(user) response = client.get(reverse("create_org_qa")) assert response.status_code == 200
def test_testresults_page_visible_to_logged_in_users(self): client, user = self.make_user_and_client(UserFactory()) private_planrepo = PlanRepository.objects.filter( repo__name="PrivateRepo").first() assign_perm("plan.view_builds", user, private_planrepo) response = client.get(f"/repos/{private_planrepo.repo}/perf") self.debugmsg(response) self.assertEqual(response.status_code, 200) self.assertNotIn("Please login", response.content.decode("utf-8"))
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()
def setUpClass(cls): super().setUpClass() cls.superuser = StaffSuperuserFactory() cls.user = UserFactory() cls.client = APIClient() TestResultFactory(method__testclass__test_type="Robot") TestResultFactory(method__testclass__test_type="Robot") TestResultFactory(method__testclass__test_type="Robot") testresults = TestResult.objects.all() assign_perm("plan.view_builds", cls.user, testresults[0].build_flow.build.planrepo) assign_perm("plan.view_builds", cls.user, testresults[1].build_flow.build.planrepo)
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()
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="", )
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
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, )
def test_public_access(self): client, user = self.make_user_and_client(UserFactory()) response = client.get("/api/testmethod_perf_UI/") self.debugmsg(response) self.assertEqual(response.status_code, 200)
def test_api_schema_protection_normal_user(self): client, user = self.make_user_and_client(UserFactory()) response = client.get("/api/") self.debugmsg(response) self.assertEqual(response.status_code, 403)
def make_user_and_client(cls, user=None): user = user or UserFactory() client = APIClient() assert client.login(username=user.username, password="******") return client, user
def setUpTestData(cls): super().setUpTestData() cls.client = Client() cls.superuser = StaffSuperuserFactory() cls.user = UserFactory() cls.build = BuildFactory()
def test_qa_org__as_user_not_allowed(self, client, planrepos): user = UserFactory() client.force_login(user) response = client.get(reverse("create_org_qa")) assert response.status_code == 403