Commits

Andriy Kornatskyy committed 6424167

Assert repository contract with looks-like checks.

  • Participants
  • Parent commits 254d237

Comments (0)

Files changed (6)

demos/template/setup.py

 README = open(os.path.join(os.path.dirname(__file__), 'README')).read()
 
 install_requires = [
-    'wheezy.core>=0.1.82',
-    'wheezy.caching>=0.1.61',
+    'wheezy.core>=0.1.83',
+    'wheezy.caching>=0.1.62',
     'wheezy.html>=0.1.109',
-    'wheezy.http>=0.1.254',
+    'wheezy.http>=0.1.255',
     'wheezy.routing>=0.1.124',
     'wheezy.security>=0.1.36',
     'wheezy.validation>=0.1.74',
-    'wheezy.web>=0.1.262',
+    'wheezy.web>=0.1.315',
 ]
 
 install_optional = [

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

 """
 """
 
+from wheezy.core.introspection import looks
+
 from config import cache
 from membership.repository import keys
 from membership.repository.contract import IMembershipRepository
 
 
-class MembershipRepository(IMembershipRepository):
+class MembershipRepository(object):
 
     def __init__(self, inner):
         self.inner = inner
         key = keys.has_account(registration.credential.username)
         cache.delete(key, namespace='membership')
         return self.inner.create_account(registration)
+
+
+assert looks(IMembershipRepository).like(MembershipRepository)

demos/template/src/membership/repository/contract.py

 
 class IMembershipRepository(object):  # pragma: nocover
 
-    def authenticate(credential):
+    def authenticate(self, credential):
         assert isinstance(credential, Credential)
         return False
 

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

 """
 
 from wheezy.core.comp import u
+from wheezy.core.introspection import looks
 
 from membership.repository.contract import IMembershipRepository
 
 
-class MembershipRepository(IMembershipRepository):
-    credentials = {
-        'demo': u('P@ssw0rd'),
-        'biz': u('P@ssw0rd')
-    }
-    roles = {
-        'demo': ['user'],
-        'biz': ['business']
-    }
+class MembershipRepository(object):
 
     def __init__(self, session):
         # ensure session is entered
         session.cursor()
 
     def authenticate(self, credential):
-        return credential.password == self.credentials.get(
+        return credential.password == credentials.get(
             credential.username, None)
 
     def has_account(self, username):
-        return username in self.credentials
+        return username in credentials
 
     def user_roles(self, username):
-        return tuple(self.roles.get(username, None))
+        return tuple(roles.get(username, None))
 
     def create_account(self, registration):
         credential = registration.credential
-        self.credentials[credential.username] = credential.password
-        self.roles[credential.username] = tuple(
+        credentials[credential.username] = credential.password
+        roles[credential.username] = tuple(
             [registration.account.account_type])
         return True
+
+
+# region: internal details
+
+credentials = {
+    'demo': u('P@ssw0rd'),
+    'biz': u('P@ssw0rd')
+}
+roles = {
+    'demo': ['user'],
+    'biz': ['business']
+}
+
+assert looks(IMembershipRepository).like(MembershipRepository)

demos/template/src/membership/service/bridge.py

 from membership.models import Registration
 from membership.validation import credential_validator
 from membership.validation import registration_validator
-from membership.service.contract import IMembershipService
 
 
-class MembershipService(IMembershipService, ValidationMixin):
+class MembershipService(ValidationMixin):
 
     def __init__(self, repository, errors, translations):
         self.repository = repository

demos/template/src/membership/service/contract.py

-"""
-"""
-
-from wheezy.core.descriptors import attribute
-
-from membership.models import Credential
-from membership.models import Registration
-
-
-class IMembershipService(object):  # pragma: nocover
-
-    @attribute
-    def password_questions(self):
-        return {'0': 'None'}
-
-    @attribute
-    def list_password_questions(self):
-        return [('0', 'None')]
-
-    @attribute
-    def account_types(self):
-        return {'0': 'None'}
-
-    @attribute
-    def list_account_types(self):
-        return [('0', 'None')]
-
-    def authenticate(self, credential):
-        assert isinstance(credential, Credential)
-        return False
-
-    def roles(self, username):
-        return tuple([])
-
-    def create_account(self, registration):
-        assert isinstance(registration, Registration)
-        return False