def test_get_last_20_tests_for_a_team_and_project_ordered_by_date_created_desc(self):
     LoadTestFactory.add_to_project(25, user=self.user, team=self.team, project=self.project)
     LoadTestFactory.add_to_project(5, user=self.user, team=self.team, project=self.team.projects[1])
     loaded_tests = list(LoadTest.get_by_team_and_project_name(self.team, self.project.name))
     expect(loaded_tests).to_length(20)
     for load_tests in loaded_tests:
         expect(load_tests.project_name).to_equal(self.project.name)
Exemple #2
0
 def _add_results(self):
     self.load_test.results.append(TestResultFactory.build())
     self.load_test.results.append(
         TestResultFactory.build(config=self.config))
     self.load_test.results.append(TestResultFactory.build())
     self.load_test.save()
     self.load_test2 = LoadTestFactory.add_to_project(1,
                                                      user=self.user,
                                                      team=self.team,
                                                      project=self.project,
                                                      status="Finished")
     self.load_test2.results.append(TestResultFactory.build())
     self.load_test2.results.append(
         TestResultFactory.build(config=self.config))
     self.load_test2.save()
     self.load_test3 = LoadTestFactory.add_to_project(
         1,
         user=self.user,
         team=self.team,
         project=self.team.projects[1],
         status="Finished")
     self.load_test3.results.append(TestResultFactory.build())
     self.load_test3.results.append(
         TestResultFactory.build(config=self.config))
     self.load_test3.save()
Exemple #3
0
    def test_list_load_tests_by_team_and_project(self):
        team = TeamFactory.create(owner=self.user)
        TeamFactory.add_projects(team, 1)
        project = team.projects[0]
        LoadTestFactory.add_to_project(25, user=self.user, team=team, project=project)

        load_tests = LoadTest.get_sliced_by_team_and_project_name(team, project.name, 20)
        uuids = _get_print_lines_for_load_tests(load_tests)

        result = self.execute("list", team=team.name, project=project.name)
        expect(result).to_be_like(BASE_LOAD_TESTS_TABLE_PRINT % (team.name, project.name, "".join(uuids)))
    def test_cant_create_a_load_test_if_not_team_owner_or_team_member(self):
        try:
            LoadTestFactory.create(
                created_by=UserFactory.create(),
                team=self.team,
                project_name=self.project.name
            )
        except ValueError:
            exc = sys.exc_info()[1]
            expect(str(exc)).to_include("Only the owner or members of team %s can create tests for it." % self.team.name)
            return

        assert False, "Should not have gotten this far"
 def _add_results(self):
     self.load_test.results.append(TestResultFactory.build())
     self.load_test.results.append(TestResultFactory.build(config=self.config))
     self.load_test.results.append(TestResultFactory.build())
     self.load_test.save()
     self.load_test2 = LoadTestFactory.add_to_project(1, user=self.user, team=self.team, project=self.project, status="Finished")
     self.load_test2.results.append(TestResultFactory.build())
     self.load_test2.results.append(TestResultFactory.build(config=self.config))
     self.load_test2.save()
     self.load_test3 = LoadTestFactory.add_to_project(1, user=self.user, team=self.team, project=self.team.projects[1], status="Finished")
     self.load_test3.results.append(TestResultFactory.build())
     self.load_test3.results.append(TestResultFactory.build(config=self.config))
     self.load_test3.save()
Exemple #6
0
    def test_get_load_tests_with_20_by_default_if_quantity_was_empty(self):
        LoadTestFactory.add_to_project(24, user=self.user, team=self.team, project=self.project)
        url = "/teams/%s/projects/%s/load_tests/?quantity=" % (self.team.name, self.project.name)
        response = self.fetch_with_headers(url)
        expect(response.code).to_equal(200)

        obj = response.body
        if isinstance(obj, six.binary_type):
            obj = obj.decode('utf-8')

        obj = loads(obj)
        expect(obj).to_length(20)
        load_test = LoadTest.objects(team=self.team, project_name=self.project.name).first()
        expect(obj[0]).to_be_like(load_test.to_dict())
Exemple #7
0
    def test_can_run_project(self):
        temp_path = mkdtemp()

        team = TeamFactory.create(name="teste")
        TeamFactory.add_projects(team, 1)
        user = team.owner
        project = team.projects[0]
        project.repository = "git://github.com/heynemann/wight.git"
        load_test = LoadTestFactory.add_to_project(1,
                                                   user=user,
                                                   team=team,
                                                   project=project,
                                                   base_url=self.base_url)

        runner = BenchRunner()
        runner.run_project_tests(temp_path, str(load_test.uuid), duration=1)

        loaded = LoadTest.objects(uuid=load_test.uuid).first()

        expect(loaded).not_to_be_null()
        expect(loaded.status).to_equal("Finished")

        expect(loaded.results).to_length(2)

        expect(loaded.results[0].log).not_to_be_null()
        expect(loaded.results[0].status).to_equal("Successful")
Exemple #8
0
    def test_can_create_commit(self):
        load_test = LoadTestFactory.create()

        retrieved = LoadTest.objects(id=load_test.id).first()
        commit = retrieved.last_commit
        expect(commit).not_to_be_null()
        expect(commit.hex).to_equal(load_test.last_commit.hex)
Exemple #9
0
    def test_can_create_commit(self):
        load_test = LoadTestFactory.create()

        retrieved = LoadTest.objects(id=load_test.id).first()
        commit = retrieved.last_commit
        expect(commit).not_to_be_null()
        expect(commit.hex).to_equal(load_test.last_commit.hex)
Exemple #10
0
    def test_can_run_simple_project(self):
        temp_path = mkdtemp()
        team = TeamFactory.create()
        TeamFactory.add_projects(team, 1)
        user = team.owner
        project = team.projects[0]
        load_test = LoadTestFactory.add_to_project(1,
                                                   user=user,
                                                   team=team,
                                                   project=project,
                                                   base_url="%s/healthcheck" %
                                                   self.base_url,
                                                   simple=True)

        runner = BenchRunner()
        runner.run_project_tests(temp_path, str(load_test.uuid), duration=1)

        loaded = LoadTest.objects(uuid=load_test.uuid).first()

        expect(loaded).not_to_be_null()
        expect(loaded.status).to_equal("Finished")

        expect(loaded.results).to_length(1)

        expect(loaded.results[0].log).not_to_be_null()
        expect(loaded.results[0].status).to_equal("Successful")
        expect(loaded.results[0].config.module).to_equal("test_simple")
        expect(loaded.results[0].config.class_name).to_equal("SimpleTestTest")
        expect(loaded.results[0].config.test_name).to_equal("test_simple")
Exemple #11
0
    def test_load_test_instance(self):
        team = TeamFactory.create(owner=self.user)
        project = team.add_project("load-test-instace-acc-1", "repo", self.user)
        load_test = LoadTestFactory.create(created_by=team.owner, team=team, project_name=project.name)
        result1 = TestResultFactory.build()
        result2 = TestResultFactory.build()
        load_test.results.append(result1)
        load_test.results.append(result2)
        load_test.save()

        result = self.execute("show", load_test.uuid)
        expected_text = [
            result1.config.title,
            result1.cycles[-1].concurrent_users,
            result1.cycles[-1].request.successful_requests_per_second,
            result1.cycles[-1].request.p95,
            result1.cycles[-1].request.failed_requests,
            result1.uuid,

            result2.config.title,
            result2.cycles[-1].concurrent_users,
            result2.cycles[-1].request.successful_requests_per_second,
            result2.cycles[-1].request.p95,
            result2.cycles[-1].request.failed_requests,
            result2.uuid,
            load_test.uuid,
            load_test.status
        ]

        for expected in expected_text:
            expect(result).to_include(expected)
Exemple #12
0
    def test_can_run_funkload(self):
        team = TeamFactory.create()
        TeamFactory.add_projects(team, 1)
        user = team.owner
        project = team.projects[0]
        load_test = LoadTestFactory.add_to_project(1, user=user, team=team, project=project)
        load_test.pressure = "small"

        conf = WightConfig.load(join(root_path, 'bench', 'wight.yml'))
        test = conf.tests[0]

        DEFAULT_CYCLES = {
            "small": [10, 20],
            "medium": [10, 20, 30],
            "large": [30, 75, 100],
        }

        fl_result = FunkLoadBenchRunner.run(root_path, test, self.base_url, cycles=DEFAULT_CYCLES, duration=5)

        expect(fl_result).not_to_be_null()
        expect(fl_result.exit_code).to_equal(0)

        expect(fl_result.text).to_include("SUCCESSFUL")

        expect(fl_result.log).to_be_empty()

        expect(fl_result.result).not_to_be_null()
        expect(fl_result.config).not_to_be_null()

        result = LoadTest.get_data_from_funkload_results(fl_result.config, fl_result.result)

        load_test.add_result(result, fl_result.text)

        expect(load_test.results).to_length(1)
 def test_get_last_3_load_tests_for_all_projects_when_owner(self):
     LoadTestFactory.add_to_project(4, user=self.user, team=self.team, project=self.project)
     LoadTestFactory.add_to_project(4, user=self.user, team=self.team, project=self.team.projects[1])
     team = TeamFactory.create(owner=self.user)
     TeamFactory.add_projects(team, 1)
     LoadTestFactory.add_to_project(4, user=self.user, team=team, project=team.projects[0])
     LoadTestFactory.add_to_project(4, user=UserFactory.create())
     loaded_tests = list(LoadTest.get_by_user(self.user))
     expect(loaded_tests).to_length(9)
Exemple #14
0
def main(args=None):
    if args is None:
        args = sys.argv[1:]

    parser = argparse.ArgumentParser()
    parser.add_argument('--conf', '-c', default=DEFAULT_CONFIG_PATH, help="Path to configuration file.")
    options = parser.parse_args(args)

    config = Config.load(path=options.conf, conf_name=split(options.conf)[-1], lookup_paths=[
        os.curdir,
        expanduser('~'),
        '/etc/',
    ])

    connect(
        config.MONGO_DB,
        host=config.MONGO_HOST,
        port=config.MONGO_PORT,
        username=config.MONGO_USER,
        password=config.MONGO_PASS
    )

    user = UserFactory.create()
    team = TeamFactory.create(owner=user)
    TeamFactory.add_projects(team, 1)
    project = team.projects[0]
    config = TestConfigurationFactory.build()
    load_test1 = LoadTestFactory.add_to_project(1, user=user, team=team, project=project)
    load_test1.results.append(TestResultFactory.build(config=config))
    load_test1.save()
    print "load test 1: %s" % load_test1.uuid
    print "test result for load test 1: %s" % load_test1.results[0].uuid
    load_test2 = LoadTestFactory.add_to_project(1, user=user, team=team, project=project)
    load_test2.results.append(TestResultFactory.build(config=config))
    load_test2.results.append(TestResultFactory.build())
    load_test2.save()
    load_test3 = LoadTestFactory.add_to_project(1, user=user, team=team, project=project)
    load_test3.results.append(TestResultFactory.build(config=config))
    load_test3.save()
    load_test4 = LoadTestFactory.add_to_project(1, user=user, team=team, project=project)
    load_test4.results.append(TestResultFactory.build(config=config))
    load_test4.save()
    print "load test 2: %s" % load_test2.uuid
    print "test result 1 for load test 2: %s" % load_test2.results[0].uuid
    print "test result 2 for load test 2: %s" % load_test2.results[1].uuid
    print "url for trend: %s/%s/%s/%s/%s/" % (team.name, project.name, config.module, config.class_name, config.test_name)
 def _add_results_for_last(self):
     config = TestConfigurationFactory.build()
     self.load_test.results.append(TestResultFactory.build(config=config))
     self.load_test.results.append(TestResultFactory.build())
     self.load_test.save()
     self.load_test2 = LoadTestFactory.add_to_project(1, user=self.user, team=self.team, project=self.project, status="Finished")
     self.load_test2.results.append(TestResultFactory.build())
     self.load_test2.results.append(TestResultFactory.build(config=config))
     self.load_test2.save()
    def test_get_last_result_for_diff_only_for_same_project(self):
        config = TestConfigurationFactory.build()
        self.load_test.results.append(TestResultFactory.build(config=config))
        self.load_test.results.append(TestResultFactory.build())
        self.load_test.save()
        load_test3 = LoadTestFactory.add_to_project(1, user=self.user, team=self.team, project=self.team.projects[1], status="Finished")
        load_test3.results.append(TestResultFactory.build(config=config))
        load_test3.save()
        load_test2 = LoadTestFactory.add_to_project(1, user=self.user, team=self.team, project=self.project, status="Finished")
        load_test2.results.append(TestResultFactory.build())
        load_test2.results.append(TestResultFactory.build(config=config))
        load_test2.save()

        result1 = self.load_test.results[0]
        result2 = load_test2.results[1]

        test_result = LoadTest.get_last_result_for(str(result2.uuid))
        expect(str(test_result.uuid)).to_equal(str(result1.uuid))
 def setUp(self):
     super(LoadTestsInstanceTest, self).setUp()
     self.user = UserFactory.create(with_token=True)
     self.team = TeamFactory.create(owner=self.user)
     self.project = self.team.add_project("schedule-test-project-1", "repo",
                                          self.user)
     self.load_test = LoadTestFactory.create(created_by=self.team.owner,
                                             team=self.team,
                                             project_name=self.project.name)
Exemple #18
0
    def test_list_load_tests_by_user_only(self):
        team1 = TeamFactory.create(owner=self.user)
        team2 = TeamFactory.create(owner=self.user)
        TeamFactory.add_projects(team1, 2)
        TeamFactory.add_projects(team2, 3)

        project1 = team1.projects[0]
        project2 = team1.projects[1]

        project3 = team2.projects[0]
        project4 = team2.projects[1]
        project5 = team2.projects[2]

        LoadTestFactory.add_to_project(4, user=self.user, team=team1, project=project1)
        LoadTestFactory.add_to_project(4, user=self.user, team=team1, project=project2)

        LoadTestFactory.add_to_project(4, user=self.user, team=team2, project=project3)
        LoadTestFactory.add_to_project(4, user=self.user, team=team2, project=project4)
        LoadTestFactory.add_to_project(4, user=self.user, team=team2, project=project5)

        load_tests1 = LoadTest.get_sliced_by_team_and_project_name(team1, project1.name, 3)
        load_tests2 = LoadTest.get_sliced_by_team_and_project_name(team1, project2.name, 3)

        load_tests3 = LoadTest.get_sliced_by_team_and_project_name(team2, project3.name, 3)
        load_tests4 = LoadTest.get_sliced_by_team_and_project_name(team2, project4.name, 3)
        load_tests5 = LoadTest.get_sliced_by_team_and_project_name(team2, project5.name, 3)

        uuids1 = _get_print_lines_for_load_tests(load_tests1)
        uuids2 = _get_print_lines_for_load_tests(load_tests2)

        uuids3 = _get_print_lines_for_load_tests(load_tests3)
        uuids4 = _get_print_lines_for_load_tests(load_tests4)
        uuids5 = _get_print_lines_for_load_tests(load_tests5)

        result = self.execute("list")

        expect(result).to_be_like((BASE_LOAD_TESTS_TABLE_PRINT * 5) % (
            team1.name, project1.name, "".join(uuids1),
            team1.name, project2.name, "".join(uuids2),
            team2.name, project3.name, "".join(uuids3),
            team2.name, project4.name, "".join(uuids4),
            team2.name, project5.name, "".join(uuids5)
        ))
 def setUp(self):
     super(ShowAuthLoadTestResultTest, self).setUp()
     self.user = UserFactory.create(with_token=True)
     self.team = TeamFactory.create(owner=self.user)
     TeamFactory.add_projects(self.team, 1)
     self.project = self.team.projects[0]
     self.load_test = LoadTestFactory.create(created_by=self.user, team=self.team, project_name=self.project.name)
     self.load_test.results.append(TestResultFactory.build())
     self.load_test.save()
     self.result = self.load_test.results[0]
 def setUp(self):
     super(ShowLoadLastTestResultTest, self).setUp()
     self.user = UserFactory.create(with_token=True)
     self.team = TeamFactory.create(owner=self.user)
     TeamFactory.add_projects(self.team, 1)
     self.project = self.team.projects[0]
     self.load_test = LoadTestFactory.create(created_by=self.user, team=self.team, project_name=self.project.name, status="Finished")
     self.load_test.results.append(TestResultFactory.build())
     self.load_test.save()
     self.result = self.load_test.results[0]
Exemple #21
0
    def test_get_load_tests_with_20_by_default_if_quantity_was_empty(self):
        LoadTestFactory.add_to_project(24,
                                       user=self.user,
                                       team=self.team,
                                       project=self.project)
        url = "/teams/%s/projects/%s/load_tests/?quantity=" % (
            self.team.name, self.project.name)
        response = self.fetch_with_headers(url)
        expect(response.code).to_equal(200)

        obj = response.body
        if isinstance(obj, six.binary_type):
            obj = obj.decode('utf-8')

        obj = loads(obj)
        expect(obj).to_length(20)
        load_test = LoadTest.objects(team=self.team,
                                     project_name=self.project.name).first()
        expect(obj[0]).to_be_like(load_test.to_dict())
 def setUp(self):
     super(ShowTestResultForTeamProjectAndTestTest, self).setUp()
     self.user = UserFactory.create(with_token=True)
     self.team = TeamFactory.create(owner=self.user)
     TeamFactory.add_projects(self.team, 2)
     self.project = self.team.projects[0]
     self.load_test = LoadTestFactory.create(created_by=self.user, team=self.team, project_name=self.project.name, status="Finished")
     self.load_test.save()
     self.config = TestConfigurationFactory.build()
     self.config2 = TestConfigurationFactory.build()
Exemple #23
0
    def test_list_load_tests_by_team_only(self):
        team = TeamFactory.create(owner=self.user)
        TeamFactory.add_projects(team, 2)
        project1 = team.projects[0]
        project2 = team.projects[1]
        LoadTestFactory.add_to_project(7, user=self.user, team=team, project=project1)
        LoadTestFactory.add_to_project(7, user=self.user, team=team, project=project2)

        load_tests1 = LoadTest.get_sliced_by_team_and_project_name(team, project1.name, 5)
        load_tests2 = LoadTest.get_sliced_by_team_and_project_name(team, project2.name, 5)

        uuids1 = _get_print_lines_for_load_tests(load_tests1)
        uuids2 = _get_print_lines_for_load_tests(load_tests2)

        result = self.execute("list", team=team.name)

        expect(result).to_be_like((BASE_LOAD_TESTS_TABLE_PRINT * 2) % (
            team.name, project1.name, "".join(uuids1),
            team.name, project2.name, "".join(uuids2)
        ))
Exemple #24
0
    def test_to_dict(self):
        load_test = LoadTestFactory.create()
        commit = load_test.last_commit
        json = commit.to_dict()

        expected_committer = {'name': u'Committer Name', 'email': u'Committer Name'}
        expected_author = {'name': u'Author Name', 'email': u'*****@*****.**'}

        expect(json['message']).to_equal(commit.commit_message)
        expect(json['hex']).to_equal('b64df0e7cdd3bcd099c4e43001f6c87efd81d417')
        expect(json['author']).to_be_like(expected_author)
        expect(json['committer']).to_be_like(expected_committer)
Exemple #25
0
    def test_can_git_clone_in_specific_branch(self, run_config_mock, load_config_mock, validate_mock, save_mock, clone_mock):
        team = TeamFactory.create()
        TeamFactory.add_projects(team, 1)
        user = team.owner
        project = team.projects[0]
        load_test = LoadTestFactory.add_to_project(1, user=user, team=team, project=project, branch="test")

        runner = BenchRunner()
        runner.run_project_tests("some-path-doesnt-matter", str(load_test.uuid), duration=1)
        expect(clone_mock.call_args_list[0][1]['branch']).to_be_like(
            "test"
        )
Exemple #26
0
    def test_can_git_clone_in_specific_branch(
        self, run_config_mock, load_config_mock, validate_mock, save_mock, clone_mock
    ):
        team = TeamFactory.create()
        TeamFactory.add_projects(team, 1)
        user = team.owner
        project = team.projects[0]
        load_test = LoadTestFactory.add_to_project(1, user=user, team=team, project=project, branch="test")

        runner = BenchRunner()
        runner.run_project_tests("some-path-doesnt-matter", str(load_test.uuid), duration=1)
        expect(clone_mock.call_args_list[0][1]["branch"]).to_be_like("test")
Exemple #27
0
 def setUp(self):
     super(ShowTestResultForTeamProjectAndTestTest, self).setUp()
     self.user = UserFactory.create(with_token=True)
     self.team = TeamFactory.create(owner=self.user)
     TeamFactory.add_projects(self.team, 2)
     self.project = self.team.projects[0]
     self.load_test = LoadTestFactory.create(created_by=self.user,
                                             team=self.team,
                                             project_name=self.project.name,
                                             status="Finished")
     self.load_test.save()
     self.config = TestConfigurationFactory.build()
     self.config2 = TestConfigurationFactory.build()
Exemple #28
0
 def _add_results_for_last(self):
     config = TestConfigurationFactory.build()
     self.load_test.results.append(TestResultFactory.build(config=config))
     self.load_test.results.append(TestResultFactory.build())
     self.load_test.save()
     self.load_test2 = LoadTestFactory.add_to_project(1,
                                                      user=self.user,
                                                      team=self.team,
                                                      project=self.project,
                                                      status="Finished")
     self.load_test2.results.append(TestResultFactory.build())
     self.load_test2.results.append(TestResultFactory.build(config=config))
     self.load_test2.save()
    def test_get_results_for_team_project_and_test_get_finished_only(self):
        config = TestConfigurationFactory.build()
        self.load_test.results.append(TestResultFactory.build(config=config))
        self.load_test.results.append(TestResultFactory.build())
        self.load_test.results.append(TestResultFactory.build(config=config))
        self.load_test.save()
        load_test2 = LoadTestFactory.add_to_project(1, user=self.user, team=self.team, project=self.project, status="Failed")
        load_test2.results.append(TestResultFactory.build())
        load_test2.results.append(TestResultFactory.build(config=config))
        load_test2.save()
        load_test3 = LoadTestFactory.add_to_project(1, user=self.user, team=self.team, project=self.project)
        load_test3.results.append(TestResultFactory.build())
        load_test3.results.append(TestResultFactory.build(config=config))
        load_test3.save()

        results = [str(result.uuid) for result in LoadTest.get_same_results_for_all_load_tests_from_project(self.team, self.project.name, config.module, config.class_name, config.test_name)]

        expected_results = [
            str(self.load_test.results[0].uuid),
            str(self.load_test.results[2].uuid),
        ]

        expect(results).to_be_like(expected_results)
    def test_fail_if_yaml_not_exists(self, clone_repo_mock):
        clone_repo_mock.return_value = None
        temp_path = mkdtemp()
        os.mkdir(os.path.join(temp_path, "bench"))
        load_test = LoadTestFactory.add_to_project(1, base_url=self.base_url)

        runner = BenchRunner()
        runner.run_project_tests(temp_path, str(load_test.uuid), cycles=[1, 2], duration=1)

        loaded = LoadTest.objects(uuid=load_test.uuid).first()

        expect(loaded).not_to_be_null()
        expect(loaded.status).to_equal("Failed")
        expect(loaded.error).to_equal("The wight.yml file was not found in project repository bench folder.")
 def test_can_create_a_load_test_if_team_owner(self):
     test = LoadTestFactory.create(
         created_by=self.user,
         team=self.team,
         project_name=self.project.name
     )
     retrieveds = LoadTest.objects(id=test.id)
     expect(retrieveds.count()).to_equal(1)
     retrieved = retrieveds.first()
     expect(retrieved.status).to_equal("Scheduled")
     expect(retrieved.created_by.email).to_equal(self.user.email)
     expect(retrieved.team.name).to_equal(self.team.name)
     expect(retrieved.project_name).to_equal(self.project.name)
     expect(retrieved.date_created).to_be_like(test.date_created)
     expect(retrieved.date_modified).to_be_like(test.date_modified)
 def test_get_last_5_tests_for_a_team_ordered_by_date_created_desc(self):
     LoadTestFactory.add_to_project(7, user=self.user, team=self.team, project=self.project)
     LoadTestFactory.add_to_project(6, user=self.user, team=self.team, project=self.team.projects[1])
     LoadTestFactory.add_to_project(6, user=self.user)
     loaded_tests = list(LoadTest.get_by_team(self.team))
     expect(loaded_tests).to_length(10)
     load_tests_for_project1 = [load_test for load_test in loaded_tests if load_test.project_name == self.project.name]
     expect(load_tests_for_project1).to_length(5)
     another_project_name = self.team.projects[1].name
     load_tests_for_project2 = [load_test for load_test in loaded_tests if load_test.project_name == another_project_name]
     expect(load_tests_for_project2).to_length(5)
Exemple #33
0
    def test_fail_if_yaml_not_exists(self, clone_repo_mock):
        clone_repo_mock.return_value = None
        temp_path = mkdtemp()
        os.mkdir(os.path.join(temp_path, "bench"))
        load_test = LoadTestFactory.add_to_project(1, base_url=self.base_url)

        runner = BenchRunner()
        runner.run_project_tests(temp_path,
                                 str(load_test.uuid),
                                 cycles=[1, 2],
                                 duration=1)

        loaded = LoadTest.objects(uuid=load_test.uuid).first()

        expect(loaded).not_to_be_null()
        expect(loaded.status).to_equal("Failed")
        expect(loaded.error).to_equal(
            "The wight.yml file was not found in project repository bench folder."
        )
    def test_can_parse_stats_from_funkload_result(self):
        test = LoadTestFactory.add_to_project(1, user=self.user, team=self.team, project=self.project)

        config = FunkLoadTestResultFactory.get_config()
        cycles = FunkLoadTestResultFactory.get_result(4)

        result = LoadTest.get_data_from_funkload_results(config, cycles)

        test.add_result(result, "log")

        loaded_test = LoadTest.objects(uuid=test.uuid).first()

        expect(loaded_test).not_to_be_null()

        expect(loaded_test.results).to_length(1)

        result = loaded_test.results[0]

        expect(result.cycles).to_length(4)

        cycle = result.cycles[0]

        expect(cycle.test.successful_tests_per_second).to_equal(20.30394)
        expect(cycle.test.total_tests).to_equal(200)
        expect(cycle.test.successful_tests).to_equal(300)
        expect(cycle.test.failed_tests).to_equal(0)
        expect(cycle.test.failed_tests_percentage).to_equal(0)

        expect(cycle.page.apdex).to_equal(0.993)
        expect(cycle.page.successful_pages_per_second).to_equal(35.2)
        expect(cycle.page.maximum_successful_pages_per_second).to_equal(44.0)

        expect(cycle.page.total_pages).to_equal(200)
        expect(cycle.page.successful_pages).to_equal(300)
        expect(cycle.page.failed_pages).to_equal(0)

        expect(cycle.page.minimum).to_equal(0.123)
        expect(cycle.page.average).to_equal(0.234)
        expect(cycle.page.maximum).to_equal(0.384)
        expect(cycle.page.p10).to_equal(1.0)
        expect(cycle.page.p50).to_equal(1.0)
        expect(cycle.page.p90).to_equal(1.0)
        expect(cycle.page.p95).to_equal(1.0)
Exemple #35
0
    def test_to_dict(self):
        load_test = LoadTestFactory.create()
        commit = load_test.last_commit
        json = commit.to_dict()

        expected_committer = {
            'name': u'Committer Name',
            'email': u'Committer Name'
        }
        expected_author = {
            'name': u'Author Name',
            'email': u'*****@*****.**'
        }

        expect(json['message']).to_equal(commit.commit_message)
        expect(
            json['hex']).to_equal('b64df0e7cdd3bcd099c4e43001f6c87efd81d417')
        expect(json['author']).to_be_like(expected_author)
        expect(json['committer']).to_be_like(expected_committer)
Exemple #36
0
    def test_can_run_funkload(self):
        team = TeamFactory.create()
        TeamFactory.add_projects(team, 1)
        user = team.owner
        project = team.projects[0]
        load_test = LoadTestFactory.add_to_project(1,
                                                   user=user,
                                                   team=team,
                                                   project=project)
        load_test.pressure = "small"

        conf = WightConfig.load(join(root_path, 'bench', 'wight.yml'))
        test = conf.tests[0]

        DEFAULT_CYCLES = {
            "small": [10, 20],
            "medium": [10, 20, 30],
            "large": [30, 75, 100],
        }

        fl_result = FunkLoadBenchRunner.run(root_path,
                                            test,
                                            self.base_url,
                                            cycles=DEFAULT_CYCLES,
                                            duration=5)

        expect(fl_result).not_to_be_null()
        expect(fl_result.exit_code).to_equal(0)

        expect(fl_result.text).to_include("SUCCESSFUL")

        expect(fl_result.log).to_be_empty()

        expect(fl_result.result).not_to_be_null()
        expect(fl_result.config).not_to_be_null()

        result = LoadTest.get_data_from_funkload_results(
            fl_result.config, fl_result.result)

        load_test.add_result(result, fl_result.text)

        expect(load_test.results).to_length(1)
    def test_can_parse_configuration_from_funkload_result(self):
        test = LoadTestFactory.add_to_project(1, user=self.user, team=self.team, project=self.project)

        config = FunkLoadTestResultFactory.get_config()
        cycles = FunkLoadTestResultFactory.get_result(4)

        result = LoadTest.get_data_from_funkload_results(config, cycles)

        test.add_result(result, "log")

        loaded_test = LoadTest.objects(uuid=test.uuid).first()

        expect(loaded_test).not_to_be_null()

        expect(loaded_test.results).to_length(1)

        result = loaded_test.results[0]

        expect(result.log).to_equal("log")

        cfg = result.config

        expect(cfg.title).to_equal(config['class_title'])
        expect(cfg.description).to_equal(config['class_description'])

        expect(cfg.module).to_equal(config['module'])
        expect(cfg.class_name).to_equal(config['class'])
        expect(cfg.test_name).to_equal(config['method'])

        expect(cfg.target_server).to_equal(config['server_url'])
        expect(cfg.cycles).to_equal(config['cycles'])
        expect(cfg.cycle_duration).to_equal(int(config['duration']))

        expect(cfg.sleep_time).to_equal(float(config['sleep_time']))
        expect(cfg.sleep_time_min).to_equal(float(config['sleep_time_min']))
        expect(cfg.sleep_time_max).to_equal(float(config['sleep_time_max']))

        expect(cfg.startup_delay).to_equal(float(config['startup_delay']))

        expect(cfg.test_date.isoformat()[:20]).to_equal(config['time'][:20])
        expect(cfg.funkload_version).to_equal(config['version'])
    def test_can_run_project(self):
        temp_path = mkdtemp()

        team = TeamFactory.create()
        TeamFactory.add_projects(team, 1)
        user = team.owner
        project = team.projects[0]
        project.repository = "git://github.com/heynemann/wight.git"
        load_test = LoadTestFactory.add_to_project(1, user=user, team=team, project=project, base_url=self.base_url)

        runner = BenchRunner()
        runner.run_project_tests(temp_path, str(load_test.uuid), duration=1)

        loaded = LoadTest.objects(uuid=load_test.uuid).first()

        expect(loaded).not_to_be_null()
        expect(loaded.status).to_equal("Finished")

        expect(loaded.results).to_length(1)

        expect(loaded.results[0].log).not_to_be_null()
        expect(loaded.results[0].status).to_equal("Successful")
 def test_to_dict(self):
     test = LoadTestFactory.create(
         created_by=self.user,
         team=self.team,
         project_name=self.project.name,
         base_url="http://some-server.com/some-url"
     )
     retrieved = LoadTest.objects(id=test.id).first()
     expect(retrieved.to_dict()).to_be_like(
         {
             "baseUrl": "http://some-server.com/some-url",
             "uuid": str(test.uuid),
             "createdBy": self.user.email,
             "team": self.team.name,
             "project": self.project.name,
             "status": test.status,
             "created": test.date_created.isoformat()[:19],
             "lastModified": test.date_modified.isoformat()[:19],
             "lastCommit": test.last_commit.to_dict(),
             "gitBranch": test.git_branch,
             "results": []
         }
     )
    def test_can_run_simple_project(self):
        temp_path = mkdtemp()
        team = TeamFactory.create()
        TeamFactory.add_projects(team, 1)
        user = team.owner
        project = team.projects[0]
        load_test = LoadTestFactory.add_to_project(1, user=user, team=team, project=project, base_url="%s/healthcheck" % self.base_url, simple=True)

        runner = BenchRunner()
        runner.run_project_tests(temp_path, str(load_test.uuid), duration=1)

        loaded = LoadTest.objects(uuid=load_test.uuid).first()

        expect(loaded).not_to_be_null()
        expect(loaded.status).to_equal("Finished")

        expect(loaded.results).to_length(1)

        expect(loaded.results[0].log).not_to_be_null()
        expect(loaded.results[0].status).to_equal("Successful")
        expect(loaded.results[0].config.module).to_equal("test_simple")
        expect(loaded.results[0].config.class_name).to_equal("SimpleTestTest")
        expect(loaded.results[0].config.test_name).to_equal("test_simple")
    def test_can_run_project_with_two_test(self, build_mock):
        simple_test_content = """
import unittest
from funkload.FunkLoadTestCase import FunkLoadTestCase


class SimpleTestTest(FunkLoadTestCase):
    def setUp(self):
        self.server_url = '%s/healthcheck' % (self.conf_get('main', 'url').rstrip('/'),)

    def test_simple(self):
        self.get(self.server_url, description='Get url')

if __name__ == '__main__':
    unittest.main()

"""

        healthcheck_content = """
import unittest
from funkload.FunkLoadTestCase import FunkLoadTestCase


class HealthCheckTest(FunkLoadTestCase):
    def setUp(self):
        self.server_url = '%s/healthcheck' % (self.conf_get('main', 'url').rstrip('/'),)

    def test_healthcheck(self):
        self.get(self.server_url, description='Get url')

if __name__ == '__main__':
    unittest.main()

"""
        cfg_text = """
tests:
  -
    module: test_healthcheck.py
    class: HealthCheckTest
    test: test_healthcheck
  -
    module: test_simple.py
    class: SimpleTestTest
    test: test_simple
"""

        build_mock.return_value = WightConfig(cfg_text)

        team = TeamFactory.create()
        TeamFactory.add_projects(team, 1)
        user = team.owner
        project = team.projects[0]
        load_test = LoadTestFactory.add_to_project(1, user=user, team=team, project=project, base_url=self.base_url, simple=True)

        temp_path = mkdtemp()

        mkdir(join(temp_path, "bench"))
        init_file = open(join(temp_path, "bench/__init__.py"), "w")
        init_file.close()
        wight_file = open(join(temp_path, "bench/wight.yml"), "w")
        wight_file.write(cfg_text)
        wight_file.close()

        simple_file = open(join(temp_path, "bench/test_simple.py"), "w")
        simple_file.write(simple_test_content)
        simple_file.close()

        healthcheck_file = open(join(temp_path, "bench/test_healthcheck.py"), "w")
        healthcheck_file.write(healthcheck_content)
        healthcheck_file.close()

        runner = BenchRunner()
        runner.run_project_tests(temp_path, str(load_test.uuid), duration=1)

        loaded = LoadTest.objects(uuid=load_test.uuid).first()
        expect(loaded).not_to_be_null()
        expect(loaded.status).to_equal("Finished")

        expect(loaded.results).to_length(2)

        expect(loaded.results[0].log).not_to_be_null()
        expect(loaded.results[0].status).to_equal("Successful")
        expect(loaded.results[0].config.module).to_equal("test_healthcheck")

        expect(loaded.results[1].log).not_to_be_null()
        expect(loaded.results[1].status).to_equal("Successful")
        expect(loaded.results[1].config.module).to_equal("test_simple")
 def setUp(self):
     self.user = UserFactory.create()
     self.team = TeamFactory.create(owner=self.user)
     TeamFactory.add_projects(self.team, 2)
     self.project = self.team.projects[0]
     self.load_test = LoadTestFactory.add_to_project(1, user=self.user, team=self.team, project=self.project, status="Finished")
 def setUp(self):
     super(LoadTestsInstanceTest, self).setUp()
     self.user = UserFactory.create(with_token=True)
     self.team = TeamFactory.create(owner=self.user)
     self.project = self.team.add_project("schedule-test-project-1", "repo", self.user)
     self.load_test = LoadTestFactory.create(created_by=self.team.owner, team=self.team, project_name=self.project.name)
Exemple #44
0
    def test_can_run_project_with_two_test(self, build_mock):
        simple_test_content = """
import unittest
from funkload.FunkLoadTestCase import FunkLoadTestCase


class SimpleTestTest(FunkLoadTestCase):
    def setUp(self):
        self.server_url = '%s/healthcheck' % (self.conf_get('main', 'url').rstrip('/'),)

    def test_simple(self):
        self.get(self.server_url, description='Get url')

if __name__ == '__main__':
    unittest.main()

"""

        healthcheck_content = """
import unittest
from funkload.FunkLoadTestCase import FunkLoadTestCase


class HealthCheckTest(FunkLoadTestCase):
    def setUp(self):
        self.server_url = '%s/healthcheck' % (self.conf_get('main', 'url').rstrip('/'),)

    def test_healthcheck(self):
        self.get(self.server_url, description='Get url')

if __name__ == '__main__':
    unittest.main()

"""
        cfg_text = """
tests:
  -
    module: test_healthcheck.py
    class: HealthCheckTest
    test: test_healthcheck
  -
    module: test_simple.py
    class: SimpleTestTest
    test: test_simple
"""

        build_mock.return_value = WightConfig(cfg_text)

        team = TeamFactory.create()
        TeamFactory.add_projects(team, 1)
        user = team.owner
        project = team.projects[0]
        load_test = LoadTestFactory.add_to_project(1,
                                                   user=user,
                                                   team=team,
                                                   project=project,
                                                   base_url=self.base_url,
                                                   simple=True)

        temp_path = mkdtemp()

        mkdir(join(temp_path, "bench"))
        init_file = open(join(temp_path, "bench/__init__.py"), "w")
        init_file.close()
        wight_file = open(join(temp_path, "bench/wight.yml"), "w")
        wight_file.write(cfg_text)
        wight_file.close()

        simple_file = open(join(temp_path, "bench/test_simple.py"), "w")
        simple_file.write(simple_test_content)
        simple_file.close()

        healthcheck_file = open(join(temp_path, "bench/test_healthcheck.py"),
                                "w")
        healthcheck_file.write(healthcheck_content)
        healthcheck_file.close()

        runner = BenchRunner()
        runner.run_project_tests(temp_path, str(load_test.uuid), duration=1)

        loaded = LoadTest.objects(uuid=load_test.uuid).first()
        expect(loaded).not_to_be_null()
        expect(loaded.status).to_equal("Finished")

        expect(loaded.results).to_length(2)

        expect(loaded.results[0].log).not_to_be_null()
        expect(loaded.results[0].status).to_equal("Successful")
        expect(loaded.results[0].config.module).to_equal("test_healthcheck")

        expect(loaded.results[1].log).not_to_be_null()
        expect(loaded.results[1].status).to_equal("Successful")
        expect(loaded.results[1].config.module).to_equal("test_simple")