def test_upsert_with_options(self): """正常にバケット作成・更新できること""" self.bucket = baas.Buckets(self.masterService, "file") # create desc = "test bucket description" acl = {"u": ["g:authenticated"]} content_acl = {"d": ["g:anonymous"]} res = self.bucket.upsert("bucket1", desc=desc, acl=acl, content_acl=content_acl) assert res["name"] == "bucket1" assert res["description"] == desc assert res["ACL"]["u"] == ["g:authenticated"] assert res["contentACL"]["d"] == ["g:anonymous"] # update desc = "upsert description" acl = {"u": ["g:anonymous"]} content_acl = {"d": ["g:authenticated"]} res = self.bucket.upsert("bucket1", desc=desc, acl=acl, content_acl=content_acl) assert res["name"] == "bucket1" assert res["description"] == desc assert res["ACL"]["u"] == ["g:anonymous"] assert res["contentACL"]["d"] == ["g:authenticated"]
def test_remove(self): """正常にバケット削除できること""" self.bucket = baas.Buckets(self.masterService, "object") self.bucket.upsert("bucket1") # remove self.bucket.remove("bucket1")
def test_init(self): """正常に初期化できること""" service = mock_service_json_resp("") bucket = baas.Buckets(service, "file") assert bucket.service == service assert bucket.bucket_type == "file"
def setup(self): self.service = util.create_service() self.master_service = util.create_service(master=True) # ensure bucket buckets = baas.Buckets(self.master_service, "object") buckets.upsert(self.TEST_BUCKET, desc="performance test", acl={}, content_acl={ "r": ["g:anonymous"], "w": ["g:anonymous"] }) self.bucket = baas.ObjectBucket(self.service, self.TEST_BUCKET) (res, total) = self.bucket.query_with_count(limit=1) if total == 10000: # ok, test data exists return elif total > 0: # re-create buckets buckets.remove(self.TEST_BUCKET) buckets.upsert(self.TEST_BUCKET, content_acl={ "r": ["g:anonymous"], "w": ["g:anonymous"] }) self.create_test_data_10000()
def test_get(self): """正常にバケット取得できること""" self.bucket = baas.Buckets(self.masterService, "object") create_res = self.bucket.upsert("bucket1") # get get_res = self.bucket.get("bucket1") assert create_res == get_res
def _cleanup(self, key, num): master_service = util.create_service(master=True, key=key) try: buckets = baas.Buckets(master_service, "object") buckets.remove("bucket" + str(num)) except HTTPError: pass util.remove_all_users(key)
def test_query(self): """正常にバケット全件検索できること""" self.bucket = baas.Buckets(self.masterService, "object") num = 10 for i in range(num): self.bucket.upsert("bucket" + str(i)) # query results = self.bucket.query() assert len(results) == num for i in range(num): assert results[i]["name"] == "bucket" + str(i)
def setup_bucket_and_user(self, bucket_type): self.service = util.create_service() self.masterService = util.create_service(master=True) self.buckets = baas.Buckets(self.masterService, bucket_type) self.user = util.setup_user(self.service) try: self.buckets.remove("bucket1") except HTTPError: pass # Create test bucket self.buckets.upsert("bucket1", content_acl={"r": ["g:authenticated"], "w": ["g:authenticated"]})
def test_upsert(self): """正常にバケット作成・更新できること""" self.bucket = baas.Buckets(self.masterService, "object") # create create_res = self.bucket.upsert("bucket1") assert create_res["name"] == "bucket1" assert create_res["description"] == "" assert "ACL" in create_res assert "contentACL" in create_res # update with pytest.raises(HTTPError) as ei: self.bucket.upsert("bucket1") status_code = ei.value.response.status_code assert status_code == 400
def _setup(self, key, num): master_service = util.create_service(master=True, key=key) util.remove_all_users(key) user = baas.User(master_service) user.username = "******" + str(num) user.email = "user" + str(num) + "@example.com" user.password = "******" + str(num) user.register() buckets = baas.Buckets(master_service, "object") bucket_name = "bucket" + str(num) try: buckets.remove(bucket_name) except HTTPError: pass buckets.upsert(bucket_name, content_acl={"r": ["g:authenticated"], "w": ["g:authenticated"]})
def get_bucket(self, expected_result): service = mock_service_json_resp(expected_result) bucket = baas.Buckets(service, "object") return service, bucket
def test_init_bad_bucket_type(self): """バケットタイプが不正の場合はエラーになること""" service = mock_service_json_resp("") with pytest.raises(ValueError): baas.Buckets(service, "type")
def drop_test_object_bucket(self): buckets = baas.Buckets(self.master_service, "object") try: buckets.remove(self.TEST_BUCKET) except HTTPError: pass # just ignore