# Make a module and provide some skeleton adapters, factories, and tools
from zope.interface import implements
from zope.interface import implementedBy
from zope.component.interfaces import IFactory
from zope.annotation.attribute import AttributeAnnotations

from OFS.Folder import Folder

from Products.listen.interfaces import ISubscriptionList

from test_content import setup_utility

# A dummy subscription adapter
class Subscriptions(object):
     implements(ISubscriptionList)
     subscribers = (u'addr1@example.com',u'addr2@example.com')
     def __init__(self, context):
          self.context = context

# A dummy "Mailing List' which is Anotatable, for use with Subscription
# interfaces
class DummyAnnotableList(AttributeAnnotations):
     reset = False
     def __init__(self):
          AttributeAnnotations.__init__(self, self)
          def resetBounces(self, addresses): self.reset = True

# Some dummy CMF objects
class DummyMembershipTool(object):
     def __init__(self, user):
          self.user = user
     def isAnonymousUser(self):
          return self.user.getId() == 'anon'
     def getAuthenticatedMember(self):
          return self.user
     def getMemberById(self, user_id):
          return getattr(self, user_id)
     def searchForMembers(self, **kw):
          email = kw['email']
          for i in self.__dict__:
               prop = self.__dict__[i]
               if type(prop) is DummyMember:
                    if prop.email == email:
                         return [prop]

          return None


class DummyMember(object):
     def __init__(self, id, fullname, email):
          self.id = id
          self.fullname = fullname
          self.email = email
     def getId(self):
          return self.id
     def getProperty(self, prop, default=None):
          return getattr(self, prop, default)
    # for brain conversion
     def _getObject(self):
          return self

# Dummy factories
class SimpleFolderFactory:
    implements(IFactory)
    def __call__(self, id, title, **kwargs):
         folder = Folder(id)
         folder.title = title
         return folder
    
    def getInterfaces(self):
         return implementedBy(Folder)
    
SimpleFolderFactory = SimpleFolderFactory()
