def test_run_command_with_missing_parameter(self):
        """
        If we miss a parameter then we should get an appropriate error.
        """
        command = Command()

        with self.assertRaises(CommandError) as cm:
            command.execute(
                self.public, self.private, stdout=StringIO(), update=False)

        self.assertEqual(
            "must provide a public keyfile, private keyfile and label",
            str(cm.exception))
        self.assertEqual(0, SshKeyPair.objects.count())
    def test_run_command_with_key_import(self):
        """
        Running the import_sshkeypair command with the correct details should
        result in the keypair being imported.
        """
        command = Command()
        command.execute(
            self.public, self.private, "testing", stdout=StringIO(),
            update=False)

        self.assertEqual("Key pair created\n", command.stdout.getvalue())
        self.assertEqual(1, SshKeyPair.objects.count())
        keypair = SshKeyPair.objects.get(label="testing")
        self.assertEqual("public key", keypair.public_key)
        self.assertEqual("private key", keypair.private_key)