Created
December 4, 2013 12:27
-
-
Save bogsio/7786691 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User: | |
def __init__(self, firstname='John', lastname='Smith', is_admin=False): | |
self.firstname = firstname | |
self.lastname = lastname | |
self.is_admin = is_admin | |
def __str__(self): | |
return "User[%s %s%s]" % (self.firstname, self.lastname, | |
' Administrator' if self.is_admin else '') | |
def postlist(user): | |
if user: | |
return 'This is the public postlist of user %s %s' % (user.firstname, user.lastname) | |
return None | |
def userlist(user): | |
return 'This is the whole registered user list. [Sensitive data]' | |
def inventory(user): | |
return 'This is the inventory resource. [Sensitive data]' | |
# Tests | |
stan = User('Stan', 'Smith', False) | |
peter = User('Peter', 'Griffin', True) | |
assert postlist(None) is None | |
assert postlist(stan) is not None | |
assert postlist(peter) is not None | |
assert userlist(None) is None | |
assert userlist(stan) is None | |
assert userlist(peter) is not None | |
assert inventory(None) is None | |
assert inventory(stan) is None | |
assert inventory(peter) is not None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment