| Index: gslib/tests/test_web.py
|
| ===================================================================
|
| --- gslib/tests/test_web.py (revision 33376)
|
| +++ gslib/tests/test_web.py (working copy)
|
| @@ -1,3 +1,4 @@
|
| +# -*- coding: utf-8 -*-
|
| # Copyright 2013 Google Inc. All Rights Reserved.
|
| #
|
| # Licensed under the Apache License, Version 2.0 (the "License");
|
| @@ -11,80 +12,74 @@
|
| # 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.
|
| +"""Integration tests for the webcfg command."""
|
|
|
| -from xml.dom.minidom import parseString
|
| +from __future__ import absolute_import
|
|
|
| +import json
|
| import gslib.tests.testcase as testcase
|
| +from gslib.tests.testcase.integration_testcase import SkipForS3
|
| from gslib.tests.util import ObjectToURI as suri
|
|
|
| +WEBCFG_FULL = json.loads('{"notFoundPage": "404", "mainPageSuffix": "main"}\n')
|
| +WEBCFG_MAIN = json.loads('{"mainPageSuffix": "main"}\n')
|
| +WEBCFG_ERROR = json.loads('{"notFoundPage": "404"}\n')
|
| +WEBCFG_EMPTY = 'has no website configuration'
|
|
|
| -WEBCFG_FULL = parseString(
|
| - '<WebsiteConfiguration><MainPageSuffix>main'
|
| - '</MainPageSuffix><NotFoundPage>404</NotFoundPage>'
|
| - '</WebsiteConfiguration>').toprettyxml()
|
|
|
| -WEBCFG_MAIN = parseString(
|
| - '<WebsiteConfiguration>'
|
| - '<MainPageSuffix>main</MainPageSuffix>'
|
| - '</WebsiteConfiguration>').toprettyxml()
|
| -
|
| -WEBCFG_ERROR = parseString(
|
| - '<WebsiteConfiguration><NotFoundPage>'
|
| - '404</NotFoundPage></WebsiteConfiguration>').toprettyxml()
|
| -
|
| -WEBCFG_EMPTY = parseString('<WebsiteConfiguration/>').toprettyxml()
|
| -
|
| -
|
| +@SkipForS3('Web set not supported for S3, web get returns XML.')
|
| class TestWeb(testcase.GsUtilIntegrationTestCase):
|
| - """Integration tests for the webcfg command."""
|
| + """Integration tests for the web command."""
|
|
|
| - _set_cmd_prefix = ['web', 'set']
|
| - _get_cmd_prefix = ['web', 'get']
|
| + _set_web_cmd = ['web', 'set']
|
| + _get_web_cmd = ['web', 'get']
|
|
|
| def test_full(self):
|
| bucket_uri = self.CreateBucket()
|
| self.RunGsUtil(
|
| - self._set_cmd_prefix + ['-m', 'main', '-e', '404', suri(bucket_uri)])
|
| + self._set_web_cmd + ['-m', 'main', '-e', '404', suri(bucket_uri)])
|
| stdout = self.RunGsUtil(
|
| - self._get_cmd_prefix + [suri(bucket_uri)], return_stdout=True)
|
| - self.assertEquals(stdout, WEBCFG_FULL)
|
| + self._get_web_cmd + [suri(bucket_uri)], return_stdout=True)
|
| + self.assertEquals(json.loads(stdout), WEBCFG_FULL)
|
|
|
| def test_main(self):
|
| bucket_uri = self.CreateBucket()
|
| - self.RunGsUtil(self._set_cmd_prefix + ['-m', 'main', suri(bucket_uri)])
|
| + self.RunGsUtil(self._set_web_cmd + ['-m', 'main', suri(bucket_uri)])
|
| stdout = self.RunGsUtil(
|
| - self._get_cmd_prefix + [suri(bucket_uri)], return_stdout=True)
|
| - self.assertEquals(stdout, WEBCFG_MAIN)
|
| + self._get_web_cmd + [suri(bucket_uri)], return_stdout=True)
|
| + self.assertEquals(json.loads(stdout), WEBCFG_MAIN)
|
|
|
| def test_error(self):
|
| bucket_uri = self.CreateBucket()
|
| - self.RunGsUtil(self._set_cmd_prefix + ['-e', '404', suri(bucket_uri)])
|
| + self.RunGsUtil(self._set_web_cmd + ['-e', '404', suri(bucket_uri)])
|
| stdout = self.RunGsUtil(
|
| - self._get_cmd_prefix + [suri(bucket_uri)], return_stdout=True)
|
| - self.assertEquals(stdout, WEBCFG_ERROR)
|
| -
|
| + self._get_web_cmd + [suri(bucket_uri)], return_stdout=True)
|
| + self.assertEquals(json.loads(stdout), WEBCFG_ERROR)
|
| +
|
| def test_empty(self):
|
| bucket_uri = self.CreateBucket()
|
| - self.RunGsUtil(self._set_cmd_prefix + [suri(bucket_uri)])
|
| + self.RunGsUtil(self._set_web_cmd + [suri(bucket_uri)])
|
| stdout = self.RunGsUtil(
|
| - self._get_cmd_prefix + [suri(bucket_uri)], return_stdout=True)
|
| - self.assertEquals(stdout, WEBCFG_EMPTY)
|
| + self._get_web_cmd + [suri(bucket_uri)], return_stdout=True)
|
| + self.assertIn(WEBCFG_EMPTY, stdout)
|
|
|
| def testTooFewArgumentsFails(self):
|
| + """Ensures web commands fail with too few arguments."""
|
| # No arguments for get, but valid subcommand.
|
| - stderr = self.RunGsUtil(self._get_cmd_prefix, return_stderr=True,
|
| + stderr = self.RunGsUtil(self._get_web_cmd, return_stderr=True,
|
| expected_status=1)
|
| self.assertIn('command requires at least', stderr)
|
|
|
| # No arguments for set, but valid subcommand.
|
| - stderr = self.RunGsUtil(self._set_cmd_prefix, return_stderr=True,
|
| + stderr = self.RunGsUtil(self._set_web_cmd, return_stderr=True,
|
| expected_status=1)
|
| self.assertIn('command requires at least', stderr)
|
|
|
| # Neither arguments nor subcommand.
|
| stderr = self.RunGsUtil(['web'], return_stderr=True, expected_status=1)
|
| self.assertIn('command requires at least', stderr)
|
| -
|
| +
|
| +
|
| class TestWebOldAlias(TestWeb):
|
| - _set_cmd_prefix = ['setwebcfg']
|
| - _get_cmd_prefix = ['getwebcfg']
|
| + _set_web_cmd = ['setwebcfg']
|
| + _get_web_cmd = ['getwebcfg']
|
|
|