# Path: pupa/scrape/jurisdiction.py
# class Jurisdiction(BaseModel):
#     """ Base class for a jurisdiction """
# 
#     _type = 'jurisdiction'
#     _schema = schema
# 
#     # schema objects
#     classification = None
#     name = None
#     url = None
#     legislative_sessions = []
#     feature_flags = []
#     extras = {}
# 
#     # non-db properties
#     scrapers = {}
#     default_scrapers = None
#     parties = []
#     ignored_scraped_sessions = []
# 
#     def __init__(self):
#         super(BaseModel, self).__init__()
#         self._related = []
#         self.extras = {}
# 
#     @property
#     def jurisdiction_id(self):
#         return '{}/{}'.format(self.division_id.replace('ocd-division', 'ocd-jurisdiction'),
#                               self.classification)
# 
#     _id = jurisdiction_id
# 
#     def as_dict(self):
#         return {'_id': self.jurisdiction_id, 'id': self.jurisdiction_id,
#                 'name': self.name, 'url': self.url, 'division_id': self.division_id,
#                 'classification': self.classification,
#                 'legislative_sessions': self.legislative_sessions,
#                 'feature_flags': self.feature_flags, 'extras': self.extras, }
# 
#     def __str__(self):
#         return self.name
# 
#     def get_organizations(self):
#         raise NotImplementedError('get_organizations is not implemented')   # pragma: no cover
# 
# class JurisdictionScraper(Scraper):
#     def scrape(self):
#         # yield a single Jurisdiction object
#         yield self.jurisdiction
# 
#         # yield all organizations
#         for org in self.jurisdiction.get_organizations():
#             yield org
# 
#         if self.jurisdiction.parties:
#             warnings.warn('including parties on Jurisdiction is deprecated, '
#                           'use "pupa party" command instead')
#         for party in self.jurisdiction.parties:
#             org = Organization(classification='party', name=party['name'])
#             yield org
# 
# Path: pupa/scrape/popolo.py
# class Organization(BaseModel, SourceMixin, ContactDetailMixin, LinkMixin, IdentifierMixin,
#                    OtherNameMixin):
#     """
#     A single popolo-style Organization
#     """
# 
#     _type = 'organization'
#     _schema = org_schema
# 
#     def __init__(self, name, *, classification='', parent_id=None,
#                  founding_date='', dissolution_date='', image='',
#                  chamber=None):
#         """
#         Constructor for the Organization object.
#         """
#         super(Organization, self).__init__()
#         self.name = name
#         self.classification = classification
#         self.founding_date = founding_date
#         self.dissolution_date = dissolution_date
#         self.parent_id = pseudo_organization(parent_id, chamber)
#         self.image = image
# 
#     def __str__(self):
#         return self.name
# 
#     def validate(self):
#         schema = None
#         # these are implicitly declared & do not require sources
#         if self.classification in ('party', 'legislature', 'upper', 'lower', 'executive'):
#             schema = org_schema_no_sources
#         return super(Organization, self).validate(schema=schema)
# 
#     def add_post(self, label, role, **kwargs):
#         post = Post(label=label, role=role, organization_id=self._id, **kwargs)
#         self._related.append(post)
#         return post
# 
#     def add_member(self, name_or_person, role='member', **kwargs):
#         if isinstance(name_or_person, Person):
#             membership = Membership(person_id=name_or_person._id,
#                                     person_name=name_or_person.name,
#                                     organization_id=self._id,
#                                     role=role, **kwargs)
#         else:
#             membership = Membership(person_id=_make_pseudo_id(name=name_or_person),
#                                     person_name=name_or_person,
#                                     organization_id=self._id, role=role, **kwargs)
#         self._related.append(membership)
#         return membership


from collections import defaultdict
from pupa.scrape import Jurisdiction, Organization, JurisdictionScraper


class FakeJurisdiction(Jurisdiction):
    division_id = 'ocd-division/test'
    classification = 'government'
    name = 'Test'
    url = 'http://example.com'

    def get_organizations(self):
        parent = Organization('Congress', classification='legislature')
        yield parent

# Path: pupa/scrape/jurisdiction.py
# class Jurisdiction(BaseModel):
#     """ Base class for a jurisdiction """
# 
#     _type = 'jurisdiction'
#     _schema = schema
# 
#     # schema objects
#     classification = None
#     name = None
#     url = None
#     legislative_sessions = []
#     feature_flags = []
#     extras = {}
# 
#     # non-db properties
#     scrapers = {}
#     default_scrapers = None
#     parties = []
#     ignored_scraped_sessions = []
# 
#     def __init__(self):
#         super(BaseModel, self).__init__()
#         self._related = []
#         self.extras = {}
# 
#     @property
#     def jurisdiction_id(self):
#         return '{}/{}'.format(self.division_id.replace('ocd-division', 'ocd-jurisdiction'),
#                               self.classification)
# 
#     _id = jurisdiction_id
# 
#     def as_dict(self):
#         return {'_id': self.jurisdiction_id, 'id': self.jurisdiction_id,
#                 'name': self.name, 'url': self.url, 'division_id': self.division_id,
#                 'classification': self.classification,
#                 'legislative_sessions': self.legislative_sessions,
#                 'feature_flags': self.feature_flags, 'extras': self.extras, }
# 
#     def __str__(self):
#         return self.name
# 
#     def get_organizations(self):
#         raise NotImplementedError('get_organizations is not implemented')   # pragma: no cover
# 
# class JurisdictionScraper(Scraper):
#     def scrape(self):
#         # yield a single Jurisdiction object
#         yield self.jurisdiction
# 
#         # yield all organizations
#         for org in self.jurisdiction.get_organizations():
#             yield org
# 
#         if self.jurisdiction.parties:
#             warnings.warn('including parties on Jurisdiction is deprecated, '
#                           'use "pupa party" command instead')
#         for party in self.jurisdiction.parties:
#             org = Organization(classification='party', name=party['name'])
#             yield org
# 
# Path: pupa/scrape/popolo.py
# class Organization(BaseModel, SourceMixin, ContactDetailMixin, LinkMixin, IdentifierMixin,
#                    OtherNameMixin):
#     """
#     A single popolo-style Organization
#     """
# 
#     _type = 'organization'
#     _schema = org_schema
# 
#     def __init__(self, name, *, classification='', parent_id=None,
#                  founding_date='', dissolution_date='', image='',
#                  chamber=None):
#         """
#         Constructor for the Organization object.
#         """
#         super(Organization, self).__init__()
#         self.name = name
#         self.classification = classification
#         self.founding_date = founding_date
#         self.dissolution_date = dissolution_date
#         self.parent_id = pseudo_organization(parent_id, chamber)
#         self.image = image
# 
#     def __str__(self):
#         return self.name
# 
#     def validate(self):
#         schema = None
#         # these are implicitly declared & do not require sources
#         if self.classification in ('party', 'legislature', 'upper', 'lower', 'executive'):
#             schema = org_schema_no_sources
#         return super(Organization, self).validate(schema=schema)
# 
#     def add_post(self, label, role, **kwargs):
#         post = Post(label=label, role=role, organization_id=self._id, **kwargs)
#         self._related.append(post)
#         return post
# 
#     def add_member(self, name_or_person, role='member', **kwargs):
#         if isinstance(name_or_person, Person):
#             membership = Membership(person_id=name_or_person._id,
#                                     person_name=name_or_person.name,
#                                     organization_id=self._id,
#                                     role=role, **kwargs)
#         else:
#             membership = Membership(person_id=_make_pseudo_id(name=name_or_person),
#                                     person_name=name_or_person,
#                                     organization_id=self._id, role=role, **kwargs)
#         self._related.append(membership)
#         return membership


# Path: pupa/tests/scrape/test_jurisdiction_scrape.py
from collections import defaultdict
from pupa.scrape import Jurisdiction, Organization, JurisdictionScraper



class FakeJurisdiction(Jurisdiction):
    division_id = 'ocd-division/test'
    classification = 'government'
    name = 'Test'
    url = 'http://example.com'

    def get_organizations(self):
        parent = Organization('Congress', classification='legislature')
        yield parent

        yield Organization('House', classification='lower', parent_id=parent)