Commits

Andriy Kornatskyy committed d4384ac

Minor refactoring in repository.

  • Participants
  • Parent commits ed41086

Comments (0)

Files changed (3)

File demos/template/setup.py

 README = open(os.path.join(os.path.dirname(__file__), 'README')).read()
 
 install_requires = [
-    'wheezy.core>=0.1.86',
+    'wheezy.core>=0.1.87',
     'wheezy.caching>=0.1.62',
     'wheezy.html>=0.1.109',
     'wheezy.http>=0.1.255',

File demos/template/src/membership/repository/caching.py

 from wheezy.core.introspection import looks
 assert looks(MembershipRepository).like(IMembershipRepository)
 assert looks(IMembershipRepository).like(MembershipRepository)
-del looks
+del looks, IMembershipRepository

File demos/template/src/membership/repository/mock.py

 """
 """
 
-from operator import itemgetter
 
+from wheezy.core.collections import map_values
+from wheezy.core.collections import sorted_items
 from wheezy.core.comp import u
 from wheezy.core.i18n import ref_gettext
 
         session.cursor()
 
     def password_questions(self, locale):
-        gettext = ref_gettext(translations[locale])
-        return dict([(key, gettext(value))
-                     for key, value in db['password_question'].items()])
+        return map_values(ref_gettext(translations[locale]),
+                          db['password_question'])
 
     def list_password_questions(self, locale):
-        return sorted(self.password_questions(locale).items(),
-                      key=itemgetter(1))
+        return tuple(sorted_items(self.password_questions(locale)))
 
     def account_types(self, locale):
-        gettext = ref_gettext(translations[locale])
-        return dict([(key, gettext(value))
-                     for key, value in db['account_type'].items()])
+        return map_values(ref_gettext(translations[locale]),
+                          db['account_type'])
 
     def list_account_types(self, locale):
-        return sorted(self.account_types(locale).items(),
-                      key=itemgetter(1))
+        return tuple(sorted_items(self.account_types(locale)))
 
     def authenticate(self, credential):
         return credential.password == db['user'].get(
         return username in db['user']
 
     def user_roles(self, username):
-        return tuple(db['role'].get(username, None))
+        return tuple(db['user_role'].get(username, None))
 
     def create_account(self, registration):
         credential = registration.credential
         db['user'][credential.username] = credential.password
-        db['role'][credential.username] = tuple(
+        db['user_role'][credential.username] = tuple(
             [registration.account.account_type])
         return True
 
         'demo': u('P@ssw0rd'),
         'biz': u('P@ssw0rd')
     },
-    'role': {
+    'user_role': {
         'demo': ['user'],
         'biz': ['business']
     },
 from wheezy.core.introspection import looks
 assert looks(MembershipRepository).like(IMembershipRepository)
 assert looks(IMembershipRepository).like(MembershipRepository)
-del looks
+del looks, IMembershipRepository