Example #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}
        )
Example #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
        })
Example #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
Example #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
        })
Example #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
Example #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
        })
Example #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
     })
Example #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
        })
Example #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
        })
Example #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
        })
Example #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
Example #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
        })
Example #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}
        )
Example #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
Example #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
        })
Example #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
Example #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
     })
Example #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
     })
Example #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}
     )
Example #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}
     )
Example #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
     })
Example #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
     })
Example #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
     })
Example #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}
     )
Example #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
     })
Example #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}
     )
Example #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)
         },
     )
Example #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
        })
Example #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}
     )
Example #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
        })
Example #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
     })
Example #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
        })
Example #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
        })
Example #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
        })
Example #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
     })
Example #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
        })
Example #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}
     )
Example #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})
Example #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})
Example #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})
Example #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})
Example #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})
Example #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)
     })
Example #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)},
     )
Example #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
        })
Example #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
     })
Example #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)
         })
Example #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)
     })
Example #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,
            )
Example #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,
            )
Example #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)
Example #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)