コード例 #1
0
    def __init__(self, _db, collection=None, *args, **kwargs):
        self.access_token_requests = []
        self.requests = []
        self.responses = []

        if not collection:
            # OverdriveAPI needs a Collection, but none was provided.
            # Just create a basic one.
            library = Library.instance(_db)
            collection, ignore = get_one_or_create(
                _db,
                Collection,
                name="Test Overdrive Collection",
                protocol=Collection.OVERDRIVE,
                create_method_kwargs=dict(external_account_id=u'c'))
            collection.external_integration.username = u'a'
            collection.external_integration.password = u'b'
            collection.external_integration.set_setting('website_id', 'd')
            library.collections.append(collection)

        # The constructor will always make a request for the collection token.
        self.queue_response(
            200, content=self.mock_collection_token("collection token"))
        self.access_token_response = self.mock_access_token_response(
            "bearer token")

        super(MockOverdriveAPI, self).__init__(_db, collection, *args,
                                               **kwargs)
コード例 #2
0
    def __init__(self, _db, *args, **kwargs):
        self.responses = []
        self.requests = []

        library = Library.instance(_db)
        collection, ignore = get_one_or_create(_db,
                                               Collection,
                                               name="Test Enki Collection",
                                               protocol=Collection.ENKI,
                                               create_method_kwargs=dict(
                                                   external_account_id=u'c', ))
        collection.external_integration.username = u'a'
        collection.external_integration.password = u'b'
        collection.external_integration.url = "http://enki.test/"
        library.collections.append(collection)
        super(MockEnkiAPI, self).__init__(_db, collection, *args, **kwargs)
コード例 #3
0
    def from_environment(cls, _db):
        """Load a ThreeMAPI instance for the 'default' Bibliotheca
        collection.
        """
        library = Library.instance(_db)
        collections = [x for x in library.collections
                      if x.protocol == Collection.BIBLIOTHECA]
        if len(collections) == 0:
            # There are no Bibliotheca collections configured.
            return None

        if len(collections) > 1:
            raise ValueError(
                "Multiple Bibliotheca collections found for one library. This is not yet supported."
            )
        [collection] = collections

        return cls(_db, collection)
コード例 #4
0
ファイル: axis.py プロジェクト: datalogics/server_core
    def from_environment(cls, _db):
        """Load an Axis360API instance for the 'default' Axis 360
        collection.
        """
        library = Library.instance(_db)
        collections = [x for x in library.collections
                      if x.protocol == Collection.AXIS_360]
        if len(collections) == 0:
            # There are no Axis 360 collections configured.
            return None

        if len(collections) > 1:
            raise ValueError(
                "Multiple Axis 360 collections found for one library. This is not yet supported."
            )
        [collection] = collections 

        return cls(_db, collection)
コード例 #5
0
ファイル: axis.py プロジェクト: datalogics/server_core
 def __init__(self, _db, with_token=True, *args, **kwargs):
     library = Library.instance(_db)
     collection, ignore = get_one_or_create(
         _db, Collection,
         name="Test Axis 360 Collection",
         protocol=Collection.AXIS_360, create_method_kwargs=dict(
             external_account_id=u'c',
         )
     )
     collection.external_integration.username = u'a'
     collection.external_integration.password = u'b'
     collection.external_integration.url = u"http://axis.test/"
     library.collections.append(collection)
     super(MockAxis360API, self).__init__(_db, collection, *args, **kwargs)
     if with_token:
         self.token = "mock token"
     self.responses = []
     self.requests = []
コード例 #6
0
    def __init__(self, _db, collection=None, base_path=None):
        if not collection:
            # OneClickAPI needs a Collection, but none was provided.
            # Just create a basic one.
            library = Library.instance(_db)
            collection, ignore = get_one_or_create(
                _db,
                Collection,
                name="Test OneClick Collection",
                protocol=Collection.ONE_CLICK,
                create_method_kwargs=dict(
                    external_account_id=u'library_id_123', ))
            collection.external_integration.password = u'abcdef123hijklm'

        self.responses = []
        self.requests = []
        base_path = base_path or os.path.split(__file__)[0]
        self.resource_path = os.path.join(base_path, "files", "oneclick")
        return super(MockOneClickAPI, self).__init__(_db, collection)
コード例 #7
0
    def from_config(cls, _db):
        """Load a OneClickAPI instance for the 'default' OneClick
        collection.
        """
        library = Library.instance(_db)
        collections = [
            x for x in library.collections
            if x.protocol == Collection.ONE_CLICK
        ]
        if len(collections) == 0:
            # There are no OneClick collections configured.
            return None

        if len(collections) > 1:
            raise ValueError(
                "Multiple OneClick collections found for one library. This is not yet supported."
            )
        [collection] = collections

        return cls(_db, collection)