Пример #1
0
    def test_507_is_raised_if_quota_exceeded_on_group_update(self):
        self.create_bucket()
        self.create_collection()
        body = {"data": {"members": []}}
        resp = self.app.put_json(self.group_uri, body, headers=self.headers)
        group = resp.json["data"]
        body = {
            "data": {"members": ["elle", "lui", "je", "tu", "il", "nous", "vous", "ils", "elles"]}
        }
        resp = self.app.put_json(self.group_uri, body, headers=self.headers, status=507)

        storage_size = record_size(self.bucket)
        storage_size += record_size(self.collection)
        storage_size += record_size(group)

        self.assertFormattedError(
            resp, 507, ERRORS.FORBIDDEN, "Insufficient Storage", self.error_message
        )

        data = self.storage.get(
            resource_name=QUOTA_RESOURCE_NAME,
            parent_id=self.bucket_uri,
            object_id=BUCKET_QUOTA_OBJECT_ID,
        )
        self.assertStatsEqual(
            data, {"collection_count": 1, "record_count": 0, "storage_size": storage_size}
        )
Пример #2
0
    def test_507_is_raised_if_quota_exceeded_on_group_update(self):
        self.create_bucket()
        self.create_collection()
        body = {'data': {'members': []}}
        resp = self.app.put_json(self.group_uri, body, headers=self.headers)
        group = resp.json['data']
        body = {
            'data': {
                'members': [
                    'elle', 'lui', 'je', 'tu', 'il', 'nous', 'vous', 'ils',
                    'elles'
                ]
            }
        }
        resp = self.app.put_json(self.group_uri,
                                 body,
                                 headers=self.headers,
                                 status=507)

        storage_size = record_size(self.bucket)
        storage_size += record_size(self.collection)
        storage_size += record_size(group)

        self.assertFormattedError(resp, 507, ERRORS.FORBIDDEN,
                                  "Insufficient Storage", self.error_message)

        data = self.storage.get(collection_id=QUOTA_RESOURCE_NAME,
                                parent_id=self.bucket_uri,
                                object_id=BUCKET_QUOTA_OBJECT_ID)
        self.assertStatsEqual(data, {
            "collection_count": 1,
            "record_count": 0,
            "storage_size": storage_size
        })
Пример #3
0
    def test_507_is_raised_if_quota_exceeded_on_collection_creation(self):
        self.create_bucket()
        self.create_collection()
        self.create_record()
        body = {"data": {"foo": 42}}
        resp = self.app.post_json(
            "{}/collections".format(self.bucket_uri), body, headers=self.headers, status=507
        )

        storage_size = record_size(self.bucket)
        storage_size += record_size(self.collection)
        storage_size += record_size(self.record)

        self.assertFormattedError(
            resp, 507, ERRORS.FORBIDDEN, "Insufficient Storage", self.error_message
        )

        data = self.storage.get(
            resource_name=QUOTA_RESOURCE_NAME,
            parent_id=self.bucket_uri,
            object_id=BUCKET_QUOTA_OBJECT_ID,
        )
        self.assertStatsEqual(
            data, {"collection_count": 1, "record_count": 1, "storage_size": storage_size}
        )

        # Check that the collection wasn't created
        resp = self.app.get("{}/collections".format(self.bucket_uri), headers=self.headers)
        assert len(resp.json["data"]) == 1
Пример #4
0
    def test_507_is_raised_if_quota_exceeded_on_group_update(self):
        self.create_bucket()
        self.create_collection()
        body = {'data': {'members': []}}
        resp = self.app.put_json(self.group_uri, body,
                                 headers=self.headers)
        group = resp.json['data']
        body = {'data': {'members': ['elle', 'lui', 'je', 'tu', 'il', 'nous',
                                     'vous', 'ils', 'elles']}}
        resp = self.app.put_json(self.group_uri, body,
                                 headers=self.headers, status=507)

        storage_size = record_size(self.bucket)
        storage_size += record_size(self.collection)
        storage_size += record_size(group)

        self.assertFormattedError(
            resp, 507, ERRORS.FORBIDDEN, "Insufficient Storage",
            self.error_message)

        data = self.storage.get(collection_id=QUOTA_RESOURCE_NAME,
                                parent_id=self.bucket_uri,
                                object_id=QUOTA_BUCKET_ID)
        self.assertStatsEqual(data, {
            "collection_count": 1,
            "record_count": 0,
            "storage_size": storage_size
        })
Пример #5
0
    def test_507_is_raised_if_quota_exceeded_on_record_creation(self):
        self.create_bucket()
        self.create_collection()
        self.create_record()
        body = {'data': {'foo': 42}}
        resp = self.app.post_json('%s/records' % self.collection_uri,
                                  body,
                                  headers=self.headers,
                                  status=507)

        # Check that the storage was not updated.
        storage_size = record_size(self.bucket)
        storage_size += record_size(self.collection)
        storage_size += record_size(self.record)

        self.assertFormattedError(resp, 507, ERRORS.FORBIDDEN,
                                  "Insufficient Storage", self.error_message)

        data = self.storage.get(collection_id=QUOTA_RESOURCE_NAME,
                                parent_id=self.bucket_uri,
                                object_id=QUOTA_BUCKET_ID)
        self.assertStatsEqual(data, {
            "collection_count": 1,
            "record_count": 1,
            "storage_size": storage_size
        })

        # Check that the record wasn't created
        resp = self.app.get('%s/records' % self.collection_uri,
                            headers=self.headers)
        assert len(resp.json['data']) == 1
Пример #6
0
    def test_tracks_collection_attributes_update(self):
        self.create_bucket()
        self.create_collection()
        body = {'data': {'foo': 'baz'}}
        resp = self.app.patch_json(self.collection_uri,
                                   body,
                                   headers=self.headers)
        # Bucket stats
        storage_size = record_size(self.bucket)
        storage_size += record_size(resp.json['data'])

        data = self.storage.get(collection_id=QUOTA_RESOURCE_NAME,
                                parent_id=self.bucket_uri,
                                object_id=BUCKET_QUOTA_OBJECT_ID)
        self.assertStatsEqual(data, {
            "collection_count": 1,
            "record_count": 0,
            "storage_size": storage_size
        })

        # Collection stats
        storage_size -= record_size(self.bucket)
        data = self.storage.get(collection_id=QUOTA_RESOURCE_NAME,
                                parent_id=self.collection_uri,
                                object_id=COLLECTION_QUOTA_OBJECT_ID)
        self.assertStatsEqual(data, {
            "record_count": 0,
            "storage_size": storage_size
        })
Пример #7
0
 def test_tracks_records_delete_with_multiple_records(self):
     self.create_bucket()
     self.create_collection()
     body = {'data': {'foo': 42}}
     self.app.post_json('{}/records'.format(self.collection_uri),
                        body,
                        headers=self.headers)
     self.app.post_json('{}/records'.format(self.collection_uri),
                        body,
                        headers=self.headers)
     self.app.post_json('{}/records'.format(self.collection_uri),
                        body,
                        headers=self.headers)
     self.app.post_json('{}/records'.format(self.collection_uri),
                        body,
                        headers=self.headers)
     self.app.delete('{}/records'.format(self.collection_uri),
                     headers=self.headers)
     storage_size = record_size(self.bucket) + record_size(self.collection)
     data = self.storage.get(collection_id=QUOTA_RESOURCE_NAME,
                             parent_id=self.bucket_uri,
                             object_id=BUCKET_QUOTA_OBJECT_ID)
     self.assertStatsEqual(data, {
         "collection_count": 1,
         "record_count": 0,
         "storage_size": storage_size
     })
Пример #8
0
    def test_507_is_raised_if_quota_exceeded_on_record_update(self):
        self.create_bucket()
        self.create_collection()
        self.create_record()
        body = {"data": {"foo": 42, "bar": "This is a very long string."}}
        resp = self.app.patch_json(self.record_uri,
                                   body,
                                   headers=self.headers,
                                   status=507)

        # Check that the storage was not updated.
        storage_size = record_size(self.bucket)
        storage_size += record_size(self.collection)
        storage_size += record_size(self.record)

        self.assertFormattedError(resp, 507, ERRORS.FORBIDDEN,
                                  "Insufficient Storage", self.error_message)

        data = self.storage.get(
            resource_name=QUOTA_RESOURCE_NAME,
            parent_id=self.bucket_uri,
            object_id=BUCKET_QUOTA_OBJECT_ID,
        )
        self.assertStatsEqual(data, {
            "collection_count": 1,
            "record_count": 1,
            "storage_size": storage_size
        })
Пример #9
0
    def test_quota_tracks_collection_creation(self):
        self.create_bucket()
        self.create_collection()

        # Bucket stats
        storage_size = record_size(self.bucket) + record_size(self.collection)
        data = self.storage.get(
            resource_name=QUOTA_RESOURCE_NAME,
            parent_id=self.bucket_uri,
            object_id=BUCKET_QUOTA_OBJECT_ID,
        )
        self.assertStatsEqual(data, {
            "collection_count": 1,
            "record_count": 0,
            "storage_size": storage_size
        })

        # Collection stats
        storage_size = record_size(self.collection)
        data = self.storage.get(QUOTA_RESOURCE_NAME, self.collection_uri,
                                COLLECTION_QUOTA_OBJECT_ID)
        self.assertStatsEqual(data, {
            "record_count": 0,
            "storage_size": storage_size
        })
Пример #10
0
    def test_507_is_raised_if_quota_exceeded_on_collection_update(self):
        self.create_bucket()
        self.create_collection()
        self.create_record()
        body = {'data': {'foo': 42, 'bar': 'This is a very long string.'}}
        resp = self.app.patch_json(self.collection_uri,
                                   body,
                                   headers=self.headers,
                                   status=507)

        storage_size = record_size(self.bucket)
        storage_size += record_size(self.collection)
        storage_size += record_size(self.record)

        self.assertFormattedError(resp, 507, ERRORS.FORBIDDEN,
                                  "Insufficient Storage", self.error_message)

        data = self.storage.get(collection_id=QUOTA_RESOURCE_NAME,
                                parent_id=self.bucket_uri,
                                object_id=BUCKET_QUOTA_OBJECT_ID)
        self.assertStatsEqual(data, {
            "collection_count": 1,
            "record_count": 1,
            "storage_size": storage_size
        })
Пример #11
0
    def test_507_is_raised_if_quota_exceeded_on_collection_creation(self):
        self.create_bucket()
        self.create_collection()
        self.create_record()
        body = {"data": {"foo": 42}}
        resp = self.app.post_json(
            "{}/collections".format(self.bucket_uri), body, headers=self.headers, status=507
        )

        storage_size = record_size(self.bucket)
        storage_size += record_size(self.collection)
        storage_size += record_size(self.record)

        self.assertFormattedError(
            resp, 507, ERRORS.FORBIDDEN, "Insufficient Storage", self.error_message
        )

        data = self.storage.get(
            collection_id=QUOTA_RESOURCE_NAME,
            parent_id=self.bucket_uri,
            object_id=BUCKET_QUOTA_OBJECT_ID,
        )
        self.assertStatsEqual(
            data, {"collection_count": 1, "record_count": 1, "storage_size": storage_size}
        )

        # Check that the collection wasn't created
        resp = self.app.get("{}/collections".format(self.bucket_uri), headers=self.headers)
        assert len(resp.json["data"]) == 1
Пример #12
0
    def test_tracks_collection_attributes_update(self):
        self.create_bucket()
        self.create_collection()
        body = {'data': {'foo': 'baz'}}
        resp = self.app.patch_json(self.collection_uri, body,
                                   headers=self.headers)
        # Bucket stats
        storage_size = record_size(self.bucket)
        storage_size += record_size(resp.json['data'])

        data = self.storage.get(collection_id=QUOTA_RESOURCE_NAME,
                                parent_id=self.bucket_uri,
                                object_id=QUOTA_BUCKET_ID)
        self.assertStatsEqual(data, {
            "collection_count": 1,
            "record_count": 0,
            "storage_size": storage_size
        })

        # Collection stats
        storage_size -= record_size(self.bucket)
        data = self.storage.get(collection_id=QUOTA_RESOURCE_NAME,
                                parent_id=self.collection_uri,
                                object_id=QUOTA_COLLECTION_ID)
        self.assertStatsEqual(data, {
            "record_count": 0,
            "storage_size": storage_size
        })
Пример #13
0
    def test_507_is_raised_if_quota_exceeded_on_group_update(self):
        self.create_bucket()
        self.create_collection()
        body = {"data": {"members": []}}
        resp = self.app.put_json(self.group_uri, body, headers=self.headers)
        group = resp.json["data"]
        body = {
            "data": {"members": ["elle", "lui", "je", "tu", "il", "nous", "vous", "ils", "elles"]}
        }
        resp = self.app.put_json(self.group_uri, body, headers=self.headers, status=507)

        storage_size = record_size(self.bucket)
        storage_size += record_size(self.collection)
        storage_size += record_size(group)

        self.assertFormattedError(
            resp, 507, ERRORS.FORBIDDEN, "Insufficient Storage", self.error_message
        )

        data = self.storage.get(
            collection_id=QUOTA_RESOURCE_NAME,
            parent_id=self.bucket_uri,
            object_id=BUCKET_QUOTA_OBJECT_ID,
        )
        self.assertStatsEqual(
            data, {"collection_count": 1, "record_count": 0, "storage_size": storage_size}
        )
Пример #14
0
    def test_507_is_raised_if_quota_exceeded_on_group_creation(self):
        self.create_bucket()
        self.create_collection()
        self.create_record()
        body = {'data': {'members': ['elle']}}
        resp = self.app.put_json(self.group_uri, body,
                                 headers=self.headers, status=507)

        storage_size = record_size(self.bucket)
        storage_size += record_size(self.collection)
        storage_size += record_size(self.record)

        self.assertFormattedError(
            resp, 507, ERRORS.FORBIDDEN, "Insufficient Storage",
            self.error_message)

        data = self.storage.get(collection_id=QUOTA_RESOURCE_NAME,
                                parent_id=self.bucket_uri,
                                object_id=QUOTA_BUCKET_ID)
        self.assertStatsEqual(data, {
            "collection_count": 1,
            "record_count": 1,
            "storage_size": storage_size
        })

        # Check that the group wasn't created
        resp = self.app.get('%s/groups' % self.bucket_uri,
                            headers=self.headers)
        assert len(resp.json['data']) == 0
Пример #15
0
    def test_507_is_raised_if_quota_exceeded_on_record_update(self):
        self.create_bucket()
        self.create_collection()
        self.create_record()
        body = {'data': {'foo': 42, 'bar': 'This is a very long string.'}}
        resp = self.app.patch_json(self.record_uri,
                                   body, headers=self.headers, status=507)

        # Check that the storage was not updated.
        storage_size = record_size(self.bucket)
        storage_size += record_size(self.collection)
        storage_size += record_size(self.record)

        self.assertFormattedError(
            resp, 507, ERRORS.FORBIDDEN, "Insufficient Storage",
            self.error_message)

        data = self.storage.get(collection_id=QUOTA_RESOURCE_NAME,
                                parent_id=self.bucket_uri,
                                object_id=QUOTA_BUCKET_ID)
        self.assertStatsEqual(data, {
            "collection_count": 1,
            "record_count": 1,
            "storage_size": storage_size
        })
Пример #16
0
    def test_507_is_raised_if_quota_exceeded_on_group_creation(self):
        self.create_bucket()
        self.create_collection()
        self.create_record()
        body = {'data': {'members': ['elle']}}
        resp = self.app.put_json(self.group_uri,
                                 body,
                                 headers=self.headers,
                                 status=507)

        storage_size = record_size(self.bucket)
        storage_size += record_size(self.collection)
        storage_size += record_size(self.record)

        self.assertFormattedError(resp, 507, ERRORS.FORBIDDEN,
                                  "Insufficient Storage", self.error_message)

        data = self.storage.get(collection_id=QUOTA_RESOURCE_NAME,
                                parent_id=self.bucket_uri,
                                object_id=BUCKET_QUOTA_OBJECT_ID)
        self.assertStatsEqual(data, {
            "collection_count": 1,
            "record_count": 1,
            "storage_size": storage_size
        })

        # Check that the group wasn't created
        resp = self.app.get('{}/groups'.format(self.bucket_uri),
                            headers=self.headers)
        assert len(resp.json['data']) == 0
Пример #17
0
 def test_quota_tracks_group_creation(self):
     self.create_bucket()
     self.create_group()
     storage_size = record_size(self.bucket) + record_size(self.group)
     data = self.storage.get(collection_id=QUOTA_RESOURCE_NAME,
                             parent_id=self.bucket_uri,
                             object_id=BUCKET_QUOTA_OBJECT_ID)
     self.assertStatsEqual(data, {
         "collection_count": 0,
         "record_count": 0,
         "storage_size": storage_size
     })
Пример #18
0
 def test_quota_tracks_group_creation(self):
     self.create_bucket()
     self.create_group()
     storage_size = record_size(self.bucket) + record_size(self.group)
     data = self.storage.get(collection_id=QUOTA_RESOURCE_NAME,
                             parent_id=self.bucket_uri,
                             object_id=QUOTA_BUCKET_ID)
     self.assertStatsEqual(data, {
         "collection_count": 0,
         "record_count": 0,
         "storage_size": storage_size
     })
Пример #19
0
 def test_quota_tracks_record_creation(self):
     self.create_bucket()
     self.create_collection()
     self.create_record()
     storage_size = record_size(self.bucket)
     storage_size += record_size(self.collection)
     storage_size += record_size(self.record)
     data = self.storage.get(
         collection_id=QUOTA_RESOURCE_NAME,
         parent_id=self.bucket_uri,
         object_id=BUCKET_QUOTA_OBJECT_ID,
     )
     self.assertStatsEqual(
         data, {"collection_count": 1, "record_count": 1, "storage_size": storage_size}
     )
Пример #20
0
 def test_tracks_group_attributes_update(self):
     self.create_bucket()
     self.create_group()
     body = {"data": {"foo": "baz", "members": ["lui"]}}
     resp = self.app.patch_json(self.group_uri, body, headers=self.headers)
     storage_size = record_size(self.bucket)
     storage_size += record_size(resp.json["data"])
     data = self.storage.get(
         resource_name=QUOTA_RESOURCE_NAME,
         parent_id=self.bucket_uri,
         object_id=BUCKET_QUOTA_OBJECT_ID,
     )
     self.assertStatsEqual(
         data, {"collection_count": 0, "record_count": 0, "storage_size": storage_size}
     )
Пример #21
0
 def test_tracks_record_delete(self):
     self.create_bucket()
     self.create_collection()
     self.create_record()
     self.app.delete(self.record_uri, headers=self.headers)
     storage_size = record_size(self.bucket)
     storage_size += record_size(self.collection)
     data = self.storage.get(collection_id=QUOTA_RESOURCE_NAME,
                             parent_id=self.bucket_uri,
                             object_id=QUOTA_BUCKET_ID)
     self.assertStatsEqual(data, {
         "collection_count": 1,
         "record_count": 0,
         "storage_size": storage_size
     })
Пример #22
0
 def test_tracks_group_attributes_update(self):
     self.create_bucket()
     self.create_group()
     body = {'data': {'foo': 'baz', 'members': ['lui']}}
     resp = self.app.patch_json(self.group_uri, body, headers=self.headers)
     storage_size = record_size(self.bucket)
     storage_size += record_size(resp.json['data'])
     data = self.storage.get(collection_id=QUOTA_RESOURCE_NAME,
                             parent_id=self.bucket_uri,
                             object_id=BUCKET_QUOTA_OBJECT_ID)
     self.assertStatsEqual(data, {
         "collection_count": 0,
         "record_count": 0,
         "storage_size": storage_size
     })
Пример #23
0
 def test_tracks_record_delete(self):
     self.create_bucket()
     self.create_collection()
     self.create_record()
     self.app.delete(self.record_uri, headers=self.headers)
     storage_size = record_size(self.bucket)
     storage_size += record_size(self.collection)
     data = self.storage.get(collection_id=QUOTA_RESOURCE_NAME,
                             parent_id=self.bucket_uri,
                             object_id=BUCKET_QUOTA_OBJECT_ID)
     self.assertStatsEqual(data, {
         "collection_count": 1,
         "record_count": 0,
         "storage_size": storage_size
     })
Пример #24
0
 def test_tracks_group_attributes_update(self):
     self.create_bucket()
     self.create_group()
     body = {"data": {"foo": "baz", "members": ["lui"]}}
     resp = self.app.patch_json(self.group_uri, body, headers=self.headers)
     storage_size = record_size(self.bucket)
     storage_size += record_size(resp.json["data"])
     data = self.storage.get(
         collection_id=QUOTA_RESOURCE_NAME,
         parent_id=self.bucket_uri,
         object_id=BUCKET_QUOTA_OBJECT_ID,
     )
     self.assertStatsEqual(
         data, {"collection_count": 0, "record_count": 0, "storage_size": storage_size}
     )
Пример #25
0
 def test_quota_tracks_bucket_creation(self):
     self.create_bucket()
     self.create_collection()
     self.create_record()
     storage_size = record_size(self.bucket)
     storage_size += record_size(self.collection)
     storage_size += record_size(self.record)
     data = self.storage.get(collection_id=QUOTA_RESOURCE_NAME,
                             parent_id=self.bucket_uri,
                             object_id=QUOTA_BUCKET_ID)
     self.assertStatsEqual(data, {
         "collection_count": 1,
         "record_count": 1,
         "storage_size": storage_size
     })
Пример #26
0
 def test_tracks_record_attributes_update(self):
     self.create_bucket()
     self.create_collection()
     self.create_record()
     resp = self.app.patch_json(self.record_uri, {"data": {"foo": "baz"}}, headers=self.headers)
     storage_size = record_size(self.bucket)
     storage_size += record_size(self.collection)
     storage_size += record_size(resp.json["data"])
     data = self.storage.get(
         collection_id=QUOTA_RESOURCE_NAME,
         parent_id=self.bucket_uri,
         object_id=BUCKET_QUOTA_OBJECT_ID,
     )
     self.assertStatsEqual(
         data, {"collection_count": 1, "record_count": 1, "storage_size": storage_size}
     )
Пример #27
0
 def test_tracks_collection_delete_with_multiple_records(self):
     self.create_bucket()
     self.create_collection()
     body = {"data": {"foo": 42}}
     self.app.post_json("{}/records".format(self.collection_uri),
                        body,
                        headers=self.headers)
     self.app.post_json("{}/records".format(self.collection_uri),
                        body,
                        headers=self.headers)
     self.app.post_json("{}/records".format(self.collection_uri),
                        body,
                        headers=self.headers)
     self.app.post_json("{}/records".format(self.collection_uri),
                        body,
                        headers=self.headers)
     self.app.delete(self.collection_uri, headers=self.headers)
     data = self.storage.get(
         resource_name=QUOTA_RESOURCE_NAME,
         parent_id=self.bucket_uri,
         object_id=BUCKET_QUOTA_OBJECT_ID,
     )
     self.assertStatsEqual(
         data,
         {
             "collection_count": 0,
             "record_count": 0,
             "storage_size": record_size(self.bucket)
         },
     )
Пример #28
0
    def test_507_is_not_raised_if_quota_exceeded_on_collection_delete(self):
        self.create_bucket()
        self.create_collection()
        # fake the quota to the Max
        data = self.storage.get(collection_id=QUOTA_RESOURCE_NAME,
                                parent_id=self.bucket_uri,
                                object_id=QUOTA_BUCKET_ID)
        data['storage_size'] = 140
        self.storage.update(collection_id=QUOTA_RESOURCE_NAME,
                            parent_id=self.bucket_uri,
                            object_id=QUOTA_BUCKET_ID,
                            record=data)
        transaction.commit()
        self.app.delete(self.collection_uri,
                        headers=self.headers)

        storage_size = 140
        storage_size -= record_size(self.collection)
        data = self.storage.get(collection_id=QUOTA_RESOURCE_NAME,
                                parent_id=self.bucket_uri,
                                object_id=QUOTA_BUCKET_ID)
        self.assertStatsEqual(data, {
            "collection_count": 0,
            "record_count": 0,
            "storage_size": storage_size
        })
Пример #29
0
 def test_tracks_record_attributes_update(self):
     self.create_bucket()
     self.create_collection()
     self.create_record()
     resp = self.app.patch_json(self.record_uri, {"data": {"foo": "baz"}}, headers=self.headers)
     storage_size = record_size(self.bucket)
     storage_size += record_size(self.collection)
     storage_size += record_size(resp.json["data"])
     data = self.storage.get(
         resource_name=QUOTA_RESOURCE_NAME,
         parent_id=self.bucket_uri,
         object_id=BUCKET_QUOTA_OBJECT_ID,
     )
     self.assertStatsEqual(
         data, {"collection_count": 1, "record_count": 1, "storage_size": storage_size}
     )
Пример #30
0
    def test_507_is_raised_if_quota_exceeded_on_group_delete(self):
        self.create_bucket()
        body = {"data": {"members": []}}
        resp = self.app.put_json(self.group_uri, body, headers=self.headers)
        group = resp.json['data']
        # fake the quota to the Max
        data = self.storage.get(collection_id=QUOTA_RESOURCE_NAME,
                                parent_id=self.bucket_uri,
                                object_id=QUOTA_BUCKET_ID)
        data['storage_size'] = 140
        self.storage.update(collection_id=QUOTA_RESOURCE_NAME,
                            parent_id=self.bucket_uri,
                            object_id=QUOTA_BUCKET_ID,
                            record=data)
        transaction.commit()

        self.app.delete(self.group_uri, headers=self.headers)

        storage_size = 140
        storage_size -= record_size(group)
        data = self.storage.get(collection_id=QUOTA_RESOURCE_NAME,
                                parent_id=self.bucket_uri,
                                object_id=QUOTA_BUCKET_ID)
        self.assertStatsEqual(data, {
            "collection_count": 0,
            "record_count": 0,
            "storage_size": storage_size
        })
Пример #31
0
 def test_tracks_group_attributes_update(self):
     self.create_bucket()
     self.create_group()
     body = {'data': {'foo': 'baz', 'members': ['lui']}}
     resp = self.app.patch_json(self.group_uri, body,
                                headers=self.headers)
     storage_size = record_size(self.bucket)
     storage_size += record_size(resp.json['data'])
     data = self.storage.get(collection_id=QUOTA_RESOURCE_NAME,
                             parent_id=self.bucket_uri,
                             object_id=QUOTA_BUCKET_ID)
     self.assertStatsEqual(data, {
         "collection_count": 0,
         "record_count": 0,
         "storage_size": storage_size
     })
Пример #32
0
    def test_507_is_raised_if_quota_exceeded_on_group_delete(self):
        self.create_bucket()
        body = {"data": {"members": []}}
        resp = self.app.put_json(self.group_uri, body, headers=self.headers)
        group = resp.json['data']
        # fake the quota to the Max
        data = self.storage.get(collection_id=QUOTA_RESOURCE_NAME,
                                parent_id=self.bucket_uri,
                                object_id=BUCKET_QUOTA_OBJECT_ID)
        data['storage_size'] = 140
        self.storage.update(collection_id=QUOTA_RESOURCE_NAME,
                            parent_id=self.bucket_uri,
                            object_id=BUCKET_QUOTA_OBJECT_ID,
                            record=data)
        transaction.commit()

        self.app.delete(self.group_uri, headers=self.headers)

        storage_size = 140
        storage_size -= record_size(group)
        data = self.storage.get(collection_id=QUOTA_RESOURCE_NAME,
                                parent_id=self.bucket_uri,
                                object_id=BUCKET_QUOTA_OBJECT_ID)
        self.assertStatsEqual(data, {
            "collection_count": 0,
            "record_count": 0,
            "storage_size": storage_size
        })
Пример #33
0
    def test_507_is_not_raised_if_quota_exceeded_on_collection_delete(self):
        self.create_bucket()
        self.create_collection()
        # fake the quota to the Max
        data = self.storage.get(collection_id=QUOTA_RESOURCE_NAME,
                                parent_id=self.bucket_uri,
                                object_id=BUCKET_QUOTA_OBJECT_ID)
        data['storage_size'] = 140
        self.storage.update(collection_id=QUOTA_RESOURCE_NAME,
                            parent_id=self.bucket_uri,
                            object_id=BUCKET_QUOTA_OBJECT_ID,
                            record=data)
        transaction.commit()
        self.app.delete(self.collection_uri, headers=self.headers)

        storage_size = 140
        storage_size -= record_size(self.collection)
        data = self.storage.get(collection_id=QUOTA_RESOURCE_NAME,
                                parent_id=self.bucket_uri,
                                object_id=BUCKET_QUOTA_OBJECT_ID)
        self.assertStatsEqual(data, {
            "collection_count": 0,
            "record_count": 0,
            "storage_size": storage_size
        })
Пример #34
0
    def test_507_is_not_raised_if_quota_exceeded_on_record_delete(self):
        self.create_bucket()
        self.create_collection()
        self.create_record()
        self.app.delete(self.record_uri, headers=self.headers)

        # Check that the storage was not updated.
        storage_size = record_size(self.bucket)
        storage_size += record_size(self.collection)
        data = self.storage.get(collection_id=QUOTA_RESOURCE_NAME,
                                parent_id=self.bucket_uri,
                                object_id=BUCKET_QUOTA_OBJECT_ID)
        self.assertStatsEqual(data, {
            "collection_count": 1,
            "record_count": 0,
            "storage_size": storage_size
        })
Пример #35
0
 def test_tracks_record_attributes_update(self):
     self.create_bucket()
     self.create_collection()
     self.create_record()
     resp = self.app.patch_json(self.record_uri, {'data': {'foo': 'baz'}},
                                headers=self.headers)
     storage_size = record_size(self.bucket)
     storage_size += record_size(self.collection)
     storage_size += record_size(resp.json['data'])
     data = self.storage.get(collection_id=QUOTA_RESOURCE_NAME,
                             parent_id=self.bucket_uri,
                             object_id=QUOTA_BUCKET_ID)
     self.assertStatsEqual(data, {
         "collection_count": 1,
         "record_count": 1,
         "storage_size": storage_size
     })
Пример #36
0
    def test_507_is_not_raised_if_quota_exceeded_on_record_delete(self):
        self.create_bucket()
        self.create_collection()
        self.create_record()
        self.app.delete(self.record_uri, headers=self.headers)

        # Check that the storage was not updated.
        storage_size = record_size(self.bucket)
        storage_size += record_size(self.collection)
        data = self.storage.get(collection_id=QUOTA_RESOURCE_NAME,
                                parent_id=self.bucket_uri,
                                object_id=QUOTA_BUCKET_ID)
        self.assertStatsEqual(data, {
            "collection_count": 1,
            "record_count": 0,
            "storage_size": storage_size
        })
Пример #37
0
 def test_tracks_records_delete_with_multiple_records(self):
     self.create_bucket()
     self.create_collection()
     body = {"data": {"foo": 42}}
     self.app.post_json("{}/records".format(self.collection_uri), body, headers=self.headers)
     self.app.post_json("{}/records".format(self.collection_uri), body, headers=self.headers)
     self.app.post_json("{}/records".format(self.collection_uri), body, headers=self.headers)
     self.app.post_json("{}/records".format(self.collection_uri), body, headers=self.headers)
     self.app.delete("{}/records".format(self.collection_uri), headers=self.headers)
     storage_size = record_size(self.bucket) + record_size(self.collection)
     data = self.storage.get(
         collection_id=QUOTA_RESOURCE_NAME,
         parent_id=self.bucket_uri,
         object_id=BUCKET_QUOTA_OBJECT_ID,
     )
     self.assertStatsEqual(
         data, {"collection_count": 1, "record_count": 0, "storage_size": storage_size}
     )
Пример #38
0
    def test_507_is_raised_if_quota_exceeded_on_record_update(self):
        self.create_bucket()
        self.create_collection()
        self.create_record()
        body = {"data": {"foo": 42, "bar": "This is a very long string."}}
        resp = self.app.patch_json(self.record_uri, body, headers=self.headers, status=507)

        # Check that the storage was not updated.
        storage_size = record_size(self.collection)
        storage_size += record_size(self.record)

        self.assertFormattedError(
            resp, 507, ERRORS.FORBIDDEN, "Insufficient Storage", self.error_message
        )

        data = self.storage.get(
            QUOTA_RESOURCE_NAME, self.collection_uri, COLLECTION_QUOTA_OBJECT_ID
        )
        self.assertStatsEqual(data, {"record_count": 1, "storage_size": storage_size})
Пример #39
0
    def test_quota_tracks_collection_creation(self):
        self.create_bucket()
        self.create_collection()

        # Bucket stats
        storage_size = record_size(self.bucket) + record_size(self.collection)
        data = self.storage.get(
            collection_id=QUOTA_RESOURCE_NAME,
            parent_id=self.bucket_uri,
            object_id=BUCKET_QUOTA_OBJECT_ID,
        )
        self.assertStatsEqual(
            data, {"collection_count": 1, "record_count": 0, "storage_size": storage_size}
        )

        # Collection stats
        storage_size = record_size(self.collection)
        data = self.storage.get(
            QUOTA_RESOURCE_NAME, self.collection_uri, COLLECTION_QUOTA_OBJECT_ID
        )
        self.assertStatsEqual(data, {"record_count": 0, "storage_size": storage_size})
Пример #40
0
    def test_507_is_not_raised_if_quota_exceeded_on_record_delete(self):
        self.create_bucket()
        self.create_collection()
        self.create_record()
        self.app.delete(self.record_uri, headers=self.headers)

        # Check that the storage was not updated.
        storage_size = record_size(self.collection)
        data = self.storage.get(
            QUOTA_RESOURCE_NAME, self.collection_uri, COLLECTION_QUOTA_OBJECT_ID
        )
        self.assertStatsEqual(data, {"record_count": 0, "storage_size": storage_size})
Пример #41
0
    def test_507_is_raised_if_quota_exceeded_on_record_creation(self):
        self.create_bucket()
        self.create_collection()
        self.create_record()
        body = {"data": {"foo": 42}}
        resp = self.app.post_json(
            "{}/records".format(self.collection_uri), body, headers=self.headers, status=507
        )

        # Check that the storage was not updated.
        storage_size = record_size(self.collection)
        storage_size += record_size(self.record)

        self.assertFormattedError(
            resp, 507, ERRORS.FORBIDDEN, "Insufficient Storage", self.error_message
        )

        data = self.storage.get(
            QUOTA_RESOURCE_NAME, self.collection_uri, COLLECTION_QUOTA_OBJECT_ID
        )
        self.assertStatsEqual(data, {"record_count": 1, "storage_size": storage_size})
Пример #42
0
    def test_507_is_not_raised_if_quota_exceeded_on_record_delete(self):
        self.create_bucket()
        self.create_collection()
        self.create_record()
        self.app.delete(self.record_uri, headers=self.headers)

        # Check that the storage was not updated.
        storage_size = record_size(self.collection)
        data = self.storage.get(
            QUOTA_RESOURCE_NAME, self.collection_uri, COLLECTION_QUOTA_OBJECT_ID
        )
        self.assertStatsEqual(data, {"record_count": 0, "storage_size": storage_size})
Пример #43
0
 def test_tracks_group_delete(self):
     self.create_bucket()
     self.create_group()
     self.app.delete(self.group_uri, headers=self.headers)
     data = self.storage.get(collection_id=QUOTA_RESOURCE_NAME,
                             parent_id=self.bucket_uri,
                             object_id=QUOTA_BUCKET_ID)
     self.assertStatsEqual(data, {
         "collection_count": 0,
         "record_count": 0,
         "storage_size": record_size(self.bucket)
     })
Пример #44
0
 def test_tracks_group_delete(self):
     self.create_bucket()
     self.create_group()
     self.app.delete(self.group_uri, headers=self.headers)
     data = self.storage.get(
         collection_id=QUOTA_RESOURCE_NAME,
         parent_id=self.bucket_uri,
         object_id=BUCKET_QUOTA_OBJECT_ID,
     )
     self.assertStatsEqual(
         data,
         {"collection_count": 0, "record_count": 0, "storage_size": record_size(self.bucket)},
     )
Пример #45
0
    def test_507_is_raised_if_quota_exceeded_on_record_creation(self):
        self.create_bucket()
        self.create_collection()
        self.create_record()
        body = {'data': {'foo': 42}}
        resp = self.app.post_json('%s/records' % self.collection_uri,
                                  body, headers=self.headers, status=507)

        # Check that the storage was not updated.
        storage_size = record_size(self.collection)
        storage_size += record_size(self.record)

        self.assertFormattedError(
            resp, 507, ERRORS.FORBIDDEN, "Insufficient Storage",
            self.error_message)

        data = self.storage.get(QUOTA_RESOURCE_NAME, self.collection_uri,
                                QUOTA_COLLECTION_ID)
        self.assertStatsEqual(data, {
            "record_count": 1,
            "storage_size": storage_size
        })
Пример #46
0
 def test_tracks_records_delete_with_multiple_records(self):
     self.create_bucket()
     self.create_collection()
     body = {'data': {'foo': 42}}
     self.app.post_json('%s/records' % self.collection_uri,
                        body, headers=self.headers)
     self.app.post_json('%s/records' % self.collection_uri,
                        body, headers=self.headers)
     self.app.post_json('%s/records' % self.collection_uri,
                        body, headers=self.headers)
     self.app.post_json('%s/records' % self.collection_uri,
                        body, headers=self.headers)
     self.app.delete('%s/records' % self.collection_uri,
                     headers=self.headers)
     storage_size = record_size(self.bucket) + record_size(self.collection)
     data = self.storage.get(collection_id=QUOTA_RESOURCE_NAME,
                             parent_id=self.bucket_uri,
                             object_id=QUOTA_BUCKET_ID)
     self.assertStatsEqual(data, {
         "collection_count": 1,
         "record_count": 0,
         "storage_size": storage_size
     })
Пример #47
0
 def test_tracks_collection_delete(self):
     self.create_bucket()
     self.create_collection()
     body = {'data': {'foo': 'baz'}}
     self.app.patch_json(self.collection_uri, body, headers=self.headers)
     self.app.delete(self.collection_uri, headers=self.headers)
     data = self.storage.get(collection_id=QUOTA_RESOURCE_NAME,
                             parent_id=self.bucket_uri,
                             object_id=BUCKET_QUOTA_OBJECT_ID)
     self.assertStatsEqual(
         data, {
             "collection_count": 0,
             "record_count": 0,
             "storage_size": record_size(self.bucket)
         })
Пример #48
0
 def test_tracks_collection_delete(self):
     self.create_bucket()
     self.create_collection()
     body = {'data': {'foo': 'baz'}}
     self.app.patch_json(self.collection_uri, body,
                         headers=self.headers)
     self.app.delete(self.collection_uri, headers=self.headers)
     data = self.storage.get(collection_id=QUOTA_RESOURCE_NAME,
                             parent_id=self.bucket_uri,
                             object_id=QUOTA_BUCKET_ID)
     self.assertStatsEqual(data, {
         "collection_count": 0,
         "record_count": 0,
         "storage_size": record_size(self.bucket)
     })
Пример #49
0
    def test_bulk_delete(self):
        self.create_bucket()
        self.create_collection()
        self.create_record()

        body = {
            "defaults": {"method": "POST", "path": "{}/collections".format(self.bucket_uri)},
            "requests": [
                {"body": {"data": {"id": "a", "attr": 1}}},
                {"body": {"data": {"id": "b", "attr": 2}}},
                {"body": {"data": {"id": "c", "attr": 3}}},
            ],
        }
        self.app.post_json("/batch", body, headers=self.headers)

        body = {
            "defaults": {"method": "DELETE"},
            "requests": [
                {"path": "{}/collections/a".format(self.bucket_uri)},
                {"path": "{}/collections/b".format(self.bucket_uri)},
                {"path": "{}/collections/c".format(self.bucket_uri)},
                {"path": self.collection_uri},
            ],
        }
        self.app.post_json("/batch", body, headers=self.headers)

        data = self.storage.get(
            collection_id=QUOTA_RESOURCE_NAME,
            parent_id=self.bucket_uri,
            object_id=BUCKET_QUOTA_OBJECT_ID,
        )
        self.assertStatsEqual(
            data,
            {"collection_count": 0, "record_count": 0, "storage_size": record_size(self.bucket)},
        )

        with pytest.raises(RecordNotFoundError):
            self.storage.get(
                collection_id=QUOTA_RESOURCE_NAME,
                parent_id="{}/collections/a".format(self.bucket_uri),
                object_id=COLLECTION_QUOTA_OBJECT_ID,
            )

        with pytest.raises(RecordNotFoundError):
            self.storage.get(
                collection_id=QUOTA_RESOURCE_NAME,
                parent_id="{}/collections/b".format(self.bucket_uri),
                object_id=COLLECTION_QUOTA_OBJECT_ID,
            )

        with pytest.raises(RecordNotFoundError):
            self.storage.get(
                collection_id=QUOTA_RESOURCE_NAME,
                parent_id="{}/collections/c".format(self.bucket_uri),
                object_id=COLLECTION_QUOTA_OBJECT_ID,
            )

        with pytest.raises(RecordNotFoundError):
            self.storage.get(
                collection_id=QUOTA_RESOURCE_NAME,
                parent_id=self.collection_uri,
                object_id=COLLECTION_QUOTA_OBJECT_ID,
            )
Пример #50
0
    def test_bulk_delete(self):
        self.create_bucket()
        self.create_collection()
        self.create_record()

        body = {
            "defaults": {"method": "POST", "path": "{}/collections".format(self.bucket_uri)},
            "requests": [
                {"body": {"data": {"id": "a", "attr": 1}}},
                {"body": {"data": {"id": "b", "attr": 2}}},
                {"body": {"data": {"id": "c", "attr": 3}}},
            ],
        }
        self.app.post_json("/batch", body, headers=self.headers)

        body = {
            "defaults": {"method": "DELETE"},
            "requests": [
                {"path": "{}/collections/a".format(self.bucket_uri)},
                {"path": "{}/collections/b".format(self.bucket_uri)},
                {"path": "{}/collections/c".format(self.bucket_uri)},
                {"path": self.collection_uri},
            ],
        }
        self.app.post_json("/batch", body, headers=self.headers)

        data = self.storage.get(
            resource_name=QUOTA_RESOURCE_NAME,
            parent_id=self.bucket_uri,
            object_id=BUCKET_QUOTA_OBJECT_ID,
        )
        self.assertStatsEqual(
            data,
            {"collection_count": 0, "record_count": 0, "storage_size": record_size(self.bucket)},
        )

        with pytest.raises(ObjectNotFoundError):
            self.storage.get(
                resource_name=QUOTA_RESOURCE_NAME,
                parent_id="{}/collections/a".format(self.bucket_uri),
                object_id=COLLECTION_QUOTA_OBJECT_ID,
            )

        with pytest.raises(ObjectNotFoundError):
            self.storage.get(
                resource_name=QUOTA_RESOURCE_NAME,
                parent_id="{}/collections/b".format(self.bucket_uri),
                object_id=COLLECTION_QUOTA_OBJECT_ID,
            )

        with pytest.raises(ObjectNotFoundError):
            self.storage.get(
                resource_name=QUOTA_RESOURCE_NAME,
                parent_id="{}/collections/c".format(self.bucket_uri),
                object_id=COLLECTION_QUOTA_OBJECT_ID,
            )

        with pytest.raises(ObjectNotFoundError):
            self.storage.get(
                resource_name=QUOTA_RESOURCE_NAME,
                parent_id=self.collection_uri,
                object_id=COLLECTION_QUOTA_OBJECT_ID,
            )
Пример #51
0
    def test_bulk_delete(self):
        self.create_bucket()
        self.create_collection()
        self.create_record()

        body = {
            'defaults': {
                'method': 'POST',
                'path': '{}/collections'.format(self.bucket_uri),
            },
            'requests': [{
                'body': {
                    'data': {
                        'id': 'a',
                        'attr': 1
                    }
                },
            }, {
                'body': {
                    'data': {
                        'id': 'b',
                        'attr': 2
                    }
                },
            }, {
                'body': {
                    'data': {
                        'id': 'c',
                        'attr': 3
                    }
                }
            }]
        }
        self.app.post_json('/batch', body, headers=self.headers)

        body = {
            'defaults': {
                'method': 'DELETE',
            },
            'requests': [{
                'path': '{}/collections/a'.format(self.bucket_uri)
            }, {
                'path': '{}/collections/b'.format(self.bucket_uri)
            }, {
                'path': '{}/collections/c'.format(self.bucket_uri)
            }, {
                'path': self.collection_uri
            }]
        }
        self.app.post_json('/batch', body, headers=self.headers)

        data = self.storage.get(collection_id=QUOTA_RESOURCE_NAME,
                                parent_id=self.bucket_uri,
                                object_id=BUCKET_QUOTA_OBJECT_ID)
        self.assertStatsEqual(
            data, {
                "collection_count": 0,
                "record_count": 0,
                "storage_size": record_size(self.bucket)
            })

        with pytest.raises(RecordNotFoundError):
            self.storage.get(collection_id=QUOTA_RESOURCE_NAME,
                             parent_id='{}/collections/a'.format(
                                 self.bucket_uri),
                             object_id=COLLECTION_QUOTA_OBJECT_ID)

        with pytest.raises(RecordNotFoundError):
            self.storage.get(collection_id=QUOTA_RESOURCE_NAME,
                             parent_id='{}/collections/b'.format(
                                 self.bucket_uri),
                             object_id=COLLECTION_QUOTA_OBJECT_ID)

        with pytest.raises(RecordNotFoundError):
            self.storage.get(collection_id=QUOTA_RESOURCE_NAME,
                             parent_id='{}/collections/c'.format(
                                 self.bucket_uri),
                             object_id=COLLECTION_QUOTA_OBJECT_ID)

        with pytest.raises(RecordNotFoundError):
            self.storage.get(collection_id=QUOTA_RESOURCE_NAME,
                             parent_id=self.collection_uri,
                             object_id=COLLECTION_QUOTA_OBJECT_ID)
Пример #52
0
    def test_bulk_delete(self):
        self.create_bucket()
        self.create_collection()
        self.create_record()

        body = {
            'defaults': {
                'method': 'POST',
                'path': '%s/collections' % self.bucket_uri,
            },
            'requests': [{
                'body': {'data': {'id': 'a', 'attr': 1}},
            }, {
                'body': {'data': {'id': 'b', 'attr': 2}},
            }, {
                'body': {'data': {'id': 'c', 'attr': 3}}
            }]
        }
        self.app.post_json('/batch', body, headers=self.headers)

        body = {
            'defaults': {
                'method': 'DELETE',
            },
            'requests': [{
                'path': '%s/collections/a' % self.bucket_uri
            }, {
                'path': '%s/collections/b' % self.bucket_uri
            }, {
                'path': '%s/collections/c' % self.bucket_uri
            }, {
                'path': self.collection_uri
            }]
        }
        self.app.post_json('/batch', body, headers=self.headers)

        data = self.storage.get(collection_id=QUOTA_RESOURCE_NAME,
                                parent_id=self.bucket_uri,
                                object_id=QUOTA_BUCKET_ID)
        self.assertStatsEqual(data, {
            "collection_count": 0,
            "record_count": 0,
            "storage_size": record_size(self.bucket)
        })

        with pytest.raises(RecordNotFoundError):
            self.storage.get(collection_id=QUOTA_RESOURCE_NAME,
                             parent_id='%s/collections/a' % self.bucket_uri,
                             object_id=QUOTA_COLLECTION_ID)

        with pytest.raises(RecordNotFoundError):
            self.storage.get(collection_id=QUOTA_RESOURCE_NAME,
                             parent_id='%s/collections/b' % self.bucket_uri,
                             object_id=QUOTA_COLLECTION_ID)

        with pytest.raises(RecordNotFoundError):
            self.storage.get(collection_id=QUOTA_RESOURCE_NAME,
                             parent_id='%s/collections/c' % self.bucket_uri,
                             object_id=QUOTA_COLLECTION_ID)

        with pytest.raises(RecordNotFoundError):
            self.storage.get(collection_id=QUOTA_RESOURCE_NAME,
                             parent_id=self.collection_uri,
                             object_id=QUOTA_COLLECTION_ID)