Bläddra i källkod

add one test for CryptoEngine

also do some stuff in more pythonic way
oz123 11 år sedan
förälder
incheckning
f2c90c79b3
2 ändrade filer med 6 tillägg och 6 borttagningar
  1. 2 2
      pwman/util/crypto.py
  2. 4 4
      tests/crypto_tests.py

+ 2 - 2
pwman/util/crypto.py

@@ -118,7 +118,7 @@ class CryptoPasswordMismatchException(CryptoException):
         return "CryptoPasswordMismatchException: " + self.message
 
 
-class CryptoEngine:
+class CryptoEngine(object):
     """Cryptographic Engine"""
     _timeoutcount = 0
     _instance = None
@@ -151,7 +151,7 @@ class CryptoEngine:
                              Default is -1 (disabled).
         """
         algo = config.get_value("Encryption", "algorithm")
-        if len(algo) > 0:
+        if algo:
             self._algo = algo
         else:
             raise CryptoException("Parameters missing, no algorithm given")

+ 4 - 4
tests/crypto_tests.py

@@ -1,8 +1,9 @@
 import pwman.util.config as config
+import os
 import pwman.data.factory
 from pwman.data.nodes import NewNode
 from pwman.data.tags import Tag
-
+from pwman.util.crypto import CryptoEngine, CryptoException
 # set cls_timout to negative number (e.g. -1) to disable
 default_config = {'Global': {'umask': '0100', 'colors': 'yes',
                              'cls_timeout': '5'
@@ -21,9 +22,8 @@ import unittest
 class CryptoTest(unittest.TestCase):
 
     def test_no_algorithm(self):
-        # TODO: set config to no algorithm
-        # check that the proper exception is raised
-        self.assertRaises()
+        config.set_value('Encryption', 'algorithm', '')
+        self.assertRaises((CryptoException,), CryptoEngine)
 
         # TODO: write a white box test for each
         #       method in CryptoEngine