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