def test_delete_commands_from_command_set(self): group = TestCommandHelper.create_default_group() comm_set = CommandSetEntry.objects.create(group=group, name='name_set', order=0) CommandEntry.objects.create(command_set=comm_set, command='command1', order=0) CommandEntry.objects.create(command_set=comm_set, command='command2', order=1) CommandEntry.objects.create(command_set=comm_set, command='command3', order=2) self.assertEqual(1, 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()) CommandController.delete_commands_of_command_set(comm_set) self.assertEqual(1, CommandGroupEntry.objects.all().count()) self.assertEqual(1, CommandSetEntry.objects.all().count()) self.assertEqual(0, CommandEntry.objects.all().count()) self.assertEqual(0, CommandResultEntry.objects.all().count())
def test_add_full_command_set_with_no_white_space(self): command_group = CommandGroupEntry.objects.create() self.assertEqual(1, 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()) commands = [] commands.append('command 1') commands.append(' command 2') commands.append('command 3 ') CommandController.add_full_command_set(command_group, 'CLONE', 28, commands) self.assertEqual(1, CommandGroupEntry.objects.all().count()) self.assertEqual(1, CommandSetEntry.objects.all().count()) self.assertEqual( 1, CommandEntry.objects.filter(command='command 1').count()) self.assertEqual( 1, CommandEntry.objects.filter(command='command 2').count()) self.assertEqual( 1, CommandEntry.objects.filter(command='command 3').count()) self.assertEqual(0, CommandResultEntry.objects.all().count())
def save_project(request, project_id): """ Save project properties """ 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', {}) (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, BluesteelSchemas.SAVE_PROJECT) if not obj_validated: return res.get_schema_failed(val_resp_obj) CommandSetEntry.objects.filter(group=project_entry.command_group).delete() local_search_path = filter_folder_path(val_resp_obj['git_project_folder_search_path']) project_entry.name = val_resp_obj['name'] project_entry.git_project_folder_search_path = local_search_path project_entry.save() CommandController.add_full_command_set(project_entry.command_group, 'CLONE', 0, val_resp_obj['clone']) CommandController.add_full_command_set(project_entry.command_group, 'FETCH', 1, val_resp_obj['fetch']) return res.get_response(200, 'Project saved', {})
def delete_all_feeds(self, request, queryset): """ Delete all the feeds with all of its associated commands """ del queryset entries = FeedEntry.objects.all() for entry in entries: CommandController.delete_command_group_by_id(entry.command_group.id) entry.delete() self.message_user(request, "All Feed entries were deleted successfully.")
def test_save_bluesteel_project_removing_everything_in_path(self): commands = [] commands.append('command-1') commands.append('command-2') commands.append('command-3') commands2 = [] commands2.append('command-4') commands2.append('command-5') commands2.append('command-6') command_group = CommandGroupEntry.objects.create() CommandController.add_full_command_set(command_group, "CLONE", 0, commands) CommandController.add_full_command_set(command_group, "FETCH", 1, commands2) git_project = GitProjectEntry.objects.create(url='', name='git-project') bluesteel_proj = BluesteelProjectEntry.objects.create( name='project-1', layout=self.layout_1, command_group=command_group, git_project=git_project) obj = {} obj['name'] = 'NAME-updated' obj['git_project_folder_search_path'] = '\\..\\' obj['clone'] = [] obj['clone'].append('command-28') obj['clone'].append('command-29') obj['fetch'] = [] obj['fetch'].append('command-30') obj['fetch'].append('command-31') resp = self.client.post('/main/project/{0}/save/'.format( bluesteel_proj.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( '.', BluesteelProjectEntry.objects.all().first(). git_project_folder_search_path)
def test_delete_command_group(self): result = TestCommandHelper.create_default_command_result() self.assertEqual(1, CommandGroupEntry.objects.all().count()) self.assertEqual(1, CommandSetEntry.objects.all().count()) self.assertEqual(1, CommandEntry.objects.all().count()) self.assertEqual(1, CommandResultEntry.objects.all().count()) CommandController.delete_command_group_by_id( CommandGroupEntry.objects.all().first().id) 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())
def test_add_command_with_no_white_space_to_other_commands(self): command_group = CommandGroupEntry.objects.create() comm_set = CommandSetEntry.objects.create(group=command_group, name='name_set', order=0) CommandEntry.objects.create(command_set=comm_set, command='command 1', order=0) CommandEntry.objects.create(command_set=comm_set, command='command 2', order=1) CommandEntry.objects.create(command_set=comm_set, command='command 3', order=2) self.assertEqual(1, CommandGroupEntry.objects.all().count()) self.assertEqual(1, CommandSetEntry.objects.all().count()) self.assertEqual( 1, CommandEntry.objects.filter(command='command 1').count()) self.assertEqual( 1, CommandEntry.objects.filter(command='command 2').count()) self.assertEqual( 1, CommandEntry.objects.filter(command='command 3').count()) self.assertEqual(0, CommandResultEntry.objects.all().count()) CommandController.add_commands_to_command_set(comm_set, [' comm_3', 'comm_5 ']) self.assertEqual(1, CommandGroupEntry.objects.all().count()) self.assertEqual(1, CommandSetEntry.objects.all().count()) self.assertEqual( 1, CommandEntry.objects.filter(command='command 1').count()) self.assertEqual( 1, CommandEntry.objects.filter(command='command 2').count()) self.assertEqual( 1, CommandEntry.objects.filter(command='command 3').count()) self.assertEqual(1, CommandEntry.objects.filter(command='comm_3').count()) self.assertEqual(1, CommandEntry.objects.filter(command='comm_5').count()) self.assertEqual(0, CommandResultEntry.objects.all().count())
def test_add_full_command_set_with_group_to_none(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()) commands = [] commands.append('command 1') commands.append('command 2') commands.append('command 3') CommandController.add_full_command_set(None, 'CLONE', 28, 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())
def test_duplicate_command_set(self): comm_set = CommandSetEntry.objects.create(name='name_set', order=0) CommandEntry.objects.create(command_set=comm_set, command='command1', order=0) CommandEntry.objects.create(command_set=comm_set, command='command2', order=1) CommandEntry.objects.create(command_set=comm_set, command='command3', order=2) self.assertEqual(0, CommandGroupEntry.objects.all().count()) self.assertEqual(1, CommandSetEntry.objects.all().count()) self.assertEqual( 1, CommandEntry.objects.filter(command_set=comm_set, command='command1').count()) self.assertEqual( 1, CommandEntry.objects.filter(command_set=comm_set, command='command2').count()) self.assertEqual( 1, CommandEntry.objects.filter(command_set=comm_set, command='command3').count()) self.assertEqual(0, CommandResultEntry.objects.all().count()) new_comm_set = CommandController.duplicate_command_set(comm_set.id) self.assertEqual(0, CommandGroupEntry.objects.all().count()) self.assertEqual(2, CommandSetEntry.objects.all().count()) self.assertEqual( 1, CommandEntry.objects.filter(command_set=comm_set, command='command1').count()) self.assertEqual( 1, CommandEntry.objects.filter(command_set=comm_set, command='command2').count()) self.assertEqual( 1, CommandEntry.objects.filter(command_set=comm_set, command='command3').count()) self.assertEqual( 1, CommandEntry.objects.filter(command_set=new_comm_set, command='command1').count()) self.assertEqual( 1, CommandEntry.objects.filter(command_set=new_comm_set, command='command2').count()) self.assertEqual( 1, CommandEntry.objects.filter(command_set=new_comm_set, command='command3').count()) self.assertEqual(0, CommandResultEntry.objects.all().count())
def test_delete_bluesteel_project(self): commands = [] commands.append('command-1') commands.append('command-2') commands.append('command-3') commands2 = [] commands2.append('command-4') commands2.append('command-5') commands2.append('command-6') command_group = CommandGroupEntry.objects.create() CommandController.add_full_command_set(command_group, "CLONE", 0, commands) CommandController.add_full_command_set(command_group, "FETCH", 1, commands2) git_project = GitProjectEntry.objects.create(url='', name='git-project') bluesteel_proj = BluesteelProjectEntry.objects.create( name='project-1', layout=self.layout_1, command_group=command_group, git_project=git_project) self.assertEqual(1, CommandGroupEntry.objects.all().count()) self.assertEqual(2, CommandSetEntry.objects.all().count()) self.assertEqual(6, CommandEntry.objects.all().count()) self.assertEqual( 1, CommandEntry.objects.filter(command='command-1').count()) self.assertEqual( 1, CommandEntry.objects.filter(command='command-2').count()) self.assertEqual( 1, CommandEntry.objects.filter(command='command-3').count()) self.assertEqual( 1, CommandEntry.objects.filter(command='command-4').count()) self.assertEqual( 1, CommandEntry.objects.filter(command='command-5').count()) self.assertEqual( 1, CommandEntry.objects.filter(command='command-6').count()) self.assertEqual(1, GitProjectEntry.objects.all().count()) self.assertEqual(True, BluesteelLayoutEntry.objects.all().first().active) resp = self.client.post('/main/project/{0}/delete/'.format( bluesteel_proj.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, BluesteelProjectEntry.objects.all().count()) self.assertEqual(0, CommandGroupEntry.objects.all().count()) self.assertEqual(0, CommandSetEntry.objects.all().count()) self.assertEqual(0, CommandEntry.objects.all().count()) self.assertEqual(0, GitProjectEntry.objects.all().count()) self.assertEqual(False, BluesteelLayoutEntry.objects.all().first().active)
def test_save_bluesteel_project_does_not_delete_benchmark_definitions( self): commands = [] commands.append('command-1') commands.append('command-2') commands.append('command-3') command_group = CommandGroupEntry.objects.create() CommandController.add_full_command_set(command_group, "CLONE", 0, commands) git_project = GitProjectEntry.objects.create(url='', name='git-project') bluesteel_proj = BluesteelProjectEntry.objects.create( name='project-1', layout=self.layout_1, command_group=command_group, git_project=git_project) benchmark_def = BenchmarkDefinitionEntry.objects.create( layout=self.layout_1, project=bluesteel_proj, command_set=CommandSetEntry.objects.create()) self.assertEqual(1, CommandGroupEntry.objects.all().count()) self.assertEqual(2, CommandSetEntry.objects.all().count()) self.assertEqual(3, CommandEntry.objects.all().count()) self.assertEqual( 1, CommandEntry.objects.filter(command='command-1').count()) self.assertEqual( 1, CommandEntry.objects.filter(command='command-2').count()) self.assertEqual( 1, CommandEntry.objects.filter(command='command-3').count()) obj = {} obj['name'] = 'NAME-updated' obj['git_project_folder_search_path'] = 'local/path/updated/too/' obj['clone'] = [] obj['clone'].append('command-28') obj['clone'].append('command-29') obj['fetch'] = [] obj['fetch'].append('command-30') obj['fetch'].append('command-31') resp = self.client.post('/main/project/{0}/save/'.format( bluesteel_proj.id), data=json.dumps(obj), content_type='application/json') self.assertEqual( 1, BenchmarkDefinitionEntry.objects.filter( id=benchmark_def.id).count()) self.assertEqual(4, CommandEntry.objects.all().count()) self.assertEqual( 1, CommandEntry.objects.filter(command='command-28').count()) self.assertEqual( 1, CommandEntry.objects.filter(command='command-29').count()) self.assertEqual( 1, CommandEntry.objects.filter(command='command-30').count()) self.assertEqual( 1, CommandEntry.objects.filter(command='command-31').count())