def update_result(result_id): """Update an individual result.""" orig = Result.objects(id=result_id).first() update_event = events.UpdateEvent(before=orig) update = read_request() print((repr(update))) if 'status' in update and update['status'] != None and update['status'] != orig.status: atomic_update = { 'dec__summary__resultsByStatus__' + orig.status: 1, 'inc__summary__resultsByStatus__' + update['status']: 1 } update_testrun_event = None testrun = None if app.config['events']: testrun = Testrun.objects(id=orig.testrun.testrunId).first() update_testrun_event = events.UpdateEvent(before=testrun) Testrun.objects(id=orig.testrun.testrunId).update_one(**atomic_update) if app.config['events']: testrun.reload() update_testrun_event.after(testrun) deserialize_that(update, orig) apply_triage_notes(orig) orig.save() update_event.after(orig) return JsonResponse(orig)
def update_component(project_id, component_id): """Update a component's properties""" project = get_project(project_id) component = get_component(project, component_id) deserialize_that(read_request(), component) project.save() return JsonResponse(component)
def update_release(project_id, release_id): """Update a release""" project = get_project(project_id) release = get_release(project, release_id) deserialize_that(read_request(), release) project.save() return JsonResponse(release)
def update_build(project_id, release_id, build_id): """Update a build""" project = get_project(project_id) release = get_release(project, release_id) build = get_build(release, build_id) deserialize_that(read_request(), build) project.save() return JsonResponse(build)
def update_pipeline(pipeline_id): """Update the properties of a pipeline.""" orig = Pipeline.objects(id=pipeline_id).first() update_event = events.UpdateEvent(before=orig) deserialize_that(read_request(), orig) orig = pipeline_check(orig) orig.save() update_event.after(orig) return JsonResponse(orig)
def update_project(project_name): """Update an existing project. Only modified parameters are required.""" orig = get_project(project_name) update_event = events.UpdateEvent(orig) deserialize_that(read_request(), orig) orig.lastUpdated = datetime.datetime.utcnow() orig.save() update_event.after(orig) return JsonResponse(orig)
def update_testrun(testrun_id): """Update the properties of a testrun.""" orig = Testrun.objects(id=testrun_id).first() update_event = events.UpdateEvent(before=orig) deserialize_that(read_request(), orig) if orig.state == "FINISHED" and is_not_provided(orig, 'runFinished'): orig.runFinished = datetime.datetime.utcnow() orig.save() update_event.after(orig) return JsonResponse(orig)
def update_user_account(email): """Update a user's account info.""" orig = UserAccount.objects(email=email).first() if orig is None: return Response(status=404) update_event = events.UpdateEvent(before=orig) deserialize_that(read_request(), orig) orig.save() update_event.after(orig) return JsonResponse(orig)
def update_system_configuration(config_id): """Update a specific system configuration""" type_name = load_system_configuration_type(ObjectId(config_id)) type = BaseSystemConfiguration if type_name in SystemConfigurationTypes: type = SystemConfigurationTypes[type_name] orig = type.objects(id=config_id).first() deserialize_that(read_request(), orig) orig.save() return JsonResponse(orig)
def add_to_log(result_id): """Append log entries to a result.""" orig = Result.objects(id=result_id).first() if not hasattr(orig, 'log') or orig.log is None: orig.log = [] list_of_log_entries = read_request() if isinstance(list_of_log_entries, list): for entry_json in list_of_log_entries: orig.log.append(deserialize_that(entry_json, LogEntry())) else: orig.log.append(deserialize_that(list_of_log_entries, LogEntry())) orig.save() return JsonResponse(len(orig.log))
def update_configuration(configuration_id): """Update a configuration""" config = Configuration.objects(id=ObjectId(configuration_id)).first() if config is not None: config = deserialize_that(read_request(), config) config.save() return JsonResponse(config)
def add_testrun(): """Create a new testrun.""" new_tr = deserialize_that(read_request(), Testrun()) if is_not_provided(new_tr, 'dateCreated'): new_tr.dateCreated = datetime.datetime.utcnow() if is_not_provided(new_tr, 'info') and is_provided(new_tr, 'build') and \ is_provided(new_tr, 'project') and is_provided(new_tr, 'release'): project = get_project(new_tr.project.name) build = None if project is None: project = get_project(new_tr.project.id) if project is not None: release = get_release(project, new_tr.release.name) if release is None: release = get_release(project, new_tr.release.id) if release is not None: build = get_build(release, new_tr.build.name) if build is None: build = get_build(release, new_tr.build.id) if build is not None and is_provided(build, 'description'): new_tr.info = build.description new_tr.save() # add an event events.CreateEvent(new_tr) return JsonResponse(new_tr)
def add_testplan(): """Add a new testplan.""" new_tp = deserialize_that(read_request(), TestPlan()) if (new_tp.createdBy is None or new_tp.createdBy == "") and g.user is not None: new_tp.createdBy = g.user.full_name new_tp.save() return JsonResponse(new_tp)
def add_testrungroup(): """Create a new testrungroup.""" new_trg = deserialize_that(read_request(), TestrunGroup()) if is_not_provided(new_trg, 'created'): new_trg.created = datetime.datetime.now() new_trg.save() return JsonResponse(new_trg)
def add_testcase(): """Add a new testcase.""" new_tc = deserialize_that(read_request(), Testcase()) if (new_tc.author is None or new_tc.author == "") and g.user is not None: new_tc.author = g.user.full_name new_tc.save() return JsonResponse(new_tc)
def add_project(): """Add a new Project to slick.""" new_project = deserialize_that(read_request(), Project()) new_project.lastUpdated = datetime.datetime.utcnow() new_project.save() events.CreateEvent(new_project) return JsonResponse(new_project)
def create_event(): """Add a new slick log event.""" new_log = deserialize_that(read_request(), SlickLogEvent()) # set the user if one is logged in if (new_log.user is None or new_log.user == "" or new_log.user == "Anonymous") and g.user is not None: new_log.user = g.user.full_name + " <" + g.user.email + ">" new_log.save() return JsonResponse(new_log)
def add_dashboard(): """Add a new dashboard configuration""" data = read_request() if 'configurationType' not in data or data['configurationType'] not in DashboardTypes: return value = deserialize_that(data, DashboardTypes[data['configurationType']]()) value.save() return JsonResponse(value)
def add_system_configuration(): """Add a new system configuration""" data = read_request() if 'configurationType' not in data or data['configurationType'] not in SystemConfigurationTypes: return value = deserialize_that(data, SystemConfigurationTypes[data['configurationType']]()) value.save() return JsonResponse(value)
def add_phase_to_pipeline(pipeline_name_or_id): """Retrieve a pipeline using it's id.""" pipeline = get_pipeline(pipeline_name_or_id) if pipeline: raw = read_request() new_phases = [] if isinstance(raw, list): new_phases = deserialize_that(raw, EmbeddedDocumentListField(Phase)) else: new_phases.append(deserialize_that(raw, EmbeddedDocumentField(Phase))) if pipeline.phases and not pipeline.phases[-1].finished: pipeline.phases[-1].finished = datetime.datetime.utcnow() for phase in new_phases: phase = phase_check(phase) pipeline.phases.append(phase) pipeline.save() return JsonResponse(pipeline)
def add_testcase(): """Add a new testcase.""" new_tc = deserialize_that(read_request(), Testcase()) #if (new_tc.author is None or new_tc.author == "") and g.user is not None: # new_tc.author = g.user.full_name if is_not_provided(new_tc, 'created'): new_tc.created = datetime.datetime.utcnow() new_tc.save() return JsonResponse(new_tc)
def add_stored_file_to_result(result_id): new_stored_file = deserialize_that(read_request(), StoredFile()) new_stored_file.chunkSize = 262144 new_stored_file.save() orig = Result.objects(id=result_id).first() if not hasattr(orig, 'files') or orig.files is None: orig.files = [] orig.files.append(new_stored_file) orig.save() return JsonResponse(new_stored_file)
def update_phase_in_pipeline(pipeline_name_or_id, phase_name): """Retrieve a pipeline using it's id.""" pipeline = get_pipeline(pipeline_name_or_id) if pipeline: phase = [ind for ind, x in enumerate(pipeline.phases) if x.name == phase_name] if phase: index = phase[0] pipeline.phases[index] = deserialize_that(read_request(), pipeline.phases[index]) pipeline.phases[index] = phase_check(pipeline.phases[index]) pipeline.save() return JsonResponse(pipeline)
def add_component_for_project(project_id): """Add a component to a project.""" project = get_project(project_id) assert isinstance(project, Project) component = deserialize_that(read_request(), Component()) if not hasattr(component, 'id') or component.id is None: component.id = ObjectId() if not hasattr(project, 'components'): project.components = [] project.components.append(component) project.save() return JsonResponse(component)
def add_pipeline(): """Create a new pipeline.""" project_name = None release_name = None build_name = None raw = read_request() new_pipeline = deserialize_that(raw, Pipeline()) proj_id = None existing_pipeline = get_pipeline(new_pipeline.name) if existing_pipeline: new_pipeline = deserialize_that(raw, existing_pipeline) else: # resolve project, release and build, create if necessary if is_provided(new_pipeline, 'project'): project_name = new_pipeline.project.name if is_provided(new_pipeline, 'release'): release_name = new_pipeline.release.name if is_provided(new_pipeline, 'build'): build_name = new_pipeline.build.name if project_name is not None or release_name is not None or build_name is not None: # we have something to lookup / create proj_id, rel_id, bld_id = Project.lookup_project_release_build_ids(project_name, release_name, build_name, create_if_missing=True) if proj_id is not None: new_pipeline.project.id = proj_id if rel_id is not None: new_pipeline.release.releaseId = rel_id if bld_id is not None: new_pipeline.build.buildId = bld_id for ind, phase in enumerate(new_pipeline.phases): new_pipeline.phases[ind] = phase_check(new_pipeline.phases[ind]) new_pipeline = pipeline_check(new_pipeline) new_pipeline.save() # add an event events.CreateEvent(new_pipeline) return JsonResponse(new_pipeline)
def add_build(project_id, release_id): """Add a build to a release (and project).""" project = get_project(project_id) release = get_release(project, release_id) assert isinstance(project, Project) assert isinstance(release, Release) build = deserialize_that(read_request(), Build()) if not hasattr(build, 'id') or build.id is None: build.id = ObjectId() if not hasattr(release, 'builds'): release.builds = [] release.builds = release.builds + [build,] project.save() return JsonResponse(build)
def add_release_for_project(project_id): """Add a release to a project""" project = get_project(project_id) assert isinstance(project, Project) rel = deserialize_that(read_request(), Release()) if not hasattr(rel, 'id') or rel.id is None: rel.id = ObjectId() if not hasattr(project, 'releases'): project.releases = [] if not hasattr(rel, 'builds'): rel.builds = [] project.releases.append(rel) project.save() return JsonResponse(rel)
def create_configuration(): """Create a new configuration""" config = deserialize_that(read_request(), Configuration()) config.save() return JsonResponse(config)
def update_testplan(testplan_id): """Update an existing testplan's properties.""" orig = TestPlan.objects(id=testplan_id).first() deserialize_that(read_request(), orig) orig.save() return JsonResponse(orig)
def update_testrungroup(testrungroup_id): """Update a testrun group's properties.""" orig = TestrunGroup.objects(id=testrungroup_id).first() deserialize_that(read_request(), orig) orig.save() return JsonResponse(orig)