コード例 #1
0
class BucketLoggingTest(unittest.TestCase):
    def setUp(self):
        self.session = mock.MagicMock()
        self.client = Client(session=self.session)
        mock_response(self.session)

    def test_create_bucket_logs_info_message(self):
        with mock.patch('kinto_http.logger') as mocked_logger:
            self.client.create_bucket(id="buck", data={'foo': 'bar'})
            mocked_logger.info.assert_called_with("Create bucket 'buck'")

    def test_update_bucket_logs_info_message(self):
        with mock.patch('kinto_http.logger') as mocked_logger:
            self.client.update_bucket(id='buck', data={'foo': 'bar'})
            mocked_logger.info.assert_called_with("Update bucket 'buck'")

    def test_get_bucket_logs_info_message(self):
        with mock.patch('kinto_http.logger') as mocked_logger:
            self.client.get_bucket(id="buck")
            mocked_logger.info.assert_called_with("Get bucket 'buck'")

    def test_delete_bucket_logs_info_message(self):
        with mock.patch('kinto_http.logger') as mocked_logger:
            self.client.delete_bucket(id="buck")
            mocked_logger.info.assert_called_with("Delete bucket 'buck'")

    def test_delete_buckets_logs_info_message(self):
        with mock.patch('kinto_http.logger') as mocked_logger:
            self.client.delete_buckets()
            mocked_logger.info.assert_called_with('Delete buckets')
コード例 #2
0
    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")
コード例 #3
0
ファイル: functional.py プロジェクト: Sayli-Karnik/kinto.py
 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
コード例 #4
0
ファイル: functional.py プロジェクト: Sayli-Karnik/kinto.py
    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')
コード例 #5
0
ファイル: test_client.py プロジェクト: glasserc/kinto-http.py
class GroupTest(unittest.TestCase):

    def setUp(self):
        self.session = mock.MagicMock()
        mock_response(self.session)
        self.client = Client(session=self.session, bucket='mybucket')

    def test_create_group_can_deduce_id_from_data(self):
        self.client.create_group(data={'id': 'group'})
        self.session.request.assert_called_with(
            'put', '/buckets/mybucket/groups/group', data={'id': 'group'}, permissions=None,
            headers=DO_NOT_OVERWRITE)

    def test_update_group_can_deduce_id_from_data(self):
        self.client.update_group(data={'id': 'group'})
        self.session.request.assert_called_with(
            'put', '/buckets/mybucket/groups/group', data={'id': 'group'}, permissions=None,
            headers=None)

    def test_create_group_raises_if_group_id_is_missing(self):
        with pytest.raises(KeyError) as e:
            self.client.create_group()
        self.assertEqual('%s' % e.value, "'Please provide a group id'")

    def test_update_group_raises_if_group_id_is_missing(self):
        with pytest.raises(KeyError) as e:
            self.client.update_group()
        self.assertEqual('%s' % e.value, "'Please provide a group id'")
コード例 #6
0
ファイル: test_client.py プロジェクト: Sayli-Karnik/kinto.py
    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)
コード例 #7
0
ファイル: functional.py プロジェクト: Sayli-Karnik/kinto.py
    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')
コード例 #8
0
ファイル: functional.py プロジェクト: Sayli-Karnik/kinto.py
 def test_updating_data_on_a_group(self):
     client = Client(server_url=self.server_url, auth=self.auth,
                     bucket='mozilla')
     client.create_bucket()
     client.create_group('payments', data={'members': []})
     client.patch_group('payments', data={'secret': 'psssssst!'})
     group = client.get_group('payments')
     assert group['data']['secret'] == 'psssssst!'
コード例 #9
0
 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(id=created['data']['id'])
     assert 'alexis' in record['permissions']['read']
コード例 #10
0
ファイル: functional.py プロジェクト: Sayli-Karnik/kinto.py
 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
コード例 #11
0
ファイル: functional.py プロジェクト: Sayli-Karnik/kinto.py
 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
コード例 #12
0
ファイル: functional.py プロジェクト: Sayli-Karnik/kinto.py
 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)
コード例 #13
0
ファイル: functional.py プロジェクト: Sayli-Karnik/kinto.py
    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!'
コード例 #14
0
 def test_record_deletion_if_exists(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(data={'foo': 'bar'})
     deleted = client.delete_record(id=record['data']['id'])
     deleted_if_exists = client.delete_record(id=record['data']['id'],
                                              if_exists=True)
     assert deleted['deleted'] is True
     assert deleted_if_exists is None
コード例 #15
0
ファイル: functional.py プロジェクト: onygami/kinto-http.py
 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": ["account:alexis"]})
     # Kinto is running with kinto.paginate_by = 5
     records = client.get_records()
     assert len(records) == 10
コード例 #16
0
ファイル: functional.py プロジェクト: onygami/kinto-http.py
 def test_record_deletion_if_exists(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(data={"foo": "bar"})
     deleted = client.delete_record(id=record["data"]["id"])
     deleted_if_exists = client.delete_record(id=record["data"]["id"],
                                              if_exists=True)
     assert deleted["deleted"] is True
     assert deleted_if_exists is None
コード例 #17
0
 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)
コード例 #18
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': ['account:alexis']})
     # Kinto is running with kinto.paginate_by = 5
     records = client.get_records()
     assert len(records) == 10
コード例 #19
0
ファイル: functional.py プロジェクト: onygami/kinto-http.py
 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)
コード例 #20
0
class CollectionLoggingTest(unittest.TestCase):
    def setUp(self):
        self.session = mock.MagicMock()
        self.client = Client(session=self.session)
        mock_response(self.session)

    def test_create_collection_logs_info_message(self):
        with mock.patch('kinto_http.logger') as mocked_logger:
            self.client.create_collection('mozilla',
                                          bucket="buck",
                                          data={'foo': 'bar'},
                                          permissions={'write': [
                                              'blah',
                                          ]})
            mocked_logger.info.assert_called_with(
                "Create collection 'mozilla' in bucket 'buck'")

    def test_update_collection_logs_info_message(self):
        with mock.patch('kinto_http.logger') as mocked_logger:
            self.client.update_collection(
                data={'foo': 'bar'},
                collection='mozilla',
                bucket='buck',
                permissions={'write': [
                    'blahblah',
                ]})
            mocked_logger.info.assert_called_with(
                "Update collection 'mozilla' in bucket 'buck'")

    def test_get_collection_logs_info_message(self):
        with mock.patch('kinto_http.logger') as mocked_logger:
            self.client.get_collection('mozilla', bucket='buck')
            mocked_logger.info.assert_called_with(
                "Get collection 'mozilla' in bucket 'buck'")

    def test_delete_collection_logs_info_message(self):
        with mock.patch('kinto_http.logger') as mocked_logger:
            self.client.delete_collection('mozilla', bucket="buck")
            mocked_logger.info.assert_called_with(
                "Delete collection 'mozilla' in bucket 'buck'")

    def test_delete_collections_logs_info_message(self):
        with mock.patch('kinto_http.logger') as mocked_logger:
            self.client.delete_collections(bucket="buck")
            mocked_logger.info.assert_called_with(
                "Delete collections in bucket 'buck'")
コード例 #21
0
ファイル: test_client.py プロジェクト: argael/kinto-http.py
 def test_client_is_represented_properly_with_bucket(self):
     client = Client(
         server_url="https://kinto.notmyidea.org/v1",
         bucket="homebrewing",
     )
     expected_repr = ("<KintoClient https://kinto.notmyidea.org/v1/"
                      "buckets/homebrewing>")
     assert str(client) == expected_repr
コード例 #22
0
ファイル: functional.py プロジェクト: argael/kinto-http.py
    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': ['account: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(id=created['data']['id'])
        assert 'account:alexis' in retrieved['permissions']['read']
        assert retrieved['data']['foo'] == u'bar'
        assert retrieved['data']['bar'] == u'baz'
        assert created['data']['id'] == retrieved['data']['id']
コード例 #23
0
ファイル: functional.py プロジェクト: Sayli-Karnik/kinto.py
    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)
コード例 #24
0
ファイル: functional.py プロジェクト: Sayli-Karnik/kinto.py
 def test_record_deletion_if_exists(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'])
     deleted_if_exists = client.delete_record(record['data']['id'], if_exists=True)
     assert deleted['deleted'] is True
     assert deleted_if_exists is None
コード例 #25
0
ファイル: functional.py プロジェクト: argael/kinto-http.py
 def test_records_deletion_when_no_records_exist(self):
     client = Client(server_url=self.server_url, auth=self.auth,
                     bucket='mozilla', collection='payments')
     client.create_bucket()
     client.create_collection()
     deleted_records = client.delete_records()
     assert len(deleted_records) == 0
コード例 #26
0
ファイル: functional.py プロジェクト: onygami/kinto-http.py
    def test_records_generator_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": ["account:alexis"]})

        pages = list(client.get_paginated_records())

        assert len(pages) == 2
コード例 #27
0
ファイル: test_client.py プロジェクト: argael/kinto-http.py
    def test_batch_does_not_raise_exception_if_batch_4xx_errors_are_ignored(self):
        error = {
            "errno": 121,
            "message": "Forbidden",
            "code": 403,
            "error": "This user cannot access this resource."
        }
        self.session.request.side_effect = [
            ({"settings": {"batch_max_requests": 25}}, []),
            ({"responses": [
                {"status": 200, "path": "/url1", "body": {}, "headers": {}},
                {"status": 403, "path": "/url2", "body": error, "headers": {}}
            ]}, [])]

        client = Client(session=self.session, ignore_batch_4xx=True)
        with client.batch(bucket='moz', collection='test') as batch:  # Do not raise
            batch.create_record(id=1234, data={'foo': 'bar'})
            batch.create_record(id=5678, data={'tutu': 'toto'})
コード例 #28
0
ファイル: test_client.py プロジェクト: argael/kinto-http.py
 def test_client_is_represented_properly_with_bucket_and_collection(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
コード例 #29
0
ファイル: functional.py プロジェクト: Sayli-Karnik/kinto.py
 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
コード例 #30
0
 def test_records_timestamp_retrieval(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(data={'foo': 'bar'},
                                   permissions={'read': ['account:alexis']})
     etag = client.get_records_timestamp()
     assert str(etag) == str(record["data"]["last_modified"])
コード例 #31
0
ファイル: functional.py プロジェクト: glasserc/kinto-http.py
    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'})
コード例 #32
0
ファイル: functional.py プロジェクト: onygami/kinto-http.py
 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": ["account:alexis"]})
     record = client.get_record(id=created["data"]["id"])
     assert "account:alexis" in record["permissions"]["read"]
コード例 #33
0
class GroupLoggingTest(unittest.TestCase):
    def setUp(self):
        self.session = mock.MagicMock()
        self.client = Client(session=self.session)
        mock_response(self.session)

    def test_create_group_logs_info_message(self):
        with mock.patch('kinto_http.logger') as mocked_logger:
            self.client.create_group(
                id='mozilla', bucket="buck",
                data={'foo': 'bar'},
                permissions={'write': ['blah', ]})
            mocked_logger.info.assert_called_with(
                "Create group 'mozilla' in bucket 'buck'")

    def test_update_group_logs_info_message(self):
        with mock.patch('kinto_http.logger') as mocked_logger:
            self.client.update_group(
                data={'foo': 'bar'},
                id='mozilla', bucket='buck',
                permissions={'write': ['blahblah', ]})
            mocked_logger.info.assert_called_with(
                "Update group 'mozilla' in bucket 'buck'")

    def test_get_group_logs_info_message(self):
        with mock.patch('kinto_http.logger') as mocked_logger:
            self.client.get_group(
                id='mozilla', bucket='buck')
            mocked_logger.info.assert_called_with(
                "Get group 'mozilla' in bucket 'buck'")

    def test_delete_group_logs_info_message(self):
        with mock.patch('kinto_http.logger') as mocked_logger:
            self.client.delete_group(
                id='mozilla', bucket="buck")
            mocked_logger.info.assert_called_with(
                "Delete group 'mozilla' in bucket 'buck'")

    def test_delete_groups_logs_info_message(self):
        with mock.patch('kinto_http.logger') as mocked_logger:
            self.client.delete_groups(
                bucket="buck")
            mocked_logger.info.assert_called_with(
                "Delete groups in bucket 'buck'")
コード例 #34
0
ファイル: functional.py プロジェクト: onygami/kinto-http.py
 def test_records_timestamp_retrieval(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(data={"foo": "bar"},
                                   permissions={"read": ["account:alexis"]})
     etag = client.get_records_timestamp()
     assert str(etag) == str(record["data"]["last_modified"])
コード例 #35
0
ファイル: functional.py プロジェクト: onygami/kinto-http.py
    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": ["account:alexis"]})

        client.create_record(data={
            "id": created["data"]["id"],
            "bar": "baz"
        },
                             safe=False)
コード例 #36
0
    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': ['account:alexis']})

        client.create_record(data={
            'id': created['data']['id'],
            'bar': 'baz'
        },
                             safe=False)
コード例 #37
0
ファイル: functional.py プロジェクト: nhnt11/kinto-signer
 def setUpClass(cls):
     super(BaseTestFunctional, cls).setUpClass()
     cls.signer = local_ecdsa.ECDSASigner(private_key=cls.private_key)
     cls.source = Client(server_url=cls.server_url,
                         auth=DEFAULT_AUTH,
                         bucket=cls.source_bucket,
                         collection=cls.source_collection)
     cls.destination = Client(server_url=cls.server_url,
                              auth=DEFAULT_AUTH,
                              bucket=cls.destination_bucket,
                              collection=cls.destination_collection)
     cls.editor_client = Client(server_url=cls.server_url,
                                auth=("editor", ""),
                                bucket=cls.source_bucket,
                                collection=cls.source_collection)
     cls.someone_client = Client(server_url=cls.server_url,
                                 auth=("Sam", "Wan-Elss"),
                                 bucket=cls.source_bucket,
                                 collection=cls.source_collection)
コード例 #38
0
ファイル: functional.py プロジェクト: onygami/kinto-http.py
    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": ["account: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(id=created["data"]["id"])
        assert "account:alexis" in retrieved["permissions"]["read"]
        assert retrieved["data"]["foo"] == u"bar"
        assert retrieved["data"]["bar"] == u"baz"
        assert created["data"]["id"] == retrieved["data"]["id"]
コード例 #39
0
    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")
コード例 #40
0
ファイル: functional.py プロジェクト: Sayli-Karnik/kinto.py
    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)
コード例 #41
0
ファイル: functional.py プロジェクト: onygami/kinto-http.py
    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": ["account: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"
            })
コード例 #42
0
    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': ['account: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'
            })
コード例 #43
0
ファイル: functional.py プロジェクト: Sayli-Karnik/kinto.py
 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']
コード例 #44
0
ファイル: functional.py プロジェクト: glasserc/kinto-http.py
 def test_records_timestamp_retrieval(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(data={'foo': 'bar'},
                                   permissions={'read': ['alexis']})
     etag = client.get_records_timestamp()
     assert str(etag) == str(record["data"]["last_modified"])
コード例 #45
0
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)
コード例 #46
0
ファイル: functional.py プロジェクト: Sayli-Karnik/kinto.py
    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']
コード例 #47
0
def get_nightly_builds(from_datestr="2018-10", to_datestr="2018-11"):
    """Return nightly build data for all builds."""
    client = KintoClient(server_url=BUILDHUB_URL)
    records = client.get_records(
        **{
            "target.platform": "linux-x86_64",
            "target.channel": "nightly",
            "source.product": "firefox",
            "target.locale": "en-US",
            # Caution: use build.date because download.date is crazy for dates before
            # 2016.
            "gt_build.date": from_datestr,
            "lt_build.date": to_datestr,
            "_sort": "-download.date",
            "_fields": "build.id,source.revision,download.date",
            # "_limit": 10,
        },
        bucket="build-hub",
        collection="releases",
    )
    return records
コード例 #48
0
    def initKintoClient(self):
        self.kinto_client = None
        kinto_url = settings.conf.value("KintoServerUrl")
        if kinto_url is not None and kinto_url != "":
            kinto_bucket = settings.conf.value("KintoDefaultBucket")
            kinto_credentials = (settings.conf.value("KintoBasicUserCred"),
                                 settings.conf.value("KintoBasicPasswordCred"))
            logger.debug(kinto_credentials)
            if kinto_bucket is None or kinto_bucket == "":
                kinto_bucket = "joliebulle"
                logger.debug("using default bucket 'joliebulle'")
            try:
                tmp_client = Client(server_url=kinto_url,
                                    auth=kinto_credentials)
                tmp_client.create_bucket(id=kinto_bucket, if_not_exists=True)
                self.kinto_client = Client(server_url=kinto_url,
                                           bucket=kinto_bucket,
                                           auth=kinto_credentials)

                # Création des collections
                self.kinto_client.create_collection(id='recipes',
                                                    if_not_exists=True)
                self.kinto_client.create_collection(id='ingredients',
                                                    if_not_exists=True)

                logger.info("Synchronize with kinto server at :" +
                            repr(self.kinto_client))
            except Exception as e:
                logger.warn("Failed to initialize Kinto synchronisation: " +
                            repr(e))
コード例 #49
0
ファイル: functional.py プロジェクト: Sayli-Karnik/kinto.py
 def test_records_deletion_when_no_records_exist(self):
     client = Client(server_url=self.server_url, auth=self.auth,
                     bucket='mozilla', collection='payments')
     client.create_bucket()
     client.create_collection()
     deleted_records = client.delete_records()
     assert len(deleted_records) == 0
コード例 #50
0
def test_blocklist_timestamp(env, conf):
    if env == 'prod':
        pytest.skip('Skipping blocklist timestamp test in production')

    client = Client(server_url=conf.get(env, 'reader_server'),
                    bucket='blocklists')
    # Take the highest timestamp of the collections contained in the blocklist.xml.
    last_modified = -1
    for cid in ('addons', 'plugins', 'gfx'):
        records = client.get_records(collection=cid,
                                     _sort='-last_modified',
                                     _limit=1,
                                     enabled='true')
        if len(records) > 0:
            last_modified = max(last_modified, records[0]['last_modified'])

    # Read the current XML blocklist ETag.
    blocklist_uri = conf.get(env, 'reader_server').strip('/') + (
        '/blocklist/3/{ec8030f7-c20a-464f-9b0e-13a3a9e97384}/58.0'
        '/Firefox/20180123185941/Darwin_x86_64-gcc3-u-i386-x86_64'
        '/en-US/release/Darwin 17.4.0/default/default/invalid/invalid/0/')
    r = requests.get(blocklist_uri)
    r.raise_for_status()
    etag_header = int(r.headers.get('ETag', '')[1:-1])
    last_modified_header = r.headers.get('Last-Modified', '')
    last_modified_header = datetime.datetime.strptime(
        last_modified_header, '%a, %d %b %Y %H:%M:%S GMT')

    # Check XML attribute <blocklist lastupdate="1483471392954">
    dom = minidom.parseString(r.text)
    root = dom.getElementsByTagName('blocklist')[0]
    last_modified_attr = int(root.getAttribute('lastupdate'))

    # Make sure they all match.
    # See https://bugzilla.mozilla.org/show_bug.cgi?id=1436469
    assert last_modified == etag_header
    last_modified_dt = datetime.datetime.utcfromtimestamp(last_modified /
                                                          1000.0)
    assert last_modified_dt.replace(microsecond=0) == last_modified_header
    assert last_modified == last_modified_attr
コード例 #51
0
    def test_round_trip_with_client_wins(self):
        # Load some data
        cmd = 'kinto-wizard {} --server={} --auth={}'
        load_cmd = cmd.format("load {}".format(self.file), self.server,
                              self.auth)
        sys.argv = load_cmd.split(" ")
        main()

        # Change something that could make the server to fail.
        client = Client(server_url=self.server,
                        auth=tuple(self.auth.split(':')))
        client.update_record(bucket='build-hub',
                             collection='archives',
                             id='0831d549-0a69-48dd-b240-feef94688d47',
                             data={})
        record = client.get_record(bucket='build-hub',
                                   collection='archives',
                                   id='0831d549-0a69-48dd-b240-feef94688d47')
        assert set(record['data'].keys()) == {'id', 'last_modified'}
        cmd = 'kinto-wizard {} --server={} -D --auth={} --force'
        load_cmd = cmd.format("load {}".format(self.file), self.server,
                              self.auth)
        sys.argv = load_cmd.split(" ")
        main()
        record = client.get_record(bucket='build-hub',
                                   collection='archives',
                                   id='0831d549-0a69-48dd-b240-feef94688d47')
        assert set(record['data'].keys()) != {'id', 'last_modified'}
コード例 #52
0
    def test_round_trip_with_delete_missing_records_ask_for_confirmation(self):
        # Load some data
        cmd = 'kinto-wizard {} --server={} --auth={}'
        load_cmd = cmd.format("load {}".format(self.file), self.server,
                              self.auth)
        sys.argv = load_cmd.split(" ")
        main()

        # Change something that could make the server to fail.
        client = Client(server_url=self.server,
                        auth=tuple(self.auth.split(':')))
        client.create_record(bucket='build-hub',
                             collection='archives',
                             id='8031d549-0a69-48dd-b240-feef94688d47',
                             data={})
        cmd = 'kinto-wizard {} --server={} -D --auth={} --delete-records'
        load_cmd = cmd.format("load {}".format(self.file), self.server,
                              self.auth)
        sys.argv = load_cmd.split(" ")

        with mockInput('yes'):
            main()

        with pytest.raises(exceptions.KintoException) as exc:
            client.get_record(bucket='build-hub',
                              collection='archives',
                              id='8031d549-0a69-48dd-b240-feef94688d47')
        assert "'Not Found'" in str(exc.value)
コード例 #53
0
ファイル: main.py プロジェクト: njouanin/joliebulle
    def initKintoClient(self):
        self.kinto_client = None
        kinto_url = settings.conf.value("KintoServerUrl")
        if kinto_url is not None and kinto_url != "":
            kinto_bucket = settings.conf.value("KintoDefaultBucket")
            kinto_credentials=(settings.conf.value("KintoBasicUserCred"), settings.conf.value("KintoBasicPasswordCred"))
            logger.debug(kinto_credentials)
            if kinto_bucket is None or kinto_bucket == "":
                kinto_bucket = "joliebulle"
                logger.debug("using default bucket 'joliebulle'")
            try:
                tmp_client = Client(server_url=kinto_url, auth = kinto_credentials)
                tmp_client.create_bucket(id=kinto_bucket, if_not_exists=True)
                self.kinto_client = Client(server_url=kinto_url, bucket=kinto_bucket, auth = kinto_credentials)

                # Création des collections
                self.kinto_client.create_collection(id='recipes', if_not_exists=True)
                self.kinto_client.create_collection(id='ingredients', if_not_exists=True)
                
                logger.info("Synchronize with kinto server at :" + repr(self.kinto_client))
            except Exception as e:
                logger.warn("Failed to initialize Kinto synchronisation: " + repr(e))
コード例 #54
0
ファイル: functional.py プロジェクト: Sayli-Karnik/kinto.py
    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'
コード例 #55
0
def main():
    args = _get_args()

    print("Get editor's user id")
    editor_client = Client(server_url=args.server,
                           auth=tuple(args.editor_auth.split(':')))
    editor_id = editor_client.server_info()['user']['id']

    print("Get reviewer's user id")
    reviewer_client = Client(server_url=args.server,
                             auth=tuple(args.reviewer_auth.split(':')))
    reviewer_id = reviewer_client.server_info()['user']['id']

    print("Create signoff workflow groups")
    admin_client = Client(server_url=args.server,
                          auth=tuple(args.auth.split(':')),
                          bucket=args.bucket)

    print("Create/update editors group")
    editors_group = admin_client.create_group('editors', data={'members': []}, if_not_exists=True)
    editors_group['data']['members'] = editors_group['data']['members'] + [editor_id]
    admin_client.update_group('editors', editors_group['data'], safe=True)

    print("Create/update reviewers group")
    reviewers_group = admin_client.create_group('reviewers', data={'members': []}, if_not_exists=True)
    reviewers_group['data']['members'] = reviewers_group['data']['members'] + [reviewer_id]
    admin_client.update_group('reviewers', data=reviewers_group['data'], safe=True)
コード例 #56
0
 def setUp(self):
     self.session = mock.MagicMock()
     self.client = Client(session=self.session)
     mock_response(self.session)
コード例 #57
0
class RecordLoggingTest(unittest.TestCase):
    def setUp(self):
        self.session = mock.MagicMock()
        self.client = Client(session=self.session)
        mock_response(self.session)

    def test_create_record_logs_info_message(self):
        with mock.patch('kinto_http.logger') as mocked_logger:
            self.client.create_bucket(id='buck')
            self.client.create_collection(id='mozilla',
                                          bucket='buck')
            self.client.create_record(
                id='fake-record',
                data={'foo': 'bar'},
                permissions={'write': ['blah', ]},
                bucket='buck',
                collection='mozilla')
            mocked_logger.info.assert_called_with(
                "Create record with id 'fake-record' in collection 'mozilla' in bucket 'buck'")

    def test_update_record_logs_info_message(self):
        with mock.patch('kinto_http.logger') as mocked_logger:
            self.client.create_bucket(id='buck')
            self.client.create_collection(bucket='buck',
                                          id='mozilla')
            self.client.update_record(
                id='fake-record',
                data={'ss': 'aa'},
                bucket='buck',
                collection='mozilla')
            mocked_logger.info.assert_called_with(
                "Update record with id 'fake-record' in collection 'mozilla' in bucket 'buck'")

    def test_get_record_logs_info_message(self):
        with mock.patch('kinto_http.logger') as mocked_logger:
            self.client.create_bucket(id='buck')
            self.client.create_collection(id='mozilla',
                                          bucket='buck')
            self.client.get_record(
                id='fake-record',
                bucket='buck',
                collection='mozilla')
            mocked_logger.info.assert_called_with(
                "Get record with id 'fake-record' from collection 'mozilla' in bucket 'buck'")

    def test_delete_record_logs_info_message(self):
        with mock.patch('kinto_http.logger') as mocked_logger:
            self.client.create_bucket(id='buck')
            self.client.create_collection(id='mozilla',
                                          bucket='buck')
            self.client.delete_record(
                id='fake-record',
                bucket='buck',
                collection='mozilla')
            mocked_logger.info.assert_called_with(
                "Delete record with id 'fake-record' from collection 'mozilla' in bucket 'buck'")

    def test_delete_records_logs_info_message(self):
        with mock.patch('kinto_http.logger') as mocked_logger:
            self.client.create_bucket(id='buck')
            self.client.create_collection(id='mozilla',
                                          bucket='buck')
            self.client.delete_records(
                bucket='buck',
                collection='mozilla')
            mocked_logger.info.assert_called_with(
                "Delete records from collection 'mozilla' in bucket 'buck'")
コード例 #58
0
ファイル: test_client.py プロジェクト: Sayli-Karnik/kinto.py
 def setUp(self):
     self.session = mock.MagicMock()
     self.client = Client(
         session=self.session, bucket='mybucket',
         collection='mycollection')
コード例 #59
0
ファイル: test_client.py プロジェクト: Sayli-Karnik/kinto.py
class ClientTest(unittest.TestCase):
    def setUp(self):
        self.session = mock.MagicMock()
        self.client = Client(session=self.session)
        mock_response(self.session)

    def test_server_info(self):
        self.client.server_info()
        self.session.request.assert_called_with('get', '/')

    def test_context_manager_works_as_expected(self):
        settings = {"batch_max_requests": 25}
        self.session.request.side_effect = [({"settings": settings}, []),
                                            ({"responses": []}, [])]

        with self.client.batch(bucket='mozilla', collection='test') as batch:
            batch.create_record(id=1234, data={'foo': 'bar'})
            batch.create_record(id=5678, data={'bar': 'baz'})

        self.session.request.assert_called_with(
            method='POST',
            endpoint='/batch',
            payload={'requests': [
                {'body': {'data': {'foo': 'bar'}},
                 'path': '/buckets/mozilla/collections/test/records/1234',
                 'method': 'PUT',
                 'headers': {'If-None-Match': '*'}},
                {'body': {'data': {'bar': 'baz'}},
                 'path': '/buckets/mozilla/collections/test/records/5678',
                 'method': 'PUT',
                 'headers': {'If-None-Match': '*'}}]})

    def test_batch_raises_exception(self):
        # Make the next call to sess.request raise a 403.
        exception = KintoException()
        exception.response = mock.MagicMock()
        exception.response.status_code = 403
        exception.request = mock.sentinel.request
        self.session.request.side_effect = exception

        with self.assertRaises(KintoException):
            with self.client.batch(bucket='moz', collection='test') as batch:
                batch.create_record(id=1234, data={'foo': 'bar'})

    def test_batch_raises_exception_if_subrequest_failed(self):
        error = {
            "errno": 121,
            "message": "This user cannot access this resource.",
            "code": 403,
            "error": "Forbidden"
        }
        self.session.request.side_effect = [
            ({"settings": {"batch_max_requests": 25}}, []),
            ({"responses": [
                {"status": 200, "path": "/url1", "body": {}, "headers": {}},
                {"status": 404, "path": "/url2", "body": error, "headers": {}}
            ]}, [])]

        with self.assertRaises(KintoException):
            with self.client.batch(bucket='moz', collection='test') as batch:
                batch.create_record(id=1234, data={'foo': 'bar'})
                batch.create_record(id=5678, data={'tutu': 'toto'})

    def test_batch_options_are_transmitted(self):
        settings = {"batch_max_requests": 25}
        self.session.request.side_effect = [({"settings": settings}, [])]
        with mock.patch('kinto_http.create_session') as create_session:
            with self.client.batch(bucket='moz', collection='test', retry=12,
                                   retry_after=20):
                _, last_call_kwargs = create_session.call_args_list[-1]
                self.assertEqual(last_call_kwargs['retry'], 12)
                self.assertEqual(last_call_kwargs['retry_after'], 20)

    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 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')

    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_clone_with_auth(self):
        client_clone = self.client.clone(auth=("reviewer", ""))
        assert client_clone.session.auth == ("reviewer", "")
        assert self.client.session != client_clone.session
        assert self.client.session.server_url == client_clone.session.server_url
        assert self.client.session.auth != client_clone.session.auth
        assert self.client.session.nb_retry == client_clone.session.nb_retry
        assert self.client.session.retry_after == client_clone.session.retry_after
        assert self.client._bucket_name == client_clone._bucket_name
        assert self.client._collection_name == client_clone._collection_name

    def test_client_clone_with_server_url(self):
        client_clone = self.client.clone(server_url="https://kinto.notmyidea.org/v1")
        assert client_clone.session.server_url == "https://kinto.notmyidea.org/v1"
        assert self.client.session != client_clone.session
        assert self.client.session.server_url != client_clone.session.server_url
        assert self.client.session.auth == client_clone.session.auth
        assert self.client.session.nb_retry == client_clone.session.nb_retry
        assert self.client.session.retry_after == client_clone.session.retry_after
        assert self.client._bucket_name == client_clone._bucket_name
        assert self.client._collection_name == client_clone._collection_name

    def test_client_clone_with_new_session(self):
        session = create_session(auth=("reviewer", ""),
                                 server_url="https://kinto.notmyidea.org/v1")
        client_clone = self.client.clone(session=session)
        assert client_clone.session == session
        assert self.client.session != client_clone.session
        assert self.client.session.server_url != client_clone.session.server_url
        assert self.client.session.auth != client_clone.session.auth
        assert self.client._bucket_name == client_clone._bucket_name
        assert self.client._collection_name == client_clone._collection_name

    def test_client_clone_with_auth_and_server_url(self):
        client_clone = self.client.clone(auth=("reviewer", ""),
                                         server_url="https://kinto.notmyidea.org/v1")
        assert client_clone.session.auth == ("reviewer", "")
        assert client_clone.session.server_url == "https://kinto.notmyidea.org/v1"
        assert self.client.session != client_clone.session
        assert self.client.session.server_url != client_clone.session.server_url
        assert self.client.session.auth != client_clone.session.auth
        assert self.client.session.nb_retry == client_clone.session.nb_retry
        assert self.client.session.retry_after == client_clone.session.retry_after
        assert self.client._bucket_name == client_clone._bucket_name
        assert self.client._collection_name == client_clone._collection_name

    def test_client_clone_with_existing_session(self):
        client_clone = self.client.clone(session=self.client.session)
        assert self.client.session == client_clone.session
        assert self.client.session.server_url == client_clone.session.server_url
        assert self.client.session.auth == client_clone.session.auth
        assert self.client._bucket_name == client_clone._bucket_name
        assert self.client._collection_name == client_clone._collection_name

    def test_client_clone_with_new_bucket_and_collection(self):
        client_clone = self.client.clone(bucket="bucket_blah", collection="coll_blah")
        assert self.client.session == client_clone.session
        assert self.client.session.server_url == client_clone.session.server_url
        assert self.client.session.auth == client_clone.session.auth
        assert self.client.session.nb_retry == client_clone.session.nb_retry
        assert self.client.session.retry_after == client_clone.session.retry_after
        assert self.client._bucket_name != client_clone._bucket_name
        assert self.client._collection_name != client_clone._collection_name
        assert client_clone._bucket_name == "bucket_blah"
        assert client_clone._collection_name == "coll_blah"

    def test_client_clone_with_auth_and_server_url_bucket_and_collection(self):
        client_clone = self.client.clone(auth=("reviewer", ""),
                                         server_url="https://kinto.notmyidea.org/v1",
                                         bucket="bucket_blah",
                                         collection="coll_blah")
        assert self.client.session != client_clone.session
        assert self.client.session.server_url != client_clone.session.server_url
        assert self.client.session.auth != client_clone.session.auth
        assert self.client._bucket_name != client_clone._bucket_name
        assert self.client._collection_name != client_clone._collection_name
        assert client_clone.session.auth == ("reviewer", "")
        assert client_clone.session.server_url == "https://kinto.notmyidea.org/v1"
        assert client_clone._bucket_name == "bucket_blah"
        assert client_clone._collection_name == "coll_blah"
コード例 #60
0
ファイル: test_client.py プロジェクト: Sayli-Karnik/kinto.py
 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')