Exemple #1
0
    def delete_layout(layout):
        """ Delete layout """
        project_entries = BluesteelProjectEntry.objects.filter(layout=layout)

        for project in project_entries:
            BluesteelProjectController.delete_project(project)
        layout.delete()
Exemple #2
0
    def test_layout_remains_active_because_project_index_is_correct(self):
        git_project_1 = GitProjectEntry.objects.create(
            url='http://www.test-1.com',
            name='git-project-1',
        )

        git_project_2 = GitProjectEntry.objects.create(
            url='http://www.test-2.com',
            name='git-project-2',
        )

        command_group_1 = BluesteelProjectController.create_default_command_group(
        )
        command_group_2 = BluesteelProjectController.create_default_command_group(
        )

        project_entry_1 = BluesteelProjectEntry.objects.create(
            layout=self.layout_1,
            name='project-1',
            command_group=command_group_1,
            git_project=git_project_1,
        )

        project_entry_2 = BluesteelProjectEntry.objects.create(
            layout=self.layout_1,
            name='project-2',
            command_group=command_group_2,
            git_project=git_project_2,
        )

        self.assertEqual(0, self.layout_1.project_index_path)

        obj = {}
        obj['name'] = 'layout-1'
        obj['active'] = True
        obj['project_index_path'] = 1

        resp = self.client.post('/main/layout/{0}/save/'.format(
            self.layout_1.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(True,
                         BluesteelLayoutEntry.objects.all().first().active)
        self.assertEqual(
            1,
            BluesteelLayoutEntry.objects.all().first().project_index_path)
def get_project_branches(request, project_id, commit_depth, page_index):
    """ Display all the branches of a project """
    if request.method != 'GET':
        return res.get_template_data(request, 'presenter/not_found.html', {})

    project_entry = BluesteelProjectEntry.objects.filter(id=project_id).first()
    if project_entry is None:
        return res.get_template_data(request, 'presenter/not_found.html', {})

    project = GitProjectEntry.objects.filter(
        id=project_entry.git_project.id).first()
    if project is None:
        return res.get_template_data(request, 'presenter/not_found.html', {})

    page = Page(PROJECTS_BRANCHES_PER_PAGE, page_index)
    branches, page_indices = BluesteelProjectController.get_project_git_branch_data(
        page, project, commit_depth)
    branches = BenchmarkExecutionController.add_bench_exec_completed_to_branches(
        branches)

    pagination = ViewPrepareObjects.prepare_pagination_branches(
        project_entry.id, commit_depth, page_indices)

    data = {}
    data['branches'] = ViewPrepareObjects.prepare_branches_for_html(
        project_entry.id, branches)
    data['url'] = {}
    data['url'][
        'change_merge_target'] = ViewUrlGenerator.get_change_merge_target_url(
            project_entry.id)
    data['menu'] = ViewPrepareObjects.prepare_menu_for_html([])
    data['pagination'] = pagination

    return res.get_template_data(request, 'presenter/project_branches.html',
                                 data)
def get_projects(request, page_index):
    """ Display all branch names """
    if request.method != 'GET':
        return res.get_template_data(request, 'presenter/not_found.html', {})

    page = Page(PROJECTS_ITEMS_PER_PAGE, page_index)
    projects, page_indices = BluesteelProjectController.get_paginated_projects_as_objects(
        page)

    items = []
    for project in projects:
        obj = {}
        obj['name'] = project['name']
        obj['url'] = {}
        obj['url']['branches'] = ViewUrlGenerator.get_project_branches_url(
            project['id'], BRANCH_COMMIT_DEPTH, 1)
        obj['url']['edit'] = ViewUrlGenerator.get_project_edit_url(
            project['id'])
        items.append(obj)

    pagination = ViewPrepareObjects.prepare_pagination_project(page_indices)

    data = {}
    data['projects'] = items
    data['menu'] = ViewPrepareObjects.prepare_menu_for_html([])
    data['pagination'] = pagination

    return res.get_template_data(request, 'presenter/project_list.html', data)
def get_project_single_branch(request, project_id, branch_id):
    """ Display all the branches of a project """
    if request.method != 'GET':
        return res.get_template_data(request, 'presenter/not_found.html', {})

    project_entry = BluesteelProjectEntry.objects.filter(id=project_id).first()
    if project_entry is None:
        return res.get_template_data(request, 'presenter/not_found.html', {})

    git_project = GitProjectEntry.objects.filter(
        id=project_entry.git_project.id).first()
    if git_project is None:
        return res.get_template_data(request, 'presenter/not_found.html', {})

    branch_entry = GitBranchEntry.objects.filter(id=branch_id,
                                                 project=git_project).first()
    if branch_entry is None:
        return res.get_template_data(request, 'presenter/not_found.html', {})

    branches = BluesteelProjectController.get_project_single_git_branch_data(
        git_project, branch_entry, BRANCH_COMMIT_DEPTH)
    branches = BenchmarkExecutionController.add_bench_exec_completed_to_branches(
        branches)

    data = {}
    data['branches'] = ViewPrepareObjects.prepare_branches_for_html(
        project_entry.id, branches)
    data['url'] = {}
    data['url'][
        'change_merge_target'] = ViewUrlGenerator.get_change_merge_target_url(
            project_entry.id)
    data['menu'] = ViewPrepareObjects.prepare_menu_for_html([])

    return res.get_template_data(request, 'presenter/project_branches.html',
                                 data)
Exemple #6
0
def delete_project(request, project_id):
    """ Delete project on a layout """
    if request.method != 'POST':
        return res.get_only_post_allowed({})

    project_entry = BluesteelProjectEntry.objects.filter(id=project_id).first()
    if project_entry is None:
        return res.get_response(404, 'Bluesteel project not found', {})

    layout_id = project_entry.layout.id
    project_entry.layout.active = False
    project_entry.layout.save()

    BluesteelProjectController.delete_project(project_entry)
    BluesteelLayoutController.sort_layout_projects_by_order(project_entry.layout)

    obj = {}
    obj['redirect'] = ViewUrlGenerator.get_layout_edit_url(layout_id)
    return res.get_response(200, 'Project deleted', obj)
Exemple #7
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))
    def test_get_paginated_projects(self):
        layout_entry = BluesteelLayoutEntry.objects.create(name='name')

        project_1 = BluesteelProjectController.create_default_project(layout=layout_entry, name='project-name-1', order=28)
        project_2 = BluesteelProjectController.create_default_project(layout=layout_entry, name='project-name-2', order=27)
        project_3 = BluesteelProjectController.create_default_project(layout=layout_entry, name='project-name-3', order=26)
        project_4 = BluesteelProjectController.create_default_project(layout=layout_entry, name='project-name-4', order=25)
        project_5 = BluesteelProjectController.create_default_project(layout=layout_entry, name='project-name-5', order=24)
        project_6 = BluesteelProjectController.create_default_project(layout=layout_entry, name='project-name-6', order=23)
        project_7 = BluesteelProjectController.create_default_project(layout=layout_entry, name='project-name-7', order=22)

        projects_1, page_indices_1 = BluesteelProjectController.get_paginated_projects_as_objects(Page(3, 1))
        projects_2, page_indices_2 = BluesteelProjectController.get_paginated_projects_as_objects(Page(3, 2))
        projects_3, page_indices_3 = BluesteelProjectController.get_paginated_projects_as_objects(Page(3, 3))

        self.assertEqual(3, len(projects_1))
        self.assertEqual(project_7.id, projects_1[0]['id'])
        self.assertEqual(project_6.id, projects_1[1]['id'])
        self.assertEqual(project_5.id, projects_1[2]['id'])
        self.assertEqual(1, page_indices_1['prev'])
        self.assertEqual(1, page_indices_1['current'])
        self.assertEqual(2, page_indices_1['next'])
        self.assertEqual([1, 2, 3], page_indices_1['page_indices'])

        self.assertEqual(3, len(projects_2))
        self.assertEqual(project_4.id, projects_2[0]['id'])
        self.assertEqual(project_3.id, projects_2[1]['id'])
        self.assertEqual(project_2.id, projects_2[2]['id'])
        self.assertEqual(1, page_indices_2['prev'])
        self.assertEqual(2, page_indices_2['current'])
        self.assertEqual(3, page_indices_2['next'])
        self.assertEqual([1, 2, 3], page_indices_2['page_indices'])

        self.assertEqual(1, len(projects_3))
        self.assertEqual(project_1.id, projects_3[0]['id'])
        self.assertEqual(2, page_indices_3['prev'])
        self.assertEqual(3, page_indices_3['current'])
        self.assertEqual(3, page_indices_3['next'])
        self.assertEqual([1, 2, 3], page_indices_3['page_indices'])
Exemple #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))
Exemple #10
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())
    def test_create_default_project_entry(self):
        self.assertEqual(0, BluesteelProjectEntry.objects.all().count())

        layout_entry = BluesteelLayoutEntry.objects.create(
            name='name',
        )

        new_entry = BluesteelProjectController.create_default_project(
            layout=layout_entry,
            name='project-name',
            order=28
        )

        self.assertEqual(1, BluesteelProjectEntry.objects.all().count())
        self.assertEqual(layout_entry, BluesteelProjectEntry.objects.all().first().layout)
        self.assertEqual('project-name', BluesteelProjectEntry.objects.all().first().name)
        self.assertEqual(28, BluesteelProjectEntry.objects.all().first().order)

        self.assertEqual(1, CommandGroupEntry.objects.all().count())
        self.assertEqual(2, CommandSetEntry.objects.all().count())
        self.assertEqual('CLONE', CommandSetEntry.objects.filter(order=0).first().name)
        self.assertEqual('FETCH', CommandSetEntry.objects.filter(order=1).first().name)

        self.assertTrue(self.check_default_fetch_commands())
Exemple #12
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())
Exemple #13
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())
Exemple #14
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())
Exemple #15
0
 def add_default_project_to_layout(layout):
     """ Adds a default project to a given layout """
     project_count = BluesteelProjectEntry.objects.filter(
         layout=layout).count()
     BluesteelProjectController.create_default_project(
         layout, 'project-name', project_count)