Adding new tests to cover failure scenarios
I also removed a line of code from coverage as it seems the general practice is to ignore these lines in test coverage. This change will bring us to 100% coverage. Change-Id: I49f9de25389935f1d7b82559b41ed605eb77cb2e
This commit is contained in:
parent
5ef33c2da8
commit
282a1e3fa5
|
@ -1,3 +1,3 @@
|
||||||
[run]
|
[run]
|
||||||
branch = True
|
branch = True
|
||||||
omit = barbicanclient/openstack/*,barbicanclient/tests/*
|
omit = barbicanclient/openstack/*,barbicanclient/tests/*
|
|
@ -74,7 +74,7 @@ class Barbican(app.App):
|
||||||
else:
|
else:
|
||||||
if not any(v2_arg_combinations):
|
if not any(v2_arg_combinations):
|
||||||
msg = ('ERROR: please specify --os-tenant-id or'
|
msg = ('ERROR: please specify --os-tenant-id or'
|
||||||
'--os-tenant-name')
|
' --os-tenant-name')
|
||||||
successful = False
|
successful = False
|
||||||
|
|
||||||
if not successful and raise_exc:
|
if not successful and raise_exc:
|
||||||
|
@ -276,6 +276,5 @@ def main(argv=sys.argv[1:]):
|
||||||
barbican_app = Barbican()
|
barbican_app = Barbican()
|
||||||
return barbican_app.run(argv)
|
return barbican_app.run(argv)
|
||||||
|
|
||||||
|
if __name__ == '__main__': # pragma: no cover
|
||||||
if __name__ == '__main__':
|
|
||||||
sys.exit(main(sys.argv[1:]))
|
sys.exit(main(sys.argv[1:]))
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
import six
|
import six
|
||||||
|
|
||||||
|
from barbicanclient import barbican as barb
|
||||||
from barbicanclient.tests import keystone_client_fixtures
|
from barbicanclient.tests import keystone_client_fixtures
|
||||||
from barbicanclient.tests import test_client
|
from barbicanclient.tests import test_client
|
||||||
from barbicanclient.barbican import Barbican
|
from barbicanclient.barbican import Barbican
|
||||||
|
@ -108,6 +109,53 @@ class WhenTestingBarbicanCLI(test_client.BaseEntityResource):
|
||||||
expected_error_msg
|
expected_error_msg
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_check_auth_arguments_v2(self):
|
||||||
|
args = ("--os-username 'bob' --os-password 'jan' --os-auth-url 'boop'"
|
||||||
|
" --os-tenant-id 123 --os-identity-api-version '2.0'")
|
||||||
|
argv, remainder = self.parser.parse_known_args(args.split())
|
||||||
|
api_version = argv.os_identity_api_version
|
||||||
|
barbican = Barbican()
|
||||||
|
response = barbican.check_auth_arguments(argv, api_version)
|
||||||
|
self.assertEqual(True, response)
|
||||||
|
|
||||||
|
def test_should_fail_check_auth_arguments_v2(self):
|
||||||
|
args = ("--os-username bob --os-password jan --os-auth-url boop"
|
||||||
|
" --os-identity-api-version 2.0")
|
||||||
|
message = 'ERROR: please specify --os-tenant-id or --os-tenant-name'
|
||||||
|
argv, remainder = self.parser.parse_known_args(args.split())
|
||||||
|
api_version = argv.os_identity_api_version
|
||||||
|
e = self.assertRaises(
|
||||||
|
Exception,
|
||||||
|
self.barbican.check_auth_arguments,
|
||||||
|
argv,
|
||||||
|
api_version,
|
||||||
|
True
|
||||||
|
)
|
||||||
|
self.assertIn(message, str(e))
|
||||||
|
|
||||||
|
def test_should_fail_create_client_with_no_auth_url(self):
|
||||||
|
args = '--os-auth-token 1234567890 --os-tenant-id 123'
|
||||||
|
message = 'ERROR: please specify --os-auth-url'
|
||||||
|
argv, remainder = self.parser.parse_known_args(args.split())
|
||||||
|
e = self.assertRaises(
|
||||||
|
Exception, self.barbican.create_client, argv
|
||||||
|
)
|
||||||
|
self.assertIn(message, str(e))
|
||||||
|
|
||||||
|
def test_should_fail_missing_credentials(self):
|
||||||
|
message = 'ERROR: please specify authentication credentials'
|
||||||
|
args = ''
|
||||||
|
argv, remainder = self.parser.parse_known_args(args.split())
|
||||||
|
e = self.assertRaises(
|
||||||
|
Exception, self.barbican.create_client, argv
|
||||||
|
)
|
||||||
|
self.assertIn(message, str(e))
|
||||||
|
|
||||||
|
def test_main(self):
|
||||||
|
args = ''
|
||||||
|
response = barb.main(args)
|
||||||
|
self.assertEqual(1, response)
|
||||||
|
|
||||||
|
|
||||||
class TestBarbicanWithKeystonePasswordAuth(
|
class TestBarbicanWithKeystonePasswordAuth(
|
||||||
keystone_client_fixtures.KeystoneClientFixture):
|
keystone_client_fixtures.KeystoneClientFixture):
|
||||||
|
|
Loading…
Reference in New Issue