test_key_pair.py (ec2-api-14.0.1) | : | test_key_pair.py (ec2-api-15.0.0) | ||
---|---|---|---|---|
skipping to change at line 16 | skipping to change at line 16 | |||
# You may obtain a copy of the License at | # You may obtain a copy of the License at | |||
# http://www.apache.org/licenses/LICENSE-2.0 | # http://www.apache.org/licenses/LICENSE-2.0 | |||
# | # | |||
# Unless required by applicable law or agreed to in writing, software | # Unless required by applicable law or agreed to in writing, software | |||
# distributed under the License is distributed on an "AS IS" BASIS, | # distributed under the License is distributed on an "AS IS" BASIS, | |||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
# See the License for the specific language governing permissions and | # See the License for the specific language governing permissions and | |||
# limitations under the License. | # limitations under the License. | |||
import base64 | import base64 | |||
from unittest import mock | ||||
from novaclient import exceptions as nova_exception | from novaclient import exceptions as nova_exception | |||
from ec2api.tests.unit import base | from ec2api.tests.unit import base | |||
from ec2api.tests.unit import fakes | from ec2api.tests.unit import fakes | |||
from ec2api.tests.unit import matchers | from ec2api.tests.unit import matchers | |||
from ec2api.tests.unit import tools | from ec2api.tests.unit import tools | |||
class KeyPairCase(base.ApiTestCase): | class KeyPairCase(base.ApiTestCase): | |||
def test_create_key_pair(self): | @mock.patch('ec2api.api.key_pair._generate_key_pair') | |||
def test_create_key_pair(self, _generate_key_pair): | ||||
_generate_key_pair.return_value = ( | ||||
fakes.PRIVATE_KEY_KEY_PAIR, fakes.PUBLIC_KEY_KEY_PAIR) | ||||
self.nova.keypairs.create.return_value = ( | self.nova.keypairs.create.return_value = ( | |||
fakes.NovaKeyPair(fakes.OS_KEY_PAIR)) | fakes.NovaKeyPair(fakes.OS_KEY_PAIR)) | |||
resp = self.execute('CreateKeyPair', {'KeyName': fakes.NAME_KEY_PAIR}) | resp = self.execute('CreateKeyPair', {'KeyName': fakes.NAME_KEY_PAIR}) | |||
self.assertThat(fakes.EC2_KEY_PAIR, matchers.DictMatches(resp)) | self.assertThat(fakes.EC2_KEY_PAIR, matchers.DictMatches(resp)) | |||
self.nova.keypairs.create.assert_called_once_with(fakes.NAME_KEY_PAIR) | _generate_key_pair.assert_called_once_with() | |||
def test_create_key_pair_invalid(self): | def test_create_key_pair_invalid(self): | |||
self.nova.keypairs.create.side_effect = ( | self.nova.keypairs.create.side_effect = ( | |||
nova_exception.Conflict(409)) | nova_exception.Conflict(409)) | |||
self.assert_execution_error( | self.assert_execution_error( | |||
'InvalidKeyPair.Duplicate', 'CreateKeyPair', | 'InvalidKeyPair.Duplicate', 'CreateKeyPair', | |||
{'KeyName': fakes.NAME_KEY_PAIR}) | {'KeyName': fakes.NAME_KEY_PAIR}) | |||
self.assert_execution_error( | self.assert_execution_error( | |||
'ValidationError', 'CreateKeyPair', {'KeyName': 'k' * 256}) | 'ValidationError', 'CreateKeyPair', {'KeyName': 'k' * 256}) | |||
self.nova.keypairs.create.side_effect = ( | self.nova.keypairs.create.side_effect = ( | |||
End of changes. 3 change blocks. | ||||
2 lines changed or deleted | 6 lines changed or added |