Browse Source

Update tests

Use self.fail instead of self.assertTrue(false)
pull/1240/head
hparfr 7 years ago
parent
commit
0091bd0c6d
  1. 16
      keychain/tests/test_keychain.py

16
keychain/tests/test_keychain.py

@ -79,14 +79,14 @@ class TestKeychain(TransactionCase):
config['keychain_key'] = Fernet.generate_key() config['keychain_key'] = Fernet.generate_key()
try: try:
account._get_password() account._get_password()
self.assertTrue(False, 'It should not work with another key')
self.fail('It should not work with another key')
except UserError as err: except UserError as err:
self.assertTrue(True, 'It should raise a UserError') self.assertTrue(True, 'It should raise a UserError')
self.assertTrue( self.assertTrue(
'has been encrypted with a diff' in str(err), 'has been encrypted with a diff' in str(err),
'It should display the right msg') 'It should display the right msg')
else: else:
self.assertTrue(False, 'It should raise a UserError')
self.fail('It should raise a UserError')
def test_no_key(self): def test_no_key(self):
"""It should raise an exception when no key is set.""" """It should raise an exception when no key is set."""
@ -96,7 +96,7 @@ class TestKeychain(TransactionCase):
with self.assertRaises(UserError) as err: with self.assertRaises(UserError) as err:
account.clear_password = 'aiuepr' account.clear_password = 'aiuepr'
account._inverse_set_password() account._inverse_set_password()
self.assertTrue(False, 'It should not work without key')
self.fail('It should not work without key')
self.assertTrue( self.assertTrue(
'Use a key similar to' in str(err.exception), 'Use a key similar to' in str(err.exception),
'It should display the right msg') 'It should display the right msg')
@ -109,7 +109,7 @@ class TestKeychain(TransactionCase):
with self.assertRaises(UserError): with self.assertRaises(UserError):
account.clear_password = 'aiuepr' account.clear_password = 'aiuepr'
account._inverse_set_password() account._inverse_set_password()
self.assertTrue(False, 'It should not work missing formated key')
self.fail('It should not work missing formated key')
self.assertTrue(True, 'It shoud raise a ValueError') self.assertTrue(True, 'It shoud raise a ValueError')
@ -193,9 +193,7 @@ class TestKeychain(TransactionCase):
for json in wrong_jsons: for json in wrong_jsons:
with self.assertRaises(ValidationError) as err: with self.assertRaises(ValidationError) as err:
account.write({"data": json}) account.write({"data": json})
self.assertTrue(
False,
'Should not validate baddly formatted json')
self.fail('Should not validate baddly formatted json')
self.assertTrue( self.assertTrue(
'Data should be a valid JSON' in str(err.exception), 'Data should be a valid JSON' in str(err.exception),
'It should raise a ValidationError') 'It should raise a ValidationError')
@ -220,7 +218,7 @@ class TestKeychain(TransactionCase):
account.write({"data": json}) account.write({"data": json})
self.assertTrue(True, 'Should validate json') self.assertTrue(True, 'Should validate json')
except: except:
self.assertTrue(False, 'It should validate a good json')
self.fail('It should validate a good json')
def test_default_init_and_valid(self): def test_default_init_and_valid(self):
""".""" """."""
@ -236,7 +234,7 @@ class TestKeychain(TransactionCase):
try: try:
account.write({"login": "test default"}) account.write({"login": "test default"})
except ValidationError: except ValidationError:
self.assertTrue(False, 'It should validate any json in default')
self.fail('It should validate any json in default')
self.assertEqual( self.assertEqual(
account.data, account._serialize_data( account.data, account._serialize_data(

Loading…
Cancel
Save