class TargetsResource(ApiResource): validator = get_validator(target_schema) def on_post(self, req, resp, tenant_id): target_id = str(uuid.uuid4()) body = self.load_body(req, self.validator) body['id'] = target_id target = Target.build_target_from_dict(tenant_id, body) duplicate_target = Target.get_target(tenant_id, target_id=target.name) if duplicate_target: raise falcon.exceptions.HTTPConflict( 'Duplicate Target Name', 'Target names must be unique: {0}'.format(target.name)) Target.save_target(target) resp.status = falcon.HTTP_201 resp.body = self.format_response_body({'target_id': target_id}) def on_get(self, req, resp, tenant_id): targets = Target.get_targets(tenant_id) target_list = [target.summary_dict() for target in targets] resp.body = self.format_response_body({'targets': target_list})
class JobsResource(ApiResource): validator = get_validator(job_schema) def on_post(self, req, resp, tenant_id): body = self.load_body(req, self.validator) body['tenant_id'] = tenant_id job = Job.build_job_from_dict(body) Job.save_job(job) resp.status = falcon.HTTP_201 resp.body = self.format_response_body({'job_id': job.id}) def on_get(self, req, resp, tenant_id): jobs_list = [job.summary_dict() for job in Job.get_jobs(tenant_id)] resp.body = self.format_response_body({'jobs': jobs_list})
class SchedulesResource(ApiResource): validator = get_validator(schedule_schema) def on_get(self, req, resp, tenant_id): schedules_list = [ s.as_dict() for s in Schedule.get_schedules(tenant_id) ] resp.body = self.format_response_body({'schedules': schedules_list}) def on_post(self, req, resp, tenant_id): schedule_id = str(uuid.uuid4()) body = self.load_body(req, self.validator) body['id'] = schedule_id schedule = Schedule.build_schedule_from_dict(tenant_id, body) Schedule.save_schedule(schedule) resp.status = falcon.HTTP_201 resp.body = self.format_response_body({'schedule_id': schedule_id})
def validates(self, body): body = json.loads(body) validator = get_validator(schedule_schema) validator.validate(body)
def fails_to_falidate(self, body): body = json.loads(body) validator = get_validator(schedule_schema) expect(validator.validate, [body]).to.raise_a(ValidationError)
def validates(self, body): validator = get_validator(target_schema) validator.validate(body)
def fails_to_validate(self, body): validator = get_validator(target_schema) expect(validator.validate, [body]).to.raise_a(ValidationError)