def delete(request, layout_id): """ Layout deletion """ if request.method != 'POST': return res.get_only_post_allowed({}) layout_entry = BluesteelLayoutEntry.objects.filter(id=layout_id).first() if layout_entry is None: return res.get_response(404, 'Bluesteel layout not found', {}) BluesteelLayoutController.delete_layout(layout_entry) data = {} data['redirect'] = ViewUrlGenerator.get_layout_all_url(1) return res.get_response(200, 'Layout deleted', data)
def test_delete_layout_entry(self): self.assertEqual(0, BluesteelLayoutEntry.objects.all().count()) self.assertEqual(0, BluesteelProjectEntry.objects.all().count()) new_entry = BluesteelLayoutController.create_new_default_layout() self.assertEqual(1, BluesteelLayoutEntry.objects.all().count()) self.assertEqual(1, BluesteelProjectEntry.objects.all().count()) self.assertTrue(self.check_default_fetch_commands()) BluesteelLayoutController.delete_layout(new_entry) self.assertEqual(0, BluesteelLayoutEntry.objects.all().count()) self.assertEqual(0, BluesteelProjectEntry.objects.all().count()) self.assertEqual(0, CommandEntry.objects.all().count())
def add_default_project(request, layout_id): """ Add default projet to layout """ if request.method != 'POST': return res.get_only_post_allowed({}) layout_entry = BluesteelLayoutEntry.objects.filter(id=layout_id).first() if layout_entry is None: return res.get_response(404, 'Bluesteel layout not found', {}) BluesteelLayoutController.add_default_project_to_layout(layout_entry) BluesteelLayoutController.sort_layout_projects_by_order(layout_entry) obj = {} obj['redirect'] = ViewUrlGenerator.get_layout_edit_url(layout_entry.id) return res.get_response(200, 'Layout saved!', obj)
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())
def test_delete_bluesteel_project_to_layout(self): layout_entry = BluesteelLayoutController.create_new_default_layout() self.assertEqual( 1, BluesteelLayoutEntry.objects.filter(id=layout_entry.id).count()) self.assertEqual(1, BluesteelProjectEntry.objects.all().count()) self.assertEqual(15, CommandEntry.objects.all().count()) self.assertTrue(self.check_default_fetch_commands()) resp = self.client.post('/main/layout/{0}/delete/'.format( layout_entry.id), data='', 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( 0, BluesteelLayoutEntry.objects.filter(id=layout_entry.id).count()) self.assertEqual(0, BluesteelProjectEntry.objects.all().count()) self.assertEqual(0, CommandEntry.objects.all().count())
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( )
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)
def test_create_benchmark_definition(self): layout = BluesteelLayoutController.create_new_default_layout() blueProject = BluesteelProjectEntry.objects.all().first().git_project commit1 = GitCommitEntry.objects.create( project=blueProject, commit_hash='0000500005000050000500005000050000500005', author=self.git_user1, author_date=timezone.now(), committer=self.git_user1, committer_date=timezone.now()) commit2 = GitCommitEntry.objects.create( project=blueProject, commit_hash='0000600006000060000600006000060000600006', author=self.git_user1, author_date=timezone.now(), committer=self.git_user1, committer_date=timezone.now()) commit3 = GitCommitEntry.objects.create( project=blueProject, commit_hash='0000700007000070000700007000070000700007', author=self.git_user1, author_date=timezone.now(), committer=self.git_user1, committer_date=timezone.now()) self.assertEqual(0, BenchmarkDefinitionEntry.objects.all().count()) self.assertEqual(0, BenchmarkExecutionEntry.objects.all().count()) resp = self.client.post('/main/definitions/create/', data='', 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.all().first() self.assertEqual(1, BenchmarkDefinitionEntry.objects.all().count()) self.assertEqual(0, BenchmarkExecutionEntry.objects.all().count()) self.assertEqual( 2, BenchmarkDefinitionWorkerPassEntry.objects.all().count()) self.assertEqual( 1, BenchmarkDefinitionWorkerPassEntry.objects.filter( definition=definition, worker=self.worker1).count()) self.assertEqual( 1, BenchmarkDefinitionWorkerPassEntry.objects.filter( definition=definition, worker=self.worker2).count())
def test_get_paginated_layouts(self): layout_1 = BluesteelLayoutController.create_new_default_layout() layout_2 = BluesteelLayoutController.create_new_default_layout() layout_3 = BluesteelLayoutController.create_new_default_layout() layout_4 = BluesteelLayoutController.create_new_default_layout() layout_5 = BluesteelLayoutController.create_new_default_layout() layout_6 = BluesteelLayoutController.create_new_default_layout() layout_7 = BluesteelLayoutController.create_new_default_layout() layouts_1, page_indices1 = BluesteelLayoutController.get_paginated_layouts_as_objects( Page(3, 1)) layouts_2, page_indices2 = BluesteelLayoutController.get_paginated_layouts_as_objects( Page(3, 2)) layouts_3, page_indices3 = BluesteelLayoutController.get_paginated_layouts_as_objects( Page(3, 3)) self.assertEqual(3, len(layouts_1)) self.assertEqual(layout_7.id, layouts_1[0]['id']) self.assertEqual(layout_6.id, layouts_1[1]['id']) self.assertEqual(layout_5.id, layouts_1[2]['id']) self.assertEqual(1, page_indices1['prev']) self.assertEqual(1, page_indices1['current']) self.assertEqual(2, page_indices1['next']) self.assertEqual([1, 2, 3], page_indices1['page_indices']) self.assertEqual(3, len(layouts_2)) self.assertEqual(layout_4.id, layouts_2[0]['id']) self.assertEqual(layout_3.id, layouts_2[1]['id']) self.assertEqual(layout_2.id, layouts_2[2]['id']) self.assertEqual(1, page_indices2['prev']) self.assertEqual(2, page_indices2['current']) self.assertEqual(3, page_indices2['next']) self.assertEqual([1, 2, 3], page_indices2['page_indices']) self.assertEqual(1, len(layouts_3)) self.assertEqual(layout_1.id, layouts_3[0]['id']) self.assertEqual(2, page_indices3['prev']) self.assertEqual(3, page_indices3['current']) self.assertEqual(3, page_indices3['next']) self.assertEqual([1, 2, 3], page_indices3['page_indices'])
def post_create_new_layout(request): """ Create a new layout and return the ID of it """ if request.method != 'POST': return res.get_only_post_allowed({}) new_layout = BluesteelLayoutController.create_new_default_layout() data = {} # data['layout'] = new_layout.as_object() # data['layout'] = ViewPrepareObjects.prepare_layout_for_html(data['layout']) data['redirect'] = ViewUrlGenerator.get_layout_edit_url(new_layout.id) return res.get_response(200, 'New layout created', data)
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)
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'])
def get_layouts(request, page_index): """ Returns html for the layout page """ page = Page(LAYOUT_ITEMS_PER_PAGE, page_index) layout_list, page_indices = BluesteelLayoutController.get_paginated_layouts_as_objects(page) for layout in layout_list: layout = ViewPrepareObjects.prepare_layout_for_html(layout) control = {} control['name'] = ' Add Layout' control['link'] = ViewUrlGenerator.get_layout_create_url() control['icon'] = 'fa fa-plus' control['onclick'] = 'executeAndRedirect(\'{0}\', \'\');'.format(control['link']) pagination = ViewPrepareObjects.prepare_pagination_layout(page_indices) data = {} data['layout_list'] = layout_list data['menu'] = ViewPrepareObjects.prepare_menu_for_html([]) data['pagination'] = pagination data['controls'] = [] data['controls'].append(control) return res.get_template_data(request, 'presenter/layout.html', data)
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())