def testGetSuggestedInstancesTwoDifferentSize(self, getEC2InstancesMock): regionMock = Mock(spec="boto.ec2.region.Region") regionMock.name = "us-west-2" # Instance 1 instanceMock1 = Mock(spec="boto.ec2.instance.Instance") instanceMock1.state = "running" instanceMock1.instance_type = "m3.large" instanceMock1.launch_time = "2014-05-06T15:17:33.324Z" instanceMock1.region = regionMock instanceMock1.id = "testId1" instanceMock1.tags = {"Name": "testName1"} # Instance 2 instanceMock2 = Mock(spec="boto.ec2.instance.Instance") instanceMock2.state = "running" instanceMock2.instance_type = "m3.xlarge" instanceMock2.launch_time = "2014-05-06T15:18:33.324Z" instanceMock2.region = regionMock instanceMock2.id = "testId2" instanceMock2.tags = {"Name": "testName2"} getEC2InstancesMock.return_value = [ instanceMock1, instanceMock2, ] suggestions = ec2_utils.getSuggestedInstances(regionMock.name) self.assertIsInstance(suggestions, types.GeneratorType) suggestions = list(suggestions) self.assertSequenceEqual(suggestions, [ {"id": "testId2", "name": "testName2", "namespace": "AWS/EC2", "region": regionMock.name}, {"id": "testId1", "name": "testName1", "namespace": "AWS/EC2", "region": regionMock.name}, ]) getEC2InstancesMock.assert_call_once_with(regionMock.name)
def testGetSuggestedInstancesNone(self, getEC2InstancesMock): getEC2InstancesMock.return_value = [] suggestions = ec2_utils.getSuggestedInstances("dummy-region") self.assertIsInstance(suggestions, types.GeneratorType) suggestions = list(suggestions) self.assertSequenceEqual(suggestions, []) getEC2InstancesMock.assert_call_once_with("dummy-region")
def testGetSuggestedInstancesNoRunning(self, getEC2InstancesMock): instanceMock1 = Mock(spec="boto.ec2.instance.Instance") instanceMock1.state = "stopped" getEC2InstancesMock.return_value = [ instanceMock1, ] suggestions = ec2_utils.getSuggestedInstances("dummy-region") self.assertIsInstance(suggestions, types.GeneratorType) suggestions = list(suggestions) self.assertSequenceEqual(suggestions, []) getEC2InstancesMock.assert_call_once_with("dummy-region")
def testGetSuggestedInstancesTwoDifferentSize(self, getEC2InstancesMock): regionMock = Mock(spec="boto.ec2.region.Region") regionMock.name = "us-west-2" # Instance 1 instanceMock1 = Mock(spec="boto.ec2.instance.Instance") instanceMock1.state = "running" instanceMock1.instance_type = "m3.large" instanceMock1.launch_time = "2014-05-06T15:17:33.324Z" instanceMock1.region = regionMock instanceMock1.id = "testId1" instanceMock1.tags = {"Name": "testName1"} # Instance 2 instanceMock2 = Mock(spec="boto.ec2.instance.Instance") instanceMock2.state = "running" instanceMock2.instance_type = "m3.xlarge" instanceMock2.launch_time = "2014-05-06T15:18:33.324Z" instanceMock2.region = regionMock instanceMock2.id = "testId2" instanceMock2.tags = {"Name": "testName2"} getEC2InstancesMock.return_value = [ instanceMock1, instanceMock2, ] suggestions = ec2_utils.getSuggestedInstances(regionMock.name) self.assertIsInstance(suggestions, types.GeneratorType) suggestions = list(suggestions) self.assertSequenceEqual(suggestions, [ { "id": "testId2", "name": "testName2", "namespace": "AWS/EC2", "region": regionMock.name }, { "id": "testId1", "name": "testName1", "namespace": "AWS/EC2", "region": regionMock.name }, ]) getEC2InstancesMock.assert_call_once_with(regionMock.name)