Пример #1
0
    def test_using_admin_party_source_and_target(self):
        m_admin_party_client = self.setUpClientMocks(admin_party=True)

        m_replicator = mock.MagicMock()
        type(m_replicator).creds = mock.PropertyMock(return_value=None)
        m_admin_party_client.__getitem__.return_value = m_replicator

        # create source/target databases
        src = CouchDatabase(m_admin_party_client, self.source_db)
        tgt = CouchDatabase(m_admin_party_client, self.target_db)

        # trigger replication
        rep = Replicator(m_admin_party_client)
        rep.create_replication(src, tgt, repl_id=self.repl_id)

        kcall = m_replicator.create_document.call_args_list
        self.assertEquals(len(kcall), 1)
        args, kwargs = kcall[0]
        self.assertEquals(len(args), 1)

        expected_doc = {
            '_id': self.repl_id,
            'source': {
                'url': '/'.join((self.server_url, self.source_db))
            },
            'target': {
                'url': '/'.join((self.server_url, self.target_db))
            }
        }

        self.assertDictEqual(args[0], expected_doc)
        self.assertTrue(kwargs['throw_on_exists'])
Пример #2
0
    def __init__(self, uri, create=False, server=None, **params):
        """Constructor for Database

        @param uri: str, Database uri
        @param create: boolean, False by default,
        if True try to create the database.
        @param server: Server instance

        """
        self.uri = uri.rstrip('/')
        self.server_uri, self.dbname = self.uri.rsplit("/", 1)
        self.cloudant_dbname = unquote(self.dbname)

        if server is not None:
            if not hasattr(server, 'next_uuid'):
                raise TypeError('%s is not a couchdbkit.Server instance' %
                                server.__class__.__name__)
            self.server = server
        else:
            self.server = server = Server(self.server_uri, **params)

        self.cloudant_client = self.server.cloudant_client

        validate_dbname(self.dbname)
        self.cloudant_database = CouchDatabase(self.cloudant_client,
                                               self.cloudant_dbname)
        if create:
            self.cloudant_database.create()

        self._request_session = self.server._request_session
        self.database_url = self.cloudant_database.database_url
Пример #3
0
    def test_using_iam_auth_source_and_target(self):
        m_iam_auth_client = self.setUpClientMocks(iam_api_key=MOCK_API_KEY)

        m_replicator = mock.MagicMock()
        m_iam_auth_client.__getitem__.return_value = m_replicator

        # create source/target databases
        src = CouchDatabase(m_iam_auth_client, self.source_db)
        tgt = CouchDatabase(m_iam_auth_client, self.target_db)

        # trigger replication
        rep = Replicator(m_iam_auth_client)
        rep.create_replication(src,
                               tgt,
                               repl_id=self.repl_id,
                               user_ctx=self.user_ctx)

        kcall = m_replicator.create_document.call_args_list
        self.assertEquals(len(kcall), 1)
        args, kwargs = kcall[0]
        self.assertEquals(len(args), 1)

        expected_doc = {
            '_id': self.repl_id,
            'user_ctx': self.user_ctx,
            'source': {
                'auth': {
                    'iam': {
                        'api_key': MOCK_API_KEY
                    }
                },
                'url': '/'.join((self.server_url, self.source_db))
            },
            'target': {
                'auth': {
                    'iam': {
                        'api_key': MOCK_API_KEY
                    }
                },
                'url': '/'.join((self.server_url, self.target_db))
            }
        }

        self.assertDictEqual(args[0], expected_doc)
        self.assertTrue(kwargs['throw_on_exists'])
Пример #4
0
    def test_using_basic_auth_source_and_target(self):
        test_basic_auth_header = 'abc'

        m_basic_auth_client = self.setUpClientMocks()

        m_replicator = mock.MagicMock()
        m_basic_auth_client.__getitem__.return_value = m_replicator
        m_basic_auth_client.basic_auth_str.return_value = test_basic_auth_header

        # create source/target databases
        src = CouchDatabase(m_basic_auth_client, self.source_db)
        tgt = CouchDatabase(m_basic_auth_client, self.target_db)

        # trigger replication
        rep = Replicator(m_basic_auth_client)
        rep.create_replication(src,
                               tgt,
                               repl_id=self.repl_id,
                               user_ctx=self.user_ctx)

        kcall = m_replicator.create_document.call_args_list
        self.assertEquals(len(kcall), 1)
        args, kwargs = kcall[0]
        self.assertEquals(len(args), 1)

        expected_doc = {
            '_id': self.repl_id,
            'user_ctx': self.user_ctx,
            'source': {
                'headers': {
                    'Authorization': test_basic_auth_header
                },
                'url': '/'.join((self.server_url, self.source_db))
            },
            'target': {
                'headers': {
                    'Authorization': test_basic_auth_header
                },
                'url': '/'.join((self.server_url, self.target_db))
            }
        }

        self.assertDictEqual(args[0], expected_doc)
        self.assertTrue(kwargs['throw_on_exists'])
 def __init__(self, url=DB_URL):
     client = CouchDB(user=USERNAME,
                      auth_token=PASSWORD,
                      url=DB_URL,
                      connect=True,
                      auto_renew=True,
                      use_basic_auth=True)
     self.db = CouchDatabase(client,
                             DB_NAME,
                             fetch_limit=100,
                             partitioned=False)
Пример #6
0
 def select_db(self, db_name):
     self.couch_db = CouchDatabase(self.client, db_name)
     if not self.couch_db.exists():
         self.couch_db.create()
     self.db = self.client[db_name]
     self.c_db = CloudantDatabase(self.client, db_name)