def test_missing_id_field(self): # Note that the 'id' key is missing. definition = self.load_def("""{ "objects": [ { "name": "OVERRIDE-NAME", "type": "Schedule", "startDateTime": "2013-08-18T00:00:00", "endDateTime": "2013-08-19T00:00:00", "period": "1 day" } ]}""") with self.assertRaises(translator.PipelineDefinitionError): translator.definition_to_api(definition)
def test_missing_id_field(self): # Note that the 'id' key is missing. definition = self.load_def("""{ "objects": [ { "name": "OVERRIDE-NAME", "type": "Schedule", "startDateTime": "2013-08-18T00:00:00", "endDateTime": "2013-08-19T00:00:00", "period": "1 day" } ]}""") with self.assertRaises(translator.PipelineDefinitionError): translator.definition_to_api(definition)
def test_value_with_refs(self): definition = self.load_def("""{"objects": [ { "id" : "emrActivity", "type" : "EmrActivity", "name" : "Foo", "step" : ["s3://foo1", {"ref": "otherValue"}, "s3://foo3"] } ]}""") actual = translator.definition_to_api(definition) api = [{ "name": "Foo", "id": "emrActivity", "fields": [ { "key": "step", "stringValue": "s3://foo1" }, { "key": "step", "refValue": "otherValue" }, { "key": "step", "stringValue": "s3://foo3" }, { "key": "type", "stringValue": "EmrActivity" }, ] }] self.assertEqual(actual, api)
def add_to_params(self, parameters, value): if value is None: return new_value = uri_param(self, value) if new_value is not None: value = new_value parsed = json.loads(new_value) api_objects = translator.definition_to_api(parsed) parameters['pipeline_objects'] = api_objects
def add_to_params(self, parameters, value): if value is None: return new_value = uri_param(self, value) if new_value is not None: value = new_value parsed = json.loads(new_value) api_objects = translator.definition_to_api(parsed) parameters['pipeline_objects'] = api_objects
def test_value_with_refs(self): definition = self.load_def("""{"objects": [ { "id" : "emrActivity", "type" : "EmrActivity", "name" : "Foo", "step" : ["s3://foo1", {"ref": "otherValue"}, "s3://foo3"] } ]}""") actual = translator.definition_to_api(definition) api = [{"name": "Foo", "id": "emrActivity", "fields": [ {"key": "step", "stringValue": "s3://foo1"}, {"key": "step", "refValue": "otherValue"}, {"key": "step", "stringValue": "s3://foo3"}, {"key": "type", "stringValue": "EmrActivity"}, ]}] self.assertEqual(actual, api)
def test_convert_schedule_df_to_api(self): definition = self.load_def("""{"objects": [ { "id" : "S3ToS3Copy", "type" : "CopyActivity", "schedule" : { "ref" : "CopyPeriod" }, "input" : { "ref" : "InputData" }, "output" : { "ref" : "OutputData" } } ]}""") actual = translator.definition_to_api(definition) api = [{"name": "S3ToS3Copy", "id": "S3ToS3Copy", "fields": [ {"key": "input", "refValue": "InputData"}, {"key": "output", "refValue": "OutputData"}, {"key": "schedule", "refValue": "CopyPeriod" }, {"key": "type", "stringValue": "CopyActivity" }, ]}] self.assertEqual(actual, api)
def test_convert_df_to_api_schedule(self): definition = self.load_def("""{ "objects": [ { "id": "MySchedule", "type": "Schedule", "startDateTime": "2013-08-18T00:00:00", "endDateTime": "2013-08-19T00:00:00", "period": "1 day" } ]}""") actual = translator.definition_to_api(definition) api = [{"name": "MySchedule", "id": "MySchedule", "fields": [ {"key": "endDateTime", "stringValue": "2013-08-19T00:00:00"}, {"key": "period", "stringValue": "1 day"}, {"key": "startDateTime", "stringValue": "2013-08-18T00:00:00"}, {"key": "type", "stringValue": "Schedule"}, ]}] self.assertEqual(actual, api)
def test_convert_df_to_api_with_name(self): definition = self.load_def("""{ "objects": [ { "id": "MySchedule", "name": "OVERRIDE-NAME", "type": "Schedule", "startDateTime": "2013-08-18T00:00:00", "endDateTime": "2013-08-19T00:00:00", "period": "1 day" } ]}""") actual = translator.definition_to_api(definition) api = [{ "name": "OVERRIDE-NAME", "id": "MySchedule", "fields": [ { "key": "endDateTime", "stringValue": "2013-08-19T00:00:00" }, { "key": "period", "stringValue": "1 day" }, { "key": "startDateTime", "stringValue": "2013-08-18T00:00:00" }, { "key": "type", "stringValue": "Schedule" }, ] }] self.assertEqual(actual, api)
def test_convert_schedule_df_to_api(self): definition = self.load_def("""{"objects": [ { "id" : "S3ToS3Copy", "type" : "CopyActivity", "schedule" : { "ref" : "CopyPeriod" }, "input" : { "ref" : "InputData" }, "output" : { "ref" : "OutputData" } } ]}""") actual = translator.definition_to_api(definition) api = [{ "name": "S3ToS3Copy", "id": "S3ToS3Copy", "fields": [ { "key": "input", "refValue": "InputData" }, { "key": "output", "refValue": "OutputData" }, { "key": "schedule", "refValue": "CopyPeriod" }, { "key": "type", "stringValue": "CopyActivity" }, ] }] self.assertEqual(actual, api)
def test_objects_key_is_missing_raise_error(self): definition = self.load_def("""{"not-objects": []}""") with self.assertRaises(translator.PipelineDefinitionError): translator.definition_to_api(definition)
def add_to_params(self, parameters, value): if value is None: return parsed = json.loads(value) api_objects = translator.definition_to_api(parsed) parameters['pipeline_objects'] = api_objects
def test_objects_key_is_missing_raise_error(self): definition = self.load_def("""{"not-objects": []}""") with self.assertRaises(translator.PipelineDefinitionError): translator.definition_to_api(definition)