mirror of
https://github.com/kakwa/ldapcherry
synced 2024-11-22 09:24:21 +01:00
adding an exception for failures to open role file
This commit is contained in:
parent
17b8aa6406
commit
804e2b7202
@ -9,6 +9,7 @@ class MissingParameter(Exception):
|
||||
def __init__(self, section, key):
|
||||
self.section = section
|
||||
self.key = key
|
||||
self.log = "missing parameter <%(key)s> in section <%(section)s>" % { 'key' : key, 'section' : section }
|
||||
|
||||
class MissingKey(Exception):
|
||||
def __init__(self, key):
|
||||
@ -17,8 +18,17 @@ class MissingKey(Exception):
|
||||
class DumplicateRoleKey(Exception):
|
||||
def __init__(self, role):
|
||||
self.role = role
|
||||
self.log = "duplicate role key <%(role)s> in role file" % { 'role' : role}
|
||||
|
||||
class DumplicateRoleContent(Exception):
|
||||
def __init__(self, role1, role2):
|
||||
self.role1 = role1
|
||||
self.role2 = role2
|
||||
self.log = "role <%(role1)s> and <%(role2)s> are identical" % { 'role1' : role1, 'role2': role2}
|
||||
|
||||
class MissingRolesFile(Exception):
|
||||
def __init__(self, rolefile):
|
||||
self.rolefile = rolefile
|
||||
self.log = "fail to open role file <%(rolefile)s>" % { 'rolefile' : rolefile}
|
||||
|
||||
|
||||
|
@ -10,13 +10,16 @@ import sys
|
||||
|
||||
from ldapcherry.pyyamlwrapper import loadNoDump
|
||||
from ldapcherry.pyyamlwrapper import DumplicatedKey
|
||||
from ldapcherry.exceptions import DumplicateRoleKey, MissingKey, DumplicateRoleContent
|
||||
from ldapcherry.exceptions import DumplicateRoleKey, MissingKey, DumplicateRoleContent, MissingRolesFile
|
||||
|
||||
|
||||
class Roles:
|
||||
|
||||
def __init__(self, role_file):
|
||||
try:
|
||||
stream = open(role_file, 'r')
|
||||
except:
|
||||
raise MissingRolesFile(role_file)
|
||||
try:
|
||||
self.roles_raw = loadNoDump(stream)
|
||||
except DumplicatedKey as e:
|
||||
|
@ -7,7 +7,7 @@ from __future__ import unicode_literals
|
||||
import pytest
|
||||
import sys
|
||||
from ldapcherry.roles import Roles
|
||||
from ldapcherry.exceptions import DumplicateRoleKey, MissingKey, DumplicateRoleContent
|
||||
from ldapcherry.exceptions import DumplicateRoleKey, MissingKey, DumplicateRoleContent, MissingRolesFile
|
||||
from ldapcherry.pyyamlwrapper import DumplicatedKey, RelationError
|
||||
|
||||
|
||||
@ -34,6 +34,15 @@ class TestError(object):
|
||||
else:
|
||||
raise AssertionError("expected an exception")
|
||||
|
||||
|
||||
def testNoFile(self):
|
||||
try:
|
||||
inv = Roles('./tests/cfg/dontexist')
|
||||
except MissingRolesFile:
|
||||
return
|
||||
else:
|
||||
raise AssertionError("expected an exception")
|
||||
|
||||
def testRoleContentDuplication(self):
|
||||
try:
|
||||
inv = Roles('./tests/cfg/roles_content_dump.yml')
|
||||
|
Loading…
Reference in New Issue
Block a user