| OLD | NEW |
| 1 # -*- coding: utf-8 -*- |
| 1 # Copyright 2013 Google Inc. All Rights Reserved. | 2 # Copyright 2013 Google Inc. All Rights Reserved. |
| 2 # | 3 # |
| 3 # Licensed under the Apache License, Version 2.0 (the "License"); | 4 # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 # you may not use this file except in compliance with the License. | 5 # you may not use this file except in compliance with the License. |
| 5 # You may obtain a copy of the License at | 6 # You may obtain a copy of the License at |
| 6 # | 7 # |
| 7 # http://www.apache.org/licenses/LICENSE-2.0 | 8 # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 # | 9 # |
| 9 # Unless required by applicable law or agreed to in writing, software | 10 # Unless required by applicable law or agreed to in writing, software |
| 10 # distributed under the License is distributed on an "AS IS" BASIS, | 11 # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 # See the License for the specific language governing permissions and | 13 # See the License for the specific language governing permissions and |
| 13 # limitations under the License. | 14 # limitations under the License. |
| 15 """Integration tests for the webcfg command.""" |
| 14 | 16 |
| 15 from xml.dom.minidom import parseString | 17 from __future__ import absolute_import |
| 16 | 18 |
| 19 import json |
| 17 import gslib.tests.testcase as testcase | 20 import gslib.tests.testcase as testcase |
| 21 from gslib.tests.testcase.integration_testcase import SkipForS3 |
| 18 from gslib.tests.util import ObjectToURI as suri | 22 from gslib.tests.util import ObjectToURI as suri |
| 19 | 23 |
| 20 | 24 WEBCFG_FULL = json.loads('{"notFoundPage": "404", "mainPageSuffix": "main"}\n') |
| 21 WEBCFG_FULL = parseString( | 25 WEBCFG_MAIN = json.loads('{"mainPageSuffix": "main"}\n') |
| 22 '<WebsiteConfiguration><MainPageSuffix>main' | 26 WEBCFG_ERROR = json.loads('{"notFoundPage": "404"}\n') |
| 23 '</MainPageSuffix><NotFoundPage>404</NotFoundPage>' | 27 WEBCFG_EMPTY = 'has no website configuration' |
| 24 '</WebsiteConfiguration>').toprettyxml() | |
| 25 | |
| 26 WEBCFG_MAIN = parseString( | |
| 27 '<WebsiteConfiguration>' | |
| 28 '<MainPageSuffix>main</MainPageSuffix>' | |
| 29 '</WebsiteConfiguration>').toprettyxml() | |
| 30 | |
| 31 WEBCFG_ERROR = parseString( | |
| 32 '<WebsiteConfiguration><NotFoundPage>' | |
| 33 '404</NotFoundPage></WebsiteConfiguration>').toprettyxml() | |
| 34 | |
| 35 WEBCFG_EMPTY = parseString('<WebsiteConfiguration/>').toprettyxml() | |
| 36 | 28 |
| 37 | 29 |
| 30 @SkipForS3('Web set not supported for S3, web get returns XML.') |
| 38 class TestWeb(testcase.GsUtilIntegrationTestCase): | 31 class TestWeb(testcase.GsUtilIntegrationTestCase): |
| 39 """Integration tests for the webcfg command.""" | 32 """Integration tests for the web command.""" |
| 40 | 33 |
| 41 _set_cmd_prefix = ['web', 'set'] | 34 _set_web_cmd = ['web', 'set'] |
| 42 _get_cmd_prefix = ['web', 'get'] | 35 _get_web_cmd = ['web', 'get'] |
| 43 | 36 |
| 44 def test_full(self): | 37 def test_full(self): |
| 45 bucket_uri = self.CreateBucket() | 38 bucket_uri = self.CreateBucket() |
| 46 self.RunGsUtil( | 39 self.RunGsUtil( |
| 47 self._set_cmd_prefix + ['-m', 'main', '-e', '404', suri(bucket_uri)]) | 40 self._set_web_cmd + ['-m', 'main', '-e', '404', suri(bucket_uri)]) |
| 48 stdout = self.RunGsUtil( | 41 stdout = self.RunGsUtil( |
| 49 self._get_cmd_prefix + [suri(bucket_uri)], return_stdout=True) | 42 self._get_web_cmd + [suri(bucket_uri)], return_stdout=True) |
| 50 self.assertEquals(stdout, WEBCFG_FULL) | 43 self.assertEquals(json.loads(stdout), WEBCFG_FULL) |
| 51 | 44 |
| 52 def test_main(self): | 45 def test_main(self): |
| 53 bucket_uri = self.CreateBucket() | 46 bucket_uri = self.CreateBucket() |
| 54 self.RunGsUtil(self._set_cmd_prefix + ['-m', 'main', suri(bucket_uri)]) | 47 self.RunGsUtil(self._set_web_cmd + ['-m', 'main', suri(bucket_uri)]) |
| 55 stdout = self.RunGsUtil( | 48 stdout = self.RunGsUtil( |
| 56 self._get_cmd_prefix + [suri(bucket_uri)], return_stdout=True) | 49 self._get_web_cmd + [suri(bucket_uri)], return_stdout=True) |
| 57 self.assertEquals(stdout, WEBCFG_MAIN) | 50 self.assertEquals(json.loads(stdout), WEBCFG_MAIN) |
| 58 | 51 |
| 59 def test_error(self): | 52 def test_error(self): |
| 60 bucket_uri = self.CreateBucket() | 53 bucket_uri = self.CreateBucket() |
| 61 self.RunGsUtil(self._set_cmd_prefix + ['-e', '404', suri(bucket_uri)]) | 54 self.RunGsUtil(self._set_web_cmd + ['-e', '404', suri(bucket_uri)]) |
| 62 stdout = self.RunGsUtil( | 55 stdout = self.RunGsUtil( |
| 63 self._get_cmd_prefix + [suri(bucket_uri)], return_stdout=True) | 56 self._get_web_cmd + [suri(bucket_uri)], return_stdout=True) |
| 64 self.assertEquals(stdout, WEBCFG_ERROR) | 57 self.assertEquals(json.loads(stdout), WEBCFG_ERROR) |
| 65 | 58 |
| 66 def test_empty(self): | 59 def test_empty(self): |
| 67 bucket_uri = self.CreateBucket() | 60 bucket_uri = self.CreateBucket() |
| 68 self.RunGsUtil(self._set_cmd_prefix + [suri(bucket_uri)]) | 61 self.RunGsUtil(self._set_web_cmd + [suri(bucket_uri)]) |
| 69 stdout = self.RunGsUtil( | 62 stdout = self.RunGsUtil( |
| 70 self._get_cmd_prefix + [suri(bucket_uri)], return_stdout=True) | 63 self._get_web_cmd + [suri(bucket_uri)], return_stdout=True) |
| 71 self.assertEquals(stdout, WEBCFG_EMPTY) | 64 self.assertIn(WEBCFG_EMPTY, stdout) |
| 72 | 65 |
| 73 def testTooFewArgumentsFails(self): | 66 def testTooFewArgumentsFails(self): |
| 67 """Ensures web commands fail with too few arguments.""" |
| 74 # No arguments for get, but valid subcommand. | 68 # No arguments for get, but valid subcommand. |
| 75 stderr = self.RunGsUtil(self._get_cmd_prefix, return_stderr=True, | 69 stderr = self.RunGsUtil(self._get_web_cmd, return_stderr=True, |
| 76 expected_status=1) | 70 expected_status=1) |
| 77 self.assertIn('command requires at least', stderr) | 71 self.assertIn('command requires at least', stderr) |
| 78 | 72 |
| 79 # No arguments for set, but valid subcommand. | 73 # No arguments for set, but valid subcommand. |
| 80 stderr = self.RunGsUtil(self._set_cmd_prefix, return_stderr=True, | 74 stderr = self.RunGsUtil(self._set_web_cmd, return_stderr=True, |
| 81 expected_status=1) | 75 expected_status=1) |
| 82 self.assertIn('command requires at least', stderr) | 76 self.assertIn('command requires at least', stderr) |
| 83 | 77 |
| 84 # Neither arguments nor subcommand. | 78 # Neither arguments nor subcommand. |
| 85 stderr = self.RunGsUtil(['web'], return_stderr=True, expected_status=1) | 79 stderr = self.RunGsUtil(['web'], return_stderr=True, expected_status=1) |
| 86 self.assertIn('command requires at least', stderr) | 80 self.assertIn('command requires at least', stderr) |
| 87 | 81 |
| 82 |
| 88 class TestWebOldAlias(TestWeb): | 83 class TestWebOldAlias(TestWeb): |
| 89 _set_cmd_prefix = ['setwebcfg'] | 84 _set_web_cmd = ['setwebcfg'] |
| 90 _get_cmd_prefix = ['getwebcfg'] | 85 _get_web_cmd = ['getwebcfg'] |
| OLD | NEW |