OLD | NEW |
(Empty) | |
| 1 # Copyright (c) 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved |
| 2 # |
| 3 # Permission is hereby granted, free of charge, to any person obtaining a |
| 4 # copy of this software and associated documentation files (the |
| 5 # "Software"), to deal in the Software without restriction, including |
| 6 # without limitation the rights to use, copy, modify, merge, publish, dis- |
| 7 # tribute, sublicense, and/or sell copies of the Software, and to permit |
| 8 # persons to whom the Software is furnished to do so, subject to the fol- |
| 9 # lowing conditions: |
| 10 # |
| 11 # The above copyright notice and this permission notice shall be included |
| 12 # in all copies or substantial portions of the Software. |
| 13 # |
| 14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 15 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- |
| 16 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT |
| 17 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 18 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 20 # IN THE SOFTWARE. |
| 21 # |
| 22 import unittest |
| 23 import time |
| 24 |
| 25 from boto.elastictranscoder.layer1 import ElasticTranscoderConnection |
| 26 from boto.elastictranscoder.exceptions import ValidationException |
| 27 import boto.s3 |
| 28 import boto.sns |
| 29 import boto.iam |
| 30 import boto.sns |
| 31 |
| 32 |
| 33 class TestETSLayer1PipelineManagement(unittest.TestCase): |
| 34 def setUp(self): |
| 35 self.api = ElasticTranscoderConnection() |
| 36 self.s3 = boto.connect_s3() |
| 37 self.sns = boto.connect_sns() |
| 38 self.iam = boto.connect_iam() |
| 39 self.sns = boto.connect_sns() |
| 40 self.timestamp = str(int(time.time())) |
| 41 self.input_bucket = 'boto-pipeline-%s' % self.timestamp |
| 42 self.output_bucket = 'boto-pipeline-out-%s' % self.timestamp |
| 43 self.role_name = 'boto-ets-role-%s' % self.timestamp |
| 44 self.pipeline_name = 'boto-pipeline-%s' % self.timestamp |
| 45 self.s3.create_bucket(self.input_bucket) |
| 46 self.s3.create_bucket(self.output_bucket) |
| 47 self.addCleanup(self.s3.delete_bucket, self.input_bucket) |
| 48 self.addCleanup(self.s3.delete_bucket, self.output_bucket) |
| 49 self.role = self.iam.create_role(self.role_name) |
| 50 self.role_arn = self.role['create_role_response']['create_role_result']\ |
| 51 ['role']['arn'] |
| 52 self.addCleanup(self.iam.delete_role, self.role_name) |
| 53 |
| 54 def create_pipeline(self): |
| 55 pipeline = self.api.create_pipeline( |
| 56 self.pipeline_name, self.input_bucket, |
| 57 self.output_bucket, self.role_arn, |
| 58 {'Progressing': '', 'Completed': '', 'Warning': '', 'Error': ''}) |
| 59 pipeline_id = pipeline['Pipeline']['Id'] |
| 60 |
| 61 self.addCleanup(self.api.delete_pipeline, pipeline_id) |
| 62 return pipeline_id |
| 63 |
| 64 def test_create_delete_pipeline(self): |
| 65 pipeline = self.api.create_pipeline( |
| 66 self.pipeline_name, self.input_bucket, |
| 67 self.output_bucket, self.role_arn, |
| 68 {'Progressing': '', 'Completed': '', 'Warning': '', 'Error': ''}) |
| 69 pipeline_id = pipeline['Pipeline']['Id'] |
| 70 |
| 71 self.api.delete_pipeline(pipeline_id) |
| 72 |
| 73 def test_can_retrieve_pipeline_information(self): |
| 74 pipeline_id = self.create_pipeline() |
| 75 |
| 76 # The pipeline shows up in list_pipelines |
| 77 pipelines = self.api.list_pipelines()['Pipelines'] |
| 78 pipeline_names = [p['Name'] for p in pipelines] |
| 79 self.assertIn(self.pipeline_name, pipeline_names) |
| 80 |
| 81 # The pipeline shows up in read_pipeline |
| 82 response = self.api.read_pipeline(pipeline_id) |
| 83 self.assertEqual(response['Pipeline']['Id'], pipeline_id) |
| 84 |
| 85 def test_update_pipeline(self): |
| 86 pipeline_id = self.create_pipeline() |
| 87 self.api.update_pipeline_status(pipeline_id, 'Paused') |
| 88 |
| 89 response = self.api.read_pipeline(pipeline_id) |
| 90 self.assertEqual(response['Pipeline']['Status'], 'Paused') |
| 91 |
| 92 def test_update_pipeline_notification(self): |
| 93 pipeline_id = self.create_pipeline() |
| 94 response = self.sns.create_topic('pipeline-errors') |
| 95 topic_arn = response['CreateTopicResponse']['CreateTopicResult']\ |
| 96 ['TopicArn'] |
| 97 self.addCleanup(self.sns.delete_topic, topic_arn) |
| 98 |
| 99 self.api.update_pipeline_notifications( |
| 100 pipeline_id, |
| 101 {'Progressing': '', 'Completed': '', |
| 102 'Warning': '', 'Error': topic_arn}) |
| 103 |
| 104 response = self.api.read_pipeline(pipeline_id) |
| 105 self.assertEqual(response['Pipeline']['Notifications']['Error'], |
| 106 topic_arn) |
| 107 |
| 108 def test_list_jobs_by_pipeline(self): |
| 109 pipeline_id = self.create_pipeline() |
| 110 response = self.api.list_jobs_by_pipeline(pipeline_id) |
| 111 self.assertEqual(response['Jobs'], []) |
| 112 |
| 113 def test_proper_error_when_pipeline_does_not_exist(self): |
| 114 with self.assertRaises(ValidationException): |
| 115 self.api.read_pipeline('badpipelineid') |
OLD | NEW |