コード例 #1
0
    def test_populate_worker_passes(self):
        user1 = User.objects.create_user('*****@*****.**', '*****@*****.**',
                                         'pass')
        user1.save()

        user2 = User.objects.create_user('*****@*****.**', '*****@*****.**',
                                         'pass')
        user2.save()

        git_project1 = GitProjectEntry.objects.create(url='http://test/')

        command_group = CommandGroupEntry.objects.create()
        command_set = CommandSetEntry.objects.create(group=command_group)

        bluesteel_layout = BluesteelLayoutEntry.objects.create(
            name='Layout', active=True, project_index_path=0)

        bluesteel_project = BluesteelProjectEntry.objects.create(
            name='Project',
            order=0,
            layout=bluesteel_layout,
            command_group=command_group,
            git_project=git_project1)

        benchmark_definition1 = BenchmarkDefinitionEntry.objects.create(
            name='BenchmarkDefinition1',
            layout=bluesteel_layout,
            project=bluesteel_project,
            command_set=command_set,
            revision=28)

        worker1 = WorkerEntry.objects.create(user=user1)
        worker2 = WorkerEntry.objects.create(user=user2)

        self.assertEqual(
            0,
            BenchmarkDefinitionWorkerPassEntry.objects.all().count())

        BenchmarkDefinitionController.populate_worker_passes_for_definition(
            benchmark_definition1)

        self.assertEqual(
            2,
            BenchmarkDefinitionWorkerPassEntry.objects.all().count())
        self.assertEqual(
            1,
            BenchmarkDefinitionWorkerPassEntry.objects.filter(
                definition__id=benchmark_definition1.id,
                worker__id=worker1.id).count())
        self.assertEqual(
            1,
            BenchmarkDefinitionWorkerPassEntry.objects.filter(
                definition__id=benchmark_definition1.id,
                worker__id=worker2.id).count())
コード例 #2
0
def create_worker_info(request):
    """ Creates a worker given its info """

    if request.method != 'POST':
        return res.get_only_post_allowed({})

    (json_valid, post_info) = val.validate_json_string(request.body)
    if not json_valid:
        return res.get_json_parser_failed(
            {}
        )

    (obj_validated, val_resp_obj) = val.validate_obj_schema(
        post_info,
        BluesteelWorkerSchemas.CREATE_WORKER_INFO_SCHEMA
    )
    if not obj_validated:
        return res.get_schema_failed(val_resp_obj)

    obj = val_resp_obj
    username_trimmed = obj['uuid'][:30]

    worker = WorkerEntry.objects.filter(uuid=username_trimmed).first()
    if worker is not None:
        return res.get_response(405, 'Worker already created', {})

    user = User.objects.filter(username=username_trimmed).first()
    if not user:
        user = User.objects.create_user(
            username=username_trimmed,
            email=None,
            password=obj['uuid']
        )
        user.save()

    worker_count = WorkerEntry.objects.all().count()

    new_worker = WorkerEntry.objects.create(
        uuid=obj['uuid'],
        name=obj['host_name'],
        operative_system=obj['operative_system'],
        user=user,
        git_feeder=(worker_count == 0)
    )
    new_worker.save()

    BenchmarkDefinitionController.populate_worker_passes_all_definitions()

    ret = {}
    ret['worker'] = new_worker.as_object()
    ret['worker']['url'] = get_worker_urls(request.get_host(), ret['worker']['id'], ret['worker']['uuid'])
    ret['worker']['last_update'] = str(ret['worker']['last_update'])

    return res.get_response(200, 'Worker created succesfuly!', ret)
コード例 #3
0
    def test_create_default_definition_commands(self):
        self.assertEqual(0, CommandGroupEntry.objects.all().count())
        self.assertEqual(0, CommandSetEntry.objects.all().count())
        self.assertEqual(0, CommandEntry.objects.all().count())
        self.assertEqual(0, CommandResultEntry.objects.all().count())

        BenchmarkDefinitionController.create_default_definition_commands()

        self.assertEqual(0, CommandGroupEntry.objects.all().count())
        self.assertEqual(1, CommandSetEntry.objects.all().count())
        self.assertEqual(3, CommandEntry.objects.all().count())
        self.assertEqual(0, CommandResultEntry.objects.all().count())
コード例 #4
0
    def test_is_benchmark_definition_equivalent_all(self):
        layout = BluesteelLayoutEntry.objects.create(name='default-name')
        project = BluesteelProjectController.create_default_project(
            layout, 'project', 0)
        definition = BenchmarkDefinitionController.create_default_benchmark_definition(
        )

        commands = self.get_default_commands()

        self.assertEqual(
            True,
            BenchmarkDefinitionController.is_benchmark_definition_equivalent(
                definition.id, layout.id, project.id, commands))
コード例 #5
0
def create_new_benchmark_definition(request):
    """ Creates a new benchmark defintion """
    if request.method != 'POST':
        return res.get_response(400, 'Only post allowed', {})

    definition = BenchmarkDefinitionController.create_default_benchmark_definition(
    )
    BenchmarkDefinitionController.populate_worker_passes_for_definition(
        definition)

    data = {}
    data['redirect'] = ViewUrlGenerator.get_benchmark_definitions_url(1)

    return res.get_response(200, 'Benchmark definition created', data)
コード例 #6
0
def view_save_benchmark_definition(request, benchmark_definition_id):
    """ Save benchmark definition properties """
    if request.method != 'POST':
        return res.get_only_post_allowed({})

    (json_valid_value, post_info) = val.validate_json_string(request.body)
    if not json_valid_value:
        return res.get_json_parser_failed({})

    (obj_validated, val_resp_obj) = val.validate_obj_schema(
        post_info, BenchmarkDefinitionSchemas.SAVE_BENCHMARK_DEFINITION)

    if not obj_validated:
        return res.get_schema_failed(val_resp_obj)

    bench_entry = BenchmarkDefinitionController.save_benchmark_definition(
        benchmark_definition_id=benchmark_definition_id,
        name=val_resp_obj['name'],
        layout_id=val_resp_obj['layout_id'],
        project_id=val_resp_obj['project_id'],
        priority=val_resp_obj['priority'],
        active=val_resp_obj['active'],
        command_list=val_resp_obj['command_list'],
        max_fluctuation_percent=val_resp_obj['max_fluctuation_percent'],
        overrides=val_resp_obj['overrides'],
        max_weeks_old_notify=val_resp_obj['max_weeks_old_notify'],
        work_passes=val_resp_obj['work_passes'],
    )

    if bench_entry is None:
        return res.get_response(404, 'Benchmark Defintion save error', {})

    return res.get_response(200, 'Benchmark Definition saved', {})
コード例 #7
0
    def setUp(self):
        self.client = Client()
        self.user1 = User.objects.create_user('*****@*****.**',
                                              '*****@*****.**', 'pass')

        self.git_project1 = GitProjectEntry.objects.create(url='http://test/')

        self.git_user1 = GitUserEntry.objects.create(project=self.git_project1,
                                                     name='user1',
                                                     email='*****@*****.**')

        self.commit1 = GitCommitEntry.objects.create(
            project=self.git_project1,
            commit_hash='0000100001000010000100001000010000100001',
            author=self.git_user1,
            author_date=timezone.now(),
            committer=self.git_user1,
            committer_date=timezone.now())

        self.worker1 = WorkerEntry.objects.create(
            name='worker-name-1',
            uuid='uuid-worker-1',
            operative_system='osx',
            description='long-description-1',
            user=self.user1,
            git_feeder=False)

        self.bluesteel_layout1 = BluesteelLayoutController.create_new_default_layout(
        )
        self.benchmark_definition1 = BenchmarkDefinitionController.create_default_benchmark_definition(
        )
コード例 #8
0
def get_benchmark_definition_edit(request, definition_id):
    """ Returns html for the benchmark definition edit page """
    data = {}
    data['menu'] = ViewPrepareObjects.prepare_menu_for_html([])
    data['controls'] = get_definition_controls()

    def_entry = BenchmarkDefinitionController.get_benchmark_definition(definition_id)

    if def_entry is None:
        return res.get_template_data(request, 'presenter/not_found.html', data)

    obj = def_entry
    obj['url'] = {}
    obj['url']['save'] = ViewUrlGenerator.get_save_benchmark_definition_url(definition_id)
    obj['url']['delete'] = ViewUrlGenerator.get_confirm_delete_benchmark_def_url(definition_id)
    obj['url']['project_info'] = ViewUrlGenerator.get_editable_projects_info_url()
    obj['layout_selection'] = get_layout_selection(def_entry['layout']['id'])
    obj['project_selection'] = get_project_selection(def_entry['layout']['id'], def_entry['project']['id'])

    names_and_sel = []
    count = 0
    for name in obj['priority']['names']:
        nas = {}
        nas['name'] = name
        nas['selected'] = obj['priority']['current'] == count
        count = count +1
        names_and_sel.append(nas)
    obj['priority']['names'] = names_and_sel


    data['definition'] = obj

    return res.get_template_data(request, 'presenter/benchmark_definition_edit.html', data)
コード例 #9
0
    def test_is_benchmark_definition_equivalent_commands(self):
        layout = BluesteelLayoutEntry.objects.create(name='default-name')
        project = BluesteelProjectController.create_default_project(
            layout, 'project', 0)
        definition = BenchmarkDefinitionController.create_default_benchmark_definition(
        )

        commands = []
        commands.append('command-28')
        commands.append('command-29')
        commands.append('command-30')

        self.assertEqual(
            False,
            BenchmarkDefinitionController.is_benchmark_definition_equivalent(
                definition.id, layout.id, project.id, commands))
コード例 #10
0
    def test_delete_benchmark_definition_also_deletes_benchmark_executions(
            self):
        layout = BluesteelLayoutController.create_new_default_layout()
        definition = BenchmarkDefinitionController.create_default_benchmark_definition(
        )

        BenchmarkExecutionController.create_benchmark_execution(
            definition, self.commit1, self.worker1)
        BenchmarkExecutionController.create_benchmark_execution(
            definition, self.commit2, self.worker1)
        BenchmarkExecutionController.create_benchmark_execution(
            definition, self.commit3, self.worker1)
        BenchmarkExecutionController.create_benchmark_execution(
            definition, self.commit1, self.worker2)
        BenchmarkExecutionController.create_benchmark_execution(
            definition, self.commit2, self.worker2)
        BenchmarkExecutionController.create_benchmark_execution(
            definition, self.commit3, self.worker2)

        self.assertEqual(6, BenchmarkExecutionEntry.objects.all().count())

        resp = self.client.post('/main/definition/{0}/delete/'.format(
            definition.id),
                                data='',
                                content_type='application/json')

        self.assertEqual(0, BenchmarkDefinitionEntry.objects.all().count())
        self.assertEqual(0, BenchmarkExecutionEntry.objects.all().count())
コード例 #11
0
def get_benchmark_definition(request, definition_id):
    """ Returns html for the benchmark definition page """
    data = {}
    data['menu'] = ViewPrepareObjects.prepare_menu_for_html([])
    data['controls'] = get_definition_controls()

    def_entry = BenchmarkDefinitionController.get_benchmark_definition(definition_id)

    if def_entry is None:
        return res.get_template_data(request, 'presenter/not_found.html', data)

    obj = def_entry
    obj['url'] = {}
    obj['url']['edit'] = ViewUrlGenerator.get_edit_benchmark_definition_url(definition_id)
    obj['url']['duplicate'] = ViewUrlGenerator.get_duplicate_benchmark_definition_url(definition_id)
    obj['url']['project_info'] = ViewUrlGenerator.get_editable_projects_info_url()
    obj['layout_selection'] = get_layout_selection(def_entry['layout']['id'])
    obj['project_selection'] = get_project_selection(def_entry['layout']['id'], def_entry['project']['id'])

    # Translate priority number to name.
    obj['priority']['name'] = obj['priority']['names'][obj['priority']['current']]

    data['definition'] = obj

    return res.get_template_data(request, 'presenter/benchmark_definition.html', data)
コード例 #12
0
 def test_create_default_benchmark_definition_without_layout_returns_nothing(
         self):
     self.assertEqual(0, BluesteelLayoutEntry.objects.all().count())
     self.assertEqual(0, BluesteelProjectEntry.objects.all().count())
     self.assertEqual(
         None,
         BenchmarkDefinitionController.create_default_benchmark_definition(
         ))
コード例 #13
0
def view_delete_benchmark_definition(request, benchmark_definition_id):
    """ Delete benchmark definition properties """
    if request.method != 'POST':
        return res.get_only_post_allowed({})

    ret = BenchmarkDefinitionController.delete_benchmark_definition(
        benchmark_definition_id=benchmark_definition_id)

    data = {}
    data['redirect'] = ViewUrlGenerator.get_benchmark_definitions_url(1)
    data['benchmark_definition_id'] = benchmark_definition_id

    if ret:
        return res.get_response(200, 'Benchmark Defintion deleted', data)

    return res.get_response(404, 'Benchmark Definition not found', data)
コード例 #14
0
def view_duplicate_benchmark_definition(request, benchmark_definition_id):
    """ Duplicate benchmark definition properties """
    if request.method != 'POST':
        return res.get_only_post_allowed({})

    dup_bench_entry = BenchmarkDefinitionController.duplicate_benchmark_definition(
        benchmark_definition_id)

    if dup_bench_entry is None:
        return res.get_response(404, 'Benchmark Defintion save error', {})

    data = {}
    data['redirect'] = ViewUrlGenerator.get_benchmark_definition_url(
        dup_bench_entry.id)

    return res.get_response(200, 'Benchmark Definition saved', data)
コード例 #15
0
    def test_save_benchmark_definition_with_longest_override_id_possible(self):
        layout = BluesteelLayoutController.create_new_default_layout()
        definition = BenchmarkDefinitionController.create_default_benchmark_definition(
        )

        project = BluesteelProjectEntry.objects.filter(layout=layout).first()

        long_id = 'a' * 255

        obj = {}
        obj['name'] = 'new-name-1'
        obj['layout_id'] = layout.id
        obj['project_id'] = project.id
        obj['priority'] = 3
        obj['active'] = True
        obj['max_fluctuation_percent'] = 28
        obj['max_weeks_old_notify'] = 8
        obj['command_list'] = []
        obj['command_list'].append('command-28')
        obj['overrides'] = []
        obj['overrides'].append({
            'result_id': long_id,
            'override_value': 28,
            'ignore_fluctuation': False
        })
        obj['work_passes'] = []

        resp = self.client.post('/main/definition/{0}/save/'.format(
            definition.id),
                                data=json.dumps(obj),
                                content_type='application/json')

        res.check_cross_origin_headers(self, resp)
        resp_obj = json.loads(resp.content)

        self.assertEqual(200, resp_obj['status'])

        self.assertEqual(
            1,
            BenchmarkFluctuationOverrideEntry.objects.all().count())
        self.assertEqual(
            1,
            BenchmarkFluctuationOverrideEntry.objects.filter(
                result_id=long_id, override_value=28).count())
        self.assertEqual(
            long_id,
            BenchmarkFluctuationOverrideEntry.objects.all().first().result_id)
コード例 #16
0
def get_benchmark_definition_all(request, page_index):
    """ Returns html for the benchmark definition page """

    (definitions, page_indices) = BenchmarkDefinitionController.get_benchmark_definitions_with_pagination(
        DEFINITION_ITEMS_PER_PAGE,
        page_index,
        PAGINATION_HALF_RANGE
    )

    for definition in definitions:
        definition['url'] = {}
        definition['url']['single'] = ViewUrlGenerator.get_benchmark_definition_url(definition['id'])

    data = {}
    data['definitions'] = definitions
    data['menu'] = ViewPrepareObjects.prepare_menu_for_html([])
    data['pagination'] = ViewPrepareObjects.prepare_pagination_bench_definitions(page_indices)
    data['controls'] = get_definition_controls()
    return res.get_template_data(request, 'presenter/benchmark_definition_all.html', data)
コード例 #17
0
    def test_create_default_benchmark_definition_without_projects_returns_nothing(
            self):
        self.assertEqual(0, CommandGroupEntry.objects.all().count())
        self.assertEqual(0, CommandSetEntry.objects.all().count())
        self.assertEqual(0, CommandEntry.objects.all().count())
        self.assertEqual(0, CommandResultEntry.objects.all().count())

        new_layout = BluesteelLayoutEntry.objects.create(name='default-name')
        project = BluesteelProjectController.create_default_project(
            new_layout, 'project', 0)
        definition = BenchmarkDefinitionController.create_default_benchmark_definition(
        )

        self.assertEqual(1, BluesteelLayoutEntry.objects.all().count())
        self.assertEqual(1, BluesteelProjectEntry.objects.all().count())
        self.assertNotEqual(None, definition.command_set)
        self.assertEqual(
            3,
            CommandEntry.objects.filter(
                command_set=definition.command_set).count())
        self.assertEqual(0, CommandResultEntry.objects.all().count())
コード例 #18
0
    def test_get_workes_only_associated_with_a_benchmark_definition(self):
        layout = BluesteelLayoutController.create_new_default_layout()
        definition = BenchmarkDefinitionController.create_default_benchmark_definition(
        )

        BenchmarkDefinitionWorkerPassEntry.objects.create(
            definition=definition, worker=self.worker1, allowed=True)
        BenchmarkDefinitionWorkerPassEntry.objects.create(
            definition=definition, worker=self.worker2, allowed=False)

        resp = self.client.get('/main/definition/{0}/workers/list/'.format(
            definition.id))

        res.check_cross_origin_headers(self, resp)
        resp_obj = json.loads(resp.content)

        self.assertEqual(1, len(resp_obj['data']['workers']))
        self.assertEqual(self.worker1.id, resp_obj['data']['workers'][0]['id'])
        self.assertEqual('worker-name-1',
                         resp_obj['data']['workers'][0]['name'])
        self.assertEqual('osx',
                         resp_obj['data']['workers'][0]['operative_system'])
コード例 #19
0
    def test_get_benchmark_definitions_paginated_fist_by_active_then_by_name(
            self):
        user1 = User.objects.create_user('*****@*****.**', '*****@*****.**',
                                         'pass')
        user1.save()

        git_project1 = GitProjectEntry.objects.create(url='http://test/')

        command_group = CommandGroupEntry.objects.create()
        command_set = CommandSetEntry.objects.create(group=command_group)

        bluesteel_layout = BluesteelLayoutEntry.objects.create(
            name='Layout', active=True, project_index_path=0)

        bluesteel_project = BluesteelProjectEntry.objects.create(
            name='Project',
            order=0,
            layout=bluesteel_layout,
            command_group=command_group,
            git_project=git_project1)

        benchmark_definition1 = BenchmarkDefinitionEntry.objects.create(
            name='BenchmarkDefinition1',
            layout=bluesteel_layout,
            project=bluesteel_project,
            active=True,
            command_set=command_set,
            revision=28)
        benchmark_definition2 = BenchmarkDefinitionEntry.objects.create(
            name='BenchmarkDefinition9',
            layout=bluesteel_layout,
            project=bluesteel_project,
            active=False,
            command_set=command_set,
            revision=28)
        benchmark_definition3 = BenchmarkDefinitionEntry.objects.create(
            name='BenchmarkDefinition2',
            layout=bluesteel_layout,
            project=bluesteel_project,
            active=True,
            command_set=command_set,
            revision=28)
        benchmark_definition4 = BenchmarkDefinitionEntry.objects.create(
            name='BenchmarkDefinition8',
            layout=bluesteel_layout,
            project=bluesteel_project,
            active=False,
            command_set=command_set,
            revision=28)
        benchmark_definition5 = BenchmarkDefinitionEntry.objects.create(
            name='BenchmarkDefinition3',
            layout=bluesteel_layout,
            project=bluesteel_project,
            active=True,
            command_set=command_set,
            revision=28)
        benchmark_definition6 = BenchmarkDefinitionEntry.objects.create(
            name='BenchmarkDefinition7',
            layout=bluesteel_layout,
            project=bluesteel_project,
            active=False,
            command_set=command_set,
            revision=28)

        (
            definitions1, paginations1
        ) = BenchmarkDefinitionController.get_benchmark_definitions_with_pagination(
            6, 1, 1)

        self.assertEqual(6, len(definitions1))
        self.assertEqual('BenchmarkDefinition1', definitions1[0]['name'])
        self.assertEqual('BenchmarkDefinition2', definitions1[1]['name'])
        self.assertEqual('BenchmarkDefinition3', definitions1[2]['name'])
        self.assertEqual('BenchmarkDefinition7', definitions1[3]['name'])
        self.assertEqual('BenchmarkDefinition8', definitions1[4]['name'])
        self.assertEqual('BenchmarkDefinition9', definitions1[5]['name'])

        self.assertEqual(True, definitions1[0]['active'])
        self.assertEqual(True, definitions1[1]['active'])
        self.assertEqual(True, definitions1[2]['active'])
        self.assertEqual(False, definitions1[3]['active'])
        self.assertEqual(False, definitions1[4]['active'])
        self.assertEqual(False, definitions1[5]['active'])
コード例 #20
0
    def test_save_benchmark_definition_delete_benchmarks_executions_if_layout_or_project_different(
            self):
        user1 = User.objects.create_user('*****@*****.**', '*****@*****.**',
                                         'pass')
        user1.save()

        git_project1 = GitProjectEntry.objects.create(url='http://test/')

        git_user1 = GitUserEntry.objects.create(project=git_project1,
                                                name='user1',
                                                email='*****@*****.**')

        commit1 = GitCommitEntry.objects.create(
            project=git_project1,
            commit_hash='0000100001000010000100001000010000100001',
            author=git_user1,
            author_date=timezone.now(),
            committer=git_user1,
            committer_date=timezone.now())

        command_group = CommandGroupEntry.objects.create()
        command_set = CommandSetEntry.objects.create(group=command_group)

        bluesteel_layout1 = BluesteelLayoutEntry.objects.create(
            name='Layout', active=True, project_index_path=0)
        bluesteel_project1 = BluesteelProjectEntry.objects.create(
            name='Project',
            order=0,
            layout=bluesteel_layout1,
            command_group=command_group,
            git_project=git_project1)

        bluesteel_layout2 = BluesteelLayoutEntry.objects.create(
            name='Layout', active=True, project_index_path=0)
        bluesteel_project2 = BluesteelProjectEntry.objects.create(
            name='Project',
            order=0,
            layout=bluesteel_layout2,
            command_group=command_group,
            git_project=git_project1)

        benchmark_definition1 = BenchmarkDefinitionEntry.objects.create(
            name='BenchmarkDefinition1',
            layout=bluesteel_layout1,
            project=bluesteel_project1,
            command_set=command_set,
            revision=28)

        worker1 = WorkerEntry.objects.create(name='worker-name-1',
                                             uuid='uuid-worker-1',
                                             operative_system='osx',
                                             description='long-description-1',
                                             user=user1,
                                             git_feeder=False)
        report1 = CommandSetEntry.objects.create(group=None)

        benchmark_execution1 = BenchmarkExecutionEntry.objects.create(
            definition=benchmark_definition1,
            commit=commit1,
            worker=worker1,
            report=report1,
            invalidated=False,
            revision_target=28,
            status=BenchmarkExecutionEntry.READY)

        commands = []
        commands.append('command-new-1')
        commands.append('command-new-2')
        commands.append('command-new-3')
        commands.append('command-new-4')
        commands.append('command-new-5')

        overrides = []
        overrides.append({
            'result_id': 'id1',
            'override_value': 28,
            'ignore_fluctuation': False
        })
        overrides.append({
            'result_id': 'id2',
            'override_value': 29,
            'ignore_fluctuation': False
        })

        self.assertEqual('BenchmarkDefinition1', benchmark_definition1.name)
        self.assertEqual(1, BenchmarkExecutionEntry.objects.all().count())
        self.assertEqual(benchmark_execution1,
                         BenchmarkExecutionEntry.objects.all().first())
        self.assertEqual(
            0,
            CommandEntry.objects.filter(
                command_set=benchmark_definition1.command_set).count())
        self.assertEqual(
            0,
            BenchmarkFluctuationOverrideEntry.objects.all().count())

        result = BenchmarkDefinitionController.save_benchmark_definition(
            'BenchmarkDefinition1-1', benchmark_definition1.id,
            bluesteel_layout2.id, bluesteel_project2.id,
            BenchmarkDefinitionEntry.NORMAL, True, commands, 28, overrides, 0,
            [])

        self.assertEqual('BenchmarkDefinition1-1', result.name)
        self.assertEqual(0, BenchmarkExecutionEntry.objects.all().count())
コード例 #21
0
    def test_save_benchmark_definition(self):
        layout = BluesteelLayoutController.create_new_default_layout()
        definition = BenchmarkDefinitionController.create_default_benchmark_definition(
        )

        self.assertEqual('default-name', definition.name)
        self.assertEqual(False, definition.active)
        self.assertEqual(
            1,
            CommandEntry.objects.filter(
                command_set=definition.command_set,
                command='git checkout {commit_hash}').count())
        self.assertEqual(
            1,
            CommandEntry.objects.filter(
                command_set=definition.command_set,
                command='git submodule update --init --recursive').count())
        self.assertEqual(
            1,
            CommandEntry.objects.filter(
                command_set=definition.command_set,
                command='<add_more_commands_here>').count())
        self.assertEqual(
            0,
            BenchmarkFluctuationOverrideEntry.objects.all().count())

        project = BluesteelProjectEntry.objects.filter(layout=layout).first()

        obj = {}
        obj['name'] = 'new-name-1'
        obj['layout_id'] = layout.id
        obj['project_id'] = project.id
        obj['priority'] = 3
        obj['active'] = True
        obj['max_fluctuation_percent'] = 28
        obj['max_weeks_old_notify'] = 8
        obj['command_list'] = []
        obj['command_list'].append('command-28')
        obj['command_list'].append('command-29')
        obj['command_list'].append('command-30')
        obj['command_list'].append('command-31')
        obj['overrides'] = []
        obj['overrides'].append({
            'result_id': 'id1',
            'override_value': 28,
            'ignore_fluctuation': False
        })
        obj['overrides'].append({
            'result_id': 'id2',
            'override_value': 29,
            'ignore_fluctuation': False
        })
        obj['work_passes'] = []

        resp = self.client.post('/main/definition/{0}/save/'.format(
            definition.id),
                                data=json.dumps(obj),
                                content_type='application/json')

        res.check_cross_origin_headers(self, resp)
        resp_obj = json.loads(resp.content)

        self.assertEqual(200, resp_obj['status'])

        definition = BenchmarkDefinitionEntry.objects.filter(
            id=definition.id).first()

        self.assertEqual('new-name-1', definition.name)
        self.assertEqual(True, definition.active)
        self.assertEqual(28, definition.max_fluctuation_percent)
        self.assertEqual(8, definition.max_weeks_old_notify)

        self.assertEqual(
            0,
            CommandEntry.objects.filter(
                command_set=definition.command_set,
                command='git checkout {commit_hash}').count())
        self.assertEqual(
            0,
            CommandEntry.objects.filter(
                command_set=definition.command_set,
                command='git submodule update --init --recursive').count())
        self.assertEqual(
            0,
            CommandEntry.objects.filter(
                command_set=definition.command_set,
                command='<add_more_commands_here>').count())

        self.assertEqual(
            1,
            CommandEntry.objects.filter(command_set=definition.command_set,
                                        command='command-28').count())
        self.assertEqual(
            1,
            CommandEntry.objects.filter(command_set=definition.command_set,
                                        command='command-29').count())
        self.assertEqual(
            1,
            CommandEntry.objects.filter(command_set=definition.command_set,
                                        command='command-30').count())
        self.assertEqual(
            1,
            CommandEntry.objects.filter(command_set=definition.command_set,
                                        command='command-31').count())

        self.assertEqual(
            2,
            BenchmarkFluctuationOverrideEntry.objects.all().count())
        self.assertEqual(
            1,
            BenchmarkFluctuationOverrideEntry.objects.filter(
                result_id='id1', override_value=28).count())
        self.assertEqual(
            1,
            BenchmarkFluctuationOverrideEntry.objects.filter(
                result_id='id2', override_value=29).count())
コード例 #22
0
    def test_duplicate_benchmark_definition(self):
        self.assertEqual(0, CommandGroupEntry.objects.all().count())
        self.assertEqual(0, CommandSetEntry.objects.all().count())
        self.assertEqual(0, CommandEntry.objects.all().count())
        self.assertEqual(0, CommandResultEntry.objects.all().count())

        new_layout = BluesteelLayoutEntry.objects.create(name='default-name')
        project = BluesteelProjectController.create_default_project(
            new_layout, 'project', 0)
        definition = BenchmarkDefinitionController.create_default_benchmark_definition(
        )
        definition.priority = BenchmarkDefinitionEntry.VERY_HIGH
        definition.active = True
        definition.max_fluctuation_percent = 28
        definition.revision = 3
        definition.max_weeks_old_notify = 2
        definition.save()

        BenchmarkFluctuationOverrideEntry.objects.create(
            definition=definition,
            result_id='id1',
            override_value=28,
            ignore_fluctuation=False)
        BenchmarkFluctuationOverrideEntry.objects.create(
            definition=definition,
            result_id='id2',
            override_value=29,
            ignore_fluctuation=False)
        BenchmarkFluctuationOverrideEntry.objects.create(
            definition=definition,
            result_id='id3',
            override_value=30,
            ignore_fluctuation=False)

        user1 = User.objects.create_user('*****@*****.**', '*****@*****.**',
                                         'pass')
        user1.save()

        user2 = User.objects.create_user('*****@*****.**', '*****@*****.**',
                                         'pass')
        user2.save()

        worker1 = WorkerEntry.objects.create(user=user1)
        worker2 = WorkerEntry.objects.create(user=user2)

        BenchmarkDefinitionWorkerPassEntry.objects.create(
            definition=definition, worker=worker2)
        BenchmarkDefinitionWorkerPassEntry.objects.create(
            definition=definition, worker=worker1)

        self.assertEqual(1, BluesteelLayoutEntry.objects.all().count())
        self.assertEqual(1, BluesteelProjectEntry.objects.all().count())
        self.assertNotEqual(None, definition.command_set)
        self.assertEqual(
            3,
            CommandEntry.objects.filter(
                command_set=definition.command_set).count())
        self.assertEqual(0, CommandResultEntry.objects.all().count())
        self.assertEqual(BenchmarkDefinitionEntry.VERY_HIGH,
                         definition.priority)
        self.assertEqual(True, definition.active)
        self.assertEqual(3, definition.revision)
        self.assertEqual(28, definition.max_fluctuation_percent)
        self.assertEqual(2, definition.max_weeks_old_notify)
        self.assertEqual('default-name', definition.name)
        self.assertEqual(
            3,
            BenchmarkFluctuationOverrideEntry.objects.all().count())
        self.assertEqual(
            2,
            BenchmarkDefinitionWorkerPassEntry.objects.filter(
                definition=definition).count())

        new_definition = BenchmarkDefinitionController.duplicate_benchmark_definition(
            definition.id)

        self.assertNotEqual(None, new_definition)
        self.assertEqual(2, BenchmarkDefinitionEntry.objects.all().count())
        self.assertEqual(
            3,
            CommandEntry.objects.filter(
                command_set=definition.command_set).count())
        self.assertEqual(
            3,
            CommandEntry.objects.filter(
                command_set=new_definition.command_set).count())
        self.assertEqual(BenchmarkDefinitionEntry.VERY_HIGH,
                         definition.priority)
        self.assertEqual(BenchmarkDefinitionEntry.VERY_HIGH,
                         new_definition.priority)
        self.assertEqual(True, definition.active)
        self.assertEqual(False, new_definition.active)
        self.assertEqual(3, definition.revision)
        self.assertEqual(0, new_definition.revision)
        self.assertEqual(28, definition.max_fluctuation_percent)
        self.assertEqual(28, new_definition.max_fluctuation_percent)
        self.assertEqual(2, definition.max_weeks_old_notify)
        self.assertEqual(2, new_definition.max_weeks_old_notify)
        self.assertEqual('default-name', definition.name)
        self.assertEqual('default-name (duplicate)', new_definition.name)
        self.assertEqual(
            3,
            BenchmarkFluctuationOverrideEntry.objects.all().count())
        self.assertEqual(
            2,
            BenchmarkDefinitionWorkerPassEntry.objects.filter(
                definition=definition).count())
        self.assertEqual(
            2,
            BenchmarkDefinitionWorkerPassEntry.objects.filter(
                definition=new_definition).count())
コード例 #23
0
    def test_save_benchmark_definition(self):
        self.assertEqual(0, CommandGroupEntry.objects.all().count())
        self.assertEqual(0, CommandSetEntry.objects.all().count())
        self.assertEqual(0, CommandEntry.objects.all().count())
        self.assertEqual(0, CommandResultEntry.objects.all().count())

        new_layout = BluesteelLayoutEntry.objects.create(name='default-name')
        project = BluesteelProjectController.create_default_project(
            new_layout, 'project', 0)
        definition = BenchmarkDefinitionController.create_default_benchmark_definition(
        )

        self.assertEqual(1, BluesteelLayoutEntry.objects.all().count())
        self.assertEqual(1, BluesteelProjectEntry.objects.all().count())
        self.assertNotEqual(None, definition.command_set)
        self.assertEqual(
            3,
            CommandEntry.objects.filter(
                command_set=definition.command_set).count())
        self.assertEqual(0, CommandResultEntry.objects.all().count())
        self.assertEqual(BenchmarkDefinitionEntry.NORMAL, definition.priority)
        self.assertEqual(False, definition.active)
        self.assertEqual(0, definition.revision)
        self.assertEqual(0, definition.max_fluctuation_percent)
        self.assertEqual(1, definition.max_weeks_old_notify)
        self.assertEqual('default-name', definition.name)
        self.assertEqual(
            0,
            BenchmarkFluctuationOverrideEntry.objects.all().count())

        commands = []
        commands.append('command-28')
        commands.append('command-29')
        commands.append('command-30')

        overrides = []
        overrides.append({
            'result_id': 'id1',
            'override_value': 28,
            'ignore_fluctuation': False
        })
        overrides.append({
            'result_id': 'id2',
            'override_value': 29,
            'ignore_fluctuation': False
        })

        definition = BenchmarkDefinitionController.save_benchmark_definition(
            'new-name', definition.id, new_layout.id, project.id,
            BenchmarkDefinitionEntry.VERY_HIGH, True, commands, 28, overrides,
            8, [])

        self.assertEqual(
            1,
            CommandEntry.objects.filter(command_set=definition.command_set,
                                        command='command-28').count())
        self.assertEqual(
            1,
            CommandEntry.objects.filter(command_set=definition.command_set,
                                        command='command-29').count())
        self.assertEqual(
            1,
            CommandEntry.objects.filter(command_set=definition.command_set,
                                        command='command-30').count())
        self.assertEqual(BenchmarkDefinitionEntry.VERY_HIGH,
                         definition.priority)
        self.assertEqual(True, definition.active)
        self.assertEqual(1, definition.revision)
        self.assertEqual(28, definition.max_fluctuation_percent)
        self.assertEqual(8, definition.max_weeks_old_notify)
        self.assertEqual('new-name', definition.name)
        self.assertEqual(
            2,
            BenchmarkFluctuationOverrideEntry.objects.all().count())
コード例 #24
0
    def test_save_work_passes(self):
        user1 = User.objects.create_user('*****@*****.**', '*****@*****.**',
                                         'pass')
        user1.save()

        user2 = User.objects.create_user('*****@*****.**', '*****@*****.**',
                                         'pass')
        user2.save()

        git_project1 = GitProjectEntry.objects.create(url='http://test/')

        command_group = CommandGroupEntry.objects.create()
        command_set = CommandSetEntry.objects.create(group=command_group)

        bluesteel_layout = BluesteelLayoutEntry.objects.create(
            name='Layout', active=True, project_index_path=0)
        bluesteel_project = BluesteelProjectEntry.objects.create(
            name='Project',
            order=0,
            layout=bluesteel_layout,
            command_group=command_group,
            git_project=git_project1)

        benchmark_definition1 = BenchmarkDefinitionEntry.objects.create(
            name='BenchmarkDefinition1',
            layout=bluesteel_layout,
            project=bluesteel_project,
            command_set=command_set,
            revision=28)
        worker1 = WorkerEntry.objects.create(user=user1)
        worker2 = WorkerEntry.objects.create(user=user2)

        BenchmarkDefinitionWorkerPassEntry.objects.create(
            definition=benchmark_definition1, worker=worker1, allowed=False)
        BenchmarkDefinitionWorkerPassEntry.objects.create(
            definition=benchmark_definition1, worker=worker2, allowed=True)

        obj = {}
        obj['work_passes'] = []
        obj['work_passes'].append({'id': worker1.id, 'allowed': True})
        obj['work_passes'].append({'id': worker2.id, 'allowed': False})

        self.assertEqual(
            False,
            BenchmarkDefinitionWorkerPassEntry.objects.filter(
                worker=worker1).first().allowed)
        self.assertEqual(
            True,
            BenchmarkDefinitionWorkerPassEntry.objects.filter(
                worker=worker2).first().allowed)

        BenchmarkDefinitionController.save_work_passes(
            obj['work_passes'], benchmark_definition1.id)

        self.assertEqual(
            True,
            BenchmarkDefinitionWorkerPassEntry.objects.filter(
                worker=worker1).first().allowed)
        self.assertEqual(
            False,
            BenchmarkDefinitionWorkerPassEntry.objects.filter(
                worker=worker2).first().allowed)
コード例 #25
0
    def test_get_benchmark_definitions_paginated_with_fluctuations(self):
        user1 = User.objects.create_user('*****@*****.**', '*****@*****.**',
                                         'pass')
        user1.save()

        git_project1 = GitProjectEntry.objects.create(url='http://test/')

        command_group = CommandGroupEntry.objects.create()
        command_set = CommandSetEntry.objects.create(group=command_group)

        bluesteel_layout = BluesteelLayoutEntry.objects.create(
            name='Layout', active=True, project_index_path=0)

        bluesteel_project = BluesteelProjectEntry.objects.create(
            name='Project',
            order=0,
            layout=bluesteel_layout,
            command_group=command_group,
            git_project=git_project1)

        benchmark_definition1 = BenchmarkDefinitionEntry.objects.create(
            name='BenchmarkDefinition1',
            layout=bluesteel_layout,
            project=bluesteel_project,
            command_set=command_set,
            revision=28)
        benchmark_definition2 = BenchmarkDefinitionEntry.objects.create(
            name='BenchmarkDefinition2',
            layout=bluesteel_layout,
            project=bluesteel_project,
            command_set=command_set,
            revision=28)
        benchmark_definition3 = BenchmarkDefinitionEntry.objects.create(
            name='BenchmarkDefinition3',
            layout=bluesteel_layout,
            project=bluesteel_project,
            command_set=command_set,
            revision=28)
        benchmark_definition4 = BenchmarkDefinitionEntry.objects.create(
            name='BenchmarkDefinition4',
            layout=bluesteel_layout,
            project=bluesteel_project,
            command_set=command_set,
            revision=28)
        benchmark_definition5 = BenchmarkDefinitionEntry.objects.create(
            name='BenchmarkDefinition5',
            layout=bluesteel_layout,
            project=bluesteel_project,
            command_set=command_set,
            revision=28)
        benchmark_definition6 = BenchmarkDefinitionEntry.objects.create(
            name='BenchmarkDefinition6',
            layout=bluesteel_layout,
            project=bluesteel_project,
            command_set=command_set,
            revision=28)

        fluc1 = BenchmarkFluctuationOverrideEntry.objects.create(
            definition=benchmark_definition1,
            result_id='id1',
            override_value=28)
        fluc2 = BenchmarkFluctuationOverrideEntry.objects.create(
            definition=benchmark_definition2,
            result_id='id2',
            override_value=29)
        fluc3 = BenchmarkFluctuationOverrideEntry.objects.create(
            definition=benchmark_definition2,
            result_id='id3',
            override_value=30)

        (
            definitions1, paginations1
        ) = BenchmarkDefinitionController.get_benchmark_definitions_with_pagination(
            2, 1, 1)
        definitions1.sort(key=lambda x: x['name'])

        self.assertEqual(2, len(definitions1))
        self.assertEqual('BenchmarkDefinition1', definitions1[0]['name'])
        self.assertEqual(1, len(definitions1[0]['fluctuation_overrides']))
        self.assertEqual(
            'id1', definitions1[0]['fluctuation_overrides'][0]['result_id'])
        self.assertEqual(
            28, definitions1[0]['fluctuation_overrides'][0]['override_value'])

        self.assertEqual('BenchmarkDefinition2', definitions1[1]['name'])
        self.assertEqual(2, len(definitions1[1]['fluctuation_overrides']))
        self.assertEqual(
            'id2', definitions1[1]['fluctuation_overrides'][0]['result_id'])
        self.assertEqual(
            29, definitions1[1]['fluctuation_overrides'][0]['override_value'])
        self.assertEqual(
            'id3', definitions1[1]['fluctuation_overrides'][1]['result_id'])
        self.assertEqual(
            30, definitions1[1]['fluctuation_overrides'][1]['override_value'])

        self.assertEqual(1, paginations1['current'])
        self.assertEqual(1, paginations1['prev'])
        self.assertEqual(2, paginations1['next'])
        self.assertEqual([1, 2, 3], paginations1['page_indices'])
コード例 #26
0
    def test_save_same_benchmark_definition_does_not_increment_revision(self):
        self.assertEqual(0, CommandGroupEntry.objects.all().count())
        self.assertEqual(0, CommandSetEntry.objects.all().count())
        self.assertEqual(0, CommandEntry.objects.all().count())
        self.assertEqual(0, CommandResultEntry.objects.all().count())

        new_layout = BluesteelLayoutEntry.objects.create(name='default-name')
        project = BluesteelProjectController.create_default_project(
            new_layout, 'project', 0)
        definition = BenchmarkDefinitionController.create_default_benchmark_definition(
        )

        definition.priority = BenchmarkDefinitionEntry.HIGH

        self.assertEqual(1, BluesteelLayoutEntry.objects.all().count())
        self.assertEqual(1, BluesteelProjectEntry.objects.all().count())
        self.assertNotEqual(None, definition.command_set)
        self.assertEqual(
            1,
            CommandEntry.objects.filter(
                command_set=definition.command_set,
                command='git checkout {commit_hash}').count())
        self.assertEqual(
            1,
            CommandEntry.objects.filter(
                command_set=definition.command_set,
                command='git submodule update --init --recursive').count())
        self.assertEqual(
            1,
            CommandEntry.objects.filter(
                command_set=definition.command_set,
                command='<add_more_commands_here>').count())
        self.assertEqual(0, CommandResultEntry.objects.all().count())
        self.assertEqual(BenchmarkDefinitionEntry.HIGH, definition.priority)
        self.assertEqual(False, definition.active)
        self.assertEqual(0, definition.revision)
        self.assertEqual(0, definition.max_fluctuation_percent)
        self.assertEqual(1, definition.max_weeks_old_notify)
        self.assertEqual('default-name', definition.name)
        self.assertEqual(
            0,
            BenchmarkFluctuationOverrideEntry.objects.all().count())

        commands = self.get_default_commands()

        overrides = []
        overrides.append({
            'result_id': 'id1',
            'override_value': 28,
            'ignore_fluctuation': False
        })
        overrides.append({
            'result_id': 'id2',
            'override_value': 29,
            'ignore_fluctuation': False
        })

        result = BenchmarkDefinitionController.save_benchmark_definition(
            'default-name', definition.id, new_layout.id, project.id,
            BenchmarkDefinitionEntry.VERY_HIGH, True, commands, 0, overrides,
            8, [])
        definition = BenchmarkDefinitionEntry.objects.all().first()

        self.assertEqual(definition, result)
        self.assertEqual(
            1,
            CommandEntry.objects.filter(
                command_set=definition.command_set,
                command='git checkout {commit_hash}').count())
        self.assertEqual(
            1,
            CommandEntry.objects.filter(
                command_set=definition.command_set,
                command='git submodule update --init --recursive').count())
        self.assertEqual(
            1,
            CommandEntry.objects.filter(
                command_set=definition.command_set,
                command='<add_more_commands_here>').count())
        self.assertEqual(BenchmarkDefinitionEntry.VERY_HIGH,
                         definition.priority)
        self.assertEqual(True, definition.active)
        self.assertEqual(0, definition.revision)
        self.assertEqual(0, definition.max_fluctuation_percent)
        self.assertEqual(8, definition.max_weeks_old_notify)
        self.assertEqual('default-name', definition.name)
        self.assertEqual(
            2,
            BenchmarkFluctuationOverrideEntry.objects.all().count())