|
31 | 31 | mock_emr = None
|
32 | 32 |
|
33 | 33 |
|
| 34 | +@unittest.skipIf(mock_emr is None, 'moto package not present') |
34 | 35 | class TestEmrHook(unittest.TestCase):
|
35 | 36 | @mock_emr
|
36 | 37 | def setUp(self):
|
37 | 38 | configuration.load_test_config()
|
38 | 39 |
|
39 |
| - @unittest.skipIf(mock_emr is None, 'mock_emr package not present') |
40 | 40 | @mock_emr
|
41 | 41 | def test_get_conn_returns_a_boto3_connection(self):
|
42 | 42 | hook = EmrHook(aws_conn_id='aws_default')
|
43 | 43 | self.assertIsNotNone(hook.get_conn().list_clusters())
|
44 | 44 |
|
45 |
| - @unittest.skipIf(mock_emr is None, 'mock_emr package not present') |
46 | 45 | @mock_emr
|
47 | 46 | def test_create_job_flow_uses_the_emr_config_to_create_a_cluster(self):
|
48 | 47 | client = boto3.client('emr', region_name='us-east-1')
|
49 |
| - if len(client.list_clusters()['Clusters']): |
50 |
| - raise ValueError('AWS not properly mocked') |
51 | 48 |
|
52 | 49 | hook = EmrHook(aws_conn_id='aws_default', emr_conn_id='emr_default')
|
53 | 50 | cluster = hook.create_job_flow({'Name': 'test_cluster'})
|
54 | 51 |
|
55 |
| - self.assertEqual(client.list_clusters()['Clusters'][0]['Id'], cluster['JobFlowId']) |
| 52 | + self.assertEqual(client.list_clusters()['Clusters'][0]['Id'], |
| 53 | + cluster['JobFlowId']) |
| 54 | + |
| 55 | + @mock_emr |
| 56 | + def test_create_job_flow_extra_args(self): |
| 57 | + """ |
| 58 | + Test that we can add extra arguments to the launch call. |
| 59 | +
|
| 60 | + This is useful for when AWS add new options, such as |
| 61 | + "SecurityConfiguration" so that we don't have to change our code |
| 62 | + """ |
| 63 | + client = boto3.client('emr', region_name='us-east-1') |
| 64 | + |
| 65 | + hook = EmrHook(aws_conn_id='aws_default', emr_conn_id='emr_default') |
| 66 | + # AmiVersion is really old and almost no one will use it anymore, but |
| 67 | + # it's one of the "optional" request params that moto supports - it's |
| 68 | + # coverage of EMR isn't 100% it turns out. |
| 69 | + cluster = hook.create_job_flow({'Name': 'test_cluster', |
| 70 | + 'ReleaseLabel': '', |
| 71 | + 'AmiVersion': '3.2'}) |
| 72 | + |
| 73 | + cluster = client.describe_cluster(ClusterId=cluster['JobFlowId'])['Cluster'] |
| 74 | + |
| 75 | + # The AmiVersion comes back as {Requested,Running}AmiVersion fields. |
| 76 | + self.assertEqual(cluster['RequestedAmiVersion'], '3.2') |
56 | 77 |
|
57 | 78 | if __name__ == '__main__':
|
58 | 79 | unittest.main()
|
0 commit comments