wheezy.web / demos / template / src / membership / repository / mock.py

"""
"""


from wheezy.core.collections import map_values
from wheezy.core.collections import sorted_items
from wheezy.core.i18n import ref_gettext

from config import translations
from membership.repository.samples import db


translations = translations.domains['membership']


class MembershipRepository(object):

    def __init__(self, session):
        # ensure session is entered
        session.cursor()

    def password_questions(self, locale):
        return map_values(ref_gettext(translations[locale]),
                          db['password_question'])

    def list_password_questions(self, locale):
        return tuple(sorted_items(self.password_questions(locale)))

    def account_types(self, locale):
        return map_values(ref_gettext(translations[locale]),
                          db['account_type'])

    def list_account_types(self, locale):
        return tuple(sorted_items(self.account_types(locale)))

    def authenticate(self, credential):
        return credential.password == db['user'].get(
            credential.username, None)

    def has_account(self, username):
        return username in db['user']

    def user_roles(self, username):
        return tuple(db['user_role'].get(username, None))

    def create_account(self, registration):
        credential = registration.credential
        db['user'][credential.username] = credential.password
        db['user_role'][credential.username] = tuple(
            [registration.account.account_type])
        return True


# region: internal details

from wheezy.core.introspection import looks
from membership.repository.contract import IMembershipRepository
assert looks(MembershipRepository).like(IMembershipRepository)
assert looks(IMembershipRepository).like(MembershipRepository)
del looks, IMembershipRepository
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.