def test_logger_outputs_replication_information(self, logger): origin_session = mock.MagicMock() origin_session.server_url = "http://origin/v1" destination_session = mock.MagicMock() destination_session.server_url = "http://destination/v1" mock_response(origin_session) mock_response(destination_session) origin = Client( session=origin_session, bucket="buck", collection="coll" ) destination = Client( session=destination_session, bucket="buck", collection="coll" ) destination._server_settings = {'batch_max_requests': 15} replicate(origin, destination) msg = ("Replication from <KintoClient http://origin/v1/buckets/buck/" "collections/coll> to <KintoClient http://destination/v1/" "buckets/buck/collections/coll>") logger.info.assert_any_call(msg) logger.info.assert_any_call("replication of 0 records")
def setUp(self): self.credentials = ('testuser', 'abc123') self.client = Client(server_url=DEFAULT_SERVER, auth=self.credentials) self.collection = uuid.uuid1() self.bucket = 'deploytest' self.client.create_bucket(self.bucket, if_not_exists=True) self.client.create_collection(self.collection, bucket=self.bucket)
def test_client_is_represented_properly(self): client = Client(server_url="https://kinto.notmyidea.org/v1", bucket="homebrewing", collection="recipes") expected_repr = ("<KintoClient https://kinto.notmyidea.org/v1/" "buckets/homebrewing/collections/recipes>") assert str(client) == expected_repr
def __init__(self, *args, **kwargs): super(FunctionalTest, self).__init__(*args, **kwargs) # XXX Read the configuration from env variables. self.server_url = SERVER_URL self.auth = DEFAULT_AUTH # Read the configuration. self.config = configparser.RawConfigParser() self.config.read(os.path.join(__HERE__, 'config/kinto.ini')) self.client = Client(server_url=self.server_url, auth=self.auth)
def test_multiple_record_deletion(self): client = Client(server_url=self.server_url, auth=self.auth, bucket='mozilla', collection='payments') client.create_bucket() client.create_collection() client.create_record({'foo': 'bar'}) client.delete_records() assert len(client.get_records()) == 0
def test_records_list_retrieval(self): client = Client(server_url=self.server_url, auth=self.auth, bucket='mozilla', collection='payments') client.create_bucket() client.create_collection() client.create_record(data={'foo': 'bar'}, permissions={'read': ['alexis']}) records = client.get_records() assert len(records) == 1
def test_record_creation_and_retrieval(self): client = Client(server_url=self.server_url, auth=self.auth, bucket='mozilla', collection='payments') client.create_bucket() client.create_collection() created = client.create_record(data={'foo': 'bar'}, permissions={'read': ['alexis']}) record = client.get_record(created['data']['id']) assert 'alexis' in record['permissions']['read']
def test_updating_data_on_a_collection(self): client = Client(server_url=self.server_url, auth=self.auth, bucket='mozilla', collection='payments') client.create_bucket() client.create_collection() client.patch_collection(data={'secret': 'psssssst!'}) collection = client.get_collection() assert collection['data']['secret'] == 'psssssst!'
def main(): # pragma: nocover args = get_arguments() cli_utils.setup_logger(logger, args) origin = Client(server_url=args.origin_server, auth=args.origin_auth or args.auth, bucket=args.origin_bucket or args.bucket, collection=args.origin_collection or args.collection) destination = cli_utils.create_client_from_args(args) replicate(origin, destination)
def test_one_record_deletion(self): client = Client(server_url=self.server_url, auth=self.auth, bucket='mozilla', collection='payments') client.create_bucket() client.create_collection() record = client.create_record({'foo': 'bar'}) deleted = client.delete_record(record['data']['id']) assert deleted['deleted'] is True assert len(client.get_records()) == 0
def test_records_paginated_list_retrieval(self): client = Client(server_url=self.server_url, auth=self.auth, bucket='mozilla', collection='payments') client.create_bucket() client.create_collection() for i in range(10): client.create_record(data={'foo': 'bar'}, permissions={'read': ['alexis']}) # Kinto is running with kinto.paginate_by = 5 records = client.get_records() assert len(records) == 10
def test_bucket_sharing(self): alice_credentials = ('alice', 'p4ssw0rd') alice_userid = self.get_user_id(alice_credentials) # Create a bucket and share it with alice. self.client.create_bucket('shared-bucket', permissions={'read': [ alice_userid, ]}) alice_client = Client(server_url=self.server_url, auth=alice_credentials) alice_client.get_bucket('shared-bucket')
def test_single_record_creation_if_not_exists(self): client = Client(server_url=self.server_url, auth=self.auth, bucket='mozilla', collection='payments') client.create_bucket() client.create_collection() created = client.create_record(data={'foo': 'bar'}) client.create_record(data={ 'id': created['data']['id'], 'bar': 'baz' }, if_not_exists=True)
def test_replication(self): # First, create a few records on the first kinto collection. with self.client.batch(bucket='origin', collection='coll') as batch: batch.create_bucket() batch.create_collection() for n in range(10): batch.create_record(data={'foo': 'bar', 'n': n}) origin = Client(server_url=self.server_url, auth=self.auth, bucket='origin', collection='coll') destination = Client(server_url=self.server_url, auth=self.auth, bucket='destination', collection='coll') replication.replicate(origin, destination) records = self.client.get_records(bucket='destination', collection='coll') assert len(records) == 10
def setUp(self): # Figure out what the IP address where the containers are running f = os.popen('which docker-machine') docker_machine = str(f.read()).strip() if string.find(docker_machine, "/docker-machine") == -1: print("Could not find docker-machine in our path") exit() f = os.popen('%s ip default' % docker_machine) ip = str(f.read()).strip() # Set our master and read-only end points and create our test bucket self.master_url = "http://%s:8888/v1/" % ip self.read_only_url = "http://%s:8889/v1/" % ip self.credentials = ('testuser', 'abc123') self.master = Client(server_url=self.master_url, auth=self.credentials) self.read_only = Client(server_url=self.read_only_url, auth=self.credentials) self.bucket = self.get_timestamp() self.master.create_bucket(self.bucket) self.read_only.create_bucket(self.bucket)
def test_collection_sharing(self): alice_credentials = ('alice', 'p4ssw0rd') alice_userid = self.get_user_id(alice_credentials) self.client.create_bucket('bob-bucket') self.client.create_collection('shared', bucket='bob-bucket', permissions={'read': [ alice_userid, ]}) # Try to read the collection as Alice. alice_client = Client(server_url=self.server_url, auth=alice_credentials) alice_client.get_collection('shared', bucket='bob-bucket')
def test_single_record_can_overwrite(self): client = Client(server_url=self.server_url, auth=self.auth, bucket='mozilla', collection='payments') client.create_bucket() client.create_collection() created = client.create_record(data={'foo': 'bar'}, permissions={'read': ['alexis']}) client.create_record(data={ 'id': created['data']['id'], 'bar': 'baz' }, safe=False)
def test_single_record_doesnt_overwrite(self): client = Client(server_url=self.server_url, auth=self.auth, bucket='mozilla', collection='payments') client.create_bucket() client.create_collection() created = client.create_record(data={'foo': 'bar'}, permissions={'read': ['alexis']}) with self.assertRaises(KintoException): # Create a second record with the ID of the first one. client.create_record(data={ 'id': created['data']['id'], 'bar': 'baz' })
def test_collection_argument_takes_precedence(self): mock_response(self.session) # Specify a different collection name for the client and the operation. client = Client(session=self.session, bucket='mybucket', collection='wrong_collection') client.update_record(data={'id': '1234'}, collection='good_collection', permissions=mock.sentinel.permissions) self.session.request.assert_called_with( 'put', '/buckets/mybucket/collections/good_collection/records/1234', data={'id': '1234'}, headers=None, permissions=mock.sentinel.permissions)
def test_single_record_save(self): client = Client(server_url=self.server_url, auth=self.auth, bucket='mozilla', collection='payments') client.create_bucket() client.create_collection() created = client.create_record(data={'foo': 'bar'}, permissions={'read': ['alexis']}) created['data']['bar'] = 'baz' # XXX enhance this in order to have to pass only one argument, created. client.update_record(id=created['data']['id'], data=created['data']) retrieved = client.get_record(created['data']['id']) assert 'alexis' in retrieved['permissions']['read'] assert retrieved['data']['foo'] == u'bar' assert retrieved['data']['bar'] == u'baz' assert created['data']['id'] == retrieved['data']['id']
def _load(self): self.client = Client(server_url=self.options['server'], auth=self.options['auth'], bucket=self.options['bucket_name'], collection=self.options['collection_name']) # Create bucket try: self.client.create_bucket() except KintoException as e: if e.response.status_code != 412: raise e try: self.client.create_collection( permissions=self.options['permissions']) except KintoException as e: if e.response.status_code != 412: raise e return [self._kinto2rec(rec) for rec in self.client.get_records()]
def test_record_sharing(self): alice_credentials = ('alice', 'p4ssw0rd') alice_userid = self.get_user_id(alice_credentials) # Create a record, and share it with Alice. self.client.create_bucket('bob-bucket') self.client.create_collection('bob-personal-collection', bucket='bob-bucket') record = self.client.create_record( data={'foo': 'bar'}, permissions={'read': [ alice_userid, ]}, bucket='bob-bucket', collection='bob-personal-collection') # Try to read the record as Alice alice_client = Client(server_url=self.server_url, auth=alice_credentials) record = alice_client.get_record(id=record['data']['id'], bucket='bob-bucket', collection='bob-personal-collection') assert record['data']['foo'] == 'bar'
def setUp(self): self.session = mock.MagicMock() self.client = Client(session=self.session) mock_response(self.session)
def setUp(self): self.session = mock.MagicMock() self.client = Client(session=self.session, bucket='mybucket', collection='mycollection')
def setUp(self): self.session = mock.MagicMock() mock_response(self.session) self.client = Client(session=self.session, bucket='mybucket')
def test_client_uses_passed_bucket_if_specified(self): client = Client(server_url="https://kinto.notmyidea.org/v1", bucket="buck") assert client._bucket_name == "buck"
def test_client_uses_default_bucket_if_not_specified(self): mock_response(self.session) client = Client(session=self.session) client.get_bucket() self.session.request.assert_called_with('get', '/buckets/default')