Skip to content

Instantly share code, notes, and snippets.

@almet
Created March 28, 2012 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save almet/2226393 to your computer and use it in GitHub Desktop.
Save almet/2226393 to your computer and use it in GitHub Desktop.
class Assertions(object):
"""Custom class to deal with assertions. it provides some hight level
methods that you can call to get valid or invalid assertions.
If many assertions are contained, then it will loop on them.
"""
def __init__(self, assertions):
self._assertions = assertions
def get_assertion(self, key="valid"):
"""return an assertion"""
return random.choice(self._assertions[key])
valid = functools.partial(get_assertion, key="valid")
invalid_cert = functools.partial(get_assertion, key="invalid_cert")
invalid_issuer = functools.partial(get_assertion, key="invalid_issuer")
assertions = Assertions(dict_of_assertions)
assertions.valid() # should return the same thing than assertions.get_assertion(key="valid")
@almet
Copy link
Author

almet commented Mar 28, 2012

So, this will not work as-is. I need to put the extra definitions of valid and invalid_* in the init method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment