-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add XML RPCs to emulator (#40)
- Loading branch information
Showing
2 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#!/usr/bin/env python3 | ||
# | ||
# Copyright 2021 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Unit test for emulator.""" | ||
|
||
import json | ||
import os | ||
import unittest | ||
from werkzeug.test import create_environ | ||
|
||
import emulator | ||
import testbench | ||
|
||
|
||
class TestEmulator(unittest.TestCase): | ||
def setUp(self): | ||
emulator.db = testbench.database.Database.init() | ||
emulator.server.config["PREFERRED_URL_SCHEME"] = "https" | ||
emulator.server.config["SERVER_NAME"] = "storage.googleapis.com" | ||
emulator.root.config["PREFERRED_URL_SCHEME"] = "https" | ||
emulator.root.config["SERVER_NAME"] = "storage.googleapis.com" | ||
self.client = emulator.server.test_client(allow_subdomain_redirects=True) | ||
# Avoid magic buckets in the test | ||
os.environ.pop("GOOGLE_CLOUD_CPP_STORAGE_TEST_BUCKET_NAME", None) | ||
|
||
def test_object_xml_put_get_with_subdomain(self): | ||
response = self.client.post( | ||
"/storage/v1/b", data=json.dumps({"name": "bucket-name"}) | ||
) | ||
self.assertEqual(response.status_code, 200) | ||
|
||
response = self.client.put( | ||
"/fox.txt", | ||
base_url="https://bucket-name.storage.googleapis.com", | ||
content_type="text/plain", | ||
data="The quick brown fox jumps over the lazy dog", | ||
) | ||
self.assertEqual(response.status_code, 200, msg=response.data) | ||
|
||
response = self.client.get( | ||
"/fox.txt", base_url="https://bucket-name.storage.googleapis.com" | ||
) | ||
self.assertEqual(response.status_code, 200, msg=response.data) | ||
self.assertEqual(response.data, b"The quick brown fox jumps over the lazy dog") | ||
|
||
def test_object_xml_put_get_with_bucket(self): | ||
response = self.client.post( | ||
"/storage/v1/b", data=json.dumps({"name": "bucket-name"}) | ||
) | ||
self.assertEqual(response.status_code, 200) | ||
|
||
response = self.client.put( | ||
"/bucket-name/fox.txt", | ||
content_type="text/plain", | ||
data="The quick brown fox jumps over the lazy dog", | ||
) | ||
self.assertEqual(response.status_code, 200) | ||
|
||
response = self.client.get("/bucket-name/fox.txt") | ||
self.assertEqual(response.status_code, 200, msg=response.data) | ||
self.assertEqual(response.data, b"The quick brown fox jumps over the lazy dog") | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |