http://git-wip-us.apache.org/repos/asf/cloudstack-gcestack/blob/c6cda06f/tests/operations_tests.py ---------------------------------------------------------------------- diff --git a/tests/operations_tests.py b/tests/operations_tests.py index ac6ccb1..6d2a322 100644 --- a/tests/operations_tests.py +++ b/tests/operations_tests.py @@ -1,20 +1,42 @@ #!/usr/bin/env python # encoding: utf-8 +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# import mock from gstack.helpers import read_file from . import GStackAppTestCase + class OperationsTestCase(GStackAppTestCase): def test_query_operation(self): get = mock.Mock() - get.return_value.text = read_file('tests/data/destroy_vm_async_pending.json') + get.return_value.text = read_file( + 'tests/data/destroy_vm_async_pending.json') get.return_value.status_code = 200 with mock.patch('requests.get', get): - headers = {'authorization': 'Bearer ' + str(GStackAppTestCase.access_token)} - response = self.get('/compute/v1/projects/exampleproject/global/operations/exampleoperation', headers=headers) + headers = { + 'authorization': 'Bearer ' + str(GStackAppTestCase.access_token)} + response = self.get( + '/compute/v1/projects/exampleproject/global/operations/exampleoperation', headers=headers) - self.assert_ok(response) \ No newline at end of file + self.assert_ok(response)
http://git-wip-us.apache.org/repos/asf/cloudstack-gcestack/blob/c6cda06f/tests/project_tests.py ---------------------------------------------------------------------- diff --git a/tests/project_tests.py b/tests/project_tests.py index 9576ffd..50e1f1a 100644 --- a/tests/project_tests.py +++ b/tests/project_tests.py @@ -1,5 +1,23 @@ #!/usr/bin/env python # encoding: utf-8 +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# import mock import json @@ -7,39 +25,48 @@ import json from gstack.helpers import read_file from . import GStackAppTestCase + class ProjectsTestCase(GStackAppTestCase): def test_get_project(self): get = mock.Mock() - get.return_value = json.loads(read_file('tests/data/valid_get_account.json')) + get.return_value = json.loads( + read_file('tests/data/valid_get_account.json')) get_tags = mock.Mock() - get_tags.return_value.text = read_file('tests/data/valid_describe_tags.json') + get_tags.return_value.text = read_file( + 'tests/data/valid_describe_tags.json') get_tags.return_value.status_code = 200 with mock.patch('requests.get', get_tags): with(mock.patch('gstack.controllers.get_item_with_name', get)): - headers = {'authorization': 'Bearer ' + str(GStackAppTestCase.access_token)} - response = self.get('/compute/v1/projects/accountname', headers=headers) + headers = { + 'authorization': 'Bearer ' + str(GStackAppTestCase.access_token)} + response = self.get( + '/compute/v1/projects/accountname', headers=headers) self.assert_ok(response) def test_get_project_project_not_found(self): get = mock.Mock() - get.return_value = json.loads(read_file('tests/data/valid_describe_account.json')) + get.return_value = json.loads( + read_file('tests/data/valid_describe_account.json')) get_tags = mock.Mock() - get_tags.return_value.text = read_file('tests/data/valid_describe_tags.json') + get_tags.return_value.text = read_file( + 'tests/data/valid_describe_tags.json') get_tags.return_value.status_code = 200 with mock.patch('requests.get', get_tags): with(mock.patch('gstack.controllers._get_items', get)): - headers = {'authorization': 'Bearer ' + str(GStackAppTestCase.access_token)} - response = self.get('/compute/v1/projects/invalidaccountname', headers=headers) + headers = { + 'authorization': 'Bearer ' + str(GStackAppTestCase.access_token)} + response = self.get( + '/compute/v1/projects/invalidaccountname', headers=headers) self.assert_not_found(response) assert 'The resource \'/compute/v1/projects/invalidaccountname\' was not found' \ - in response.data + in response.data def test_set_metadata(self): data = { @@ -57,14 +84,16 @@ class ProjectsTestCase(GStackAppTestCase): data = json.dumps(data) get = mock.Mock() - get.return_value.text = read_file('tests/data/valid_register_keypair.json') + get.return_value.text = read_file( + 'tests/data/valid_register_keypair.json') get.return_value.status_code = 200 with mock.patch('requests.get', get): - headers = { - 'authorization': 'Bearer ' + str(GStackAppTestCase.access_token), - } + headers = { + 'authorization': 'Bearer ' + str(GStackAppTestCase.access_token), + } - response = self.post_json('/compute/v1/projects/admin/setCommonInstanceMetadata', data=data, headers=headers) + response = self.post_json( + '/compute/v1/projects/admin/setCommonInstanceMetadata', data=data, headers=headers) self.assert_ok(response) http://git-wip-us.apache.org/repos/asf/cloudstack-gcestack/blob/c6cda06f/tests/regions_tests.py ---------------------------------------------------------------------- diff --git a/tests/regions_tests.py b/tests/regions_tests.py index 93f0774..ffca6ad 100644 --- a/tests/regions_tests.py +++ b/tests/regions_tests.py @@ -1,49 +1,75 @@ #!/usr/bin/env python # encoding: utf-8 +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# import mock from gstack.helpers import read_file from . import GStackAppTestCase + class RegionsTestCase(GStackAppTestCase): def test_list_regions(self): get = mock.Mock() - get.return_value.text = read_file('tests/data/valid_describe_regions.json') + get.return_value.text = read_file( + 'tests/data/valid_describe_regions.json') get.return_value.status_code = 200 with mock.patch('requests.get', get): - headers = {'authorization': 'Bearer ' + str(GStackAppTestCase.access_token)} - response = self.get('/compute/v1/projects/exampleproject/regions', headers=headers) + headers = { + 'authorization': 'Bearer ' + str(GStackAppTestCase.access_token)} + response = self.get( + '/compute/v1/projects/exampleproject/regions', headers=headers) self.assert_ok(response) - def test_get_region(self): get = mock.Mock() - get.return_value.text = read_file('tests/data/valid_describe_regions.json') + get.return_value.text = read_file( + 'tests/data/valid_describe_regions.json') get.return_value.status_code = 200 with mock.patch('requests.get', get): - headers = {'authorization': 'Bearer ' + str(GStackAppTestCase.access_token)} - response = self.get('/compute/v1/projects/exampleproject/regions/regionname', headers=headers) + headers = { + 'authorization': 'Bearer ' + str(GStackAppTestCase.access_token)} + response = self.get( + '/compute/v1/projects/exampleproject/regions/regionname', headers=headers) self.assert_ok(response) def test_get_region_region_not_found(self): get = mock.Mock() - get.return_value.text = read_file('tests/data/valid_describe_regions.json') + get.return_value.text = read_file( + 'tests/data/valid_describe_regions.json') get.return_value.status_code = 200 with mock.patch('requests.get', get): - headers = {'authorization': 'Bearer ' + str(GStackAppTestCase.access_token)} - response = self.get('/compute/v1/projects/exampleproject/regions/invalidregionname', headers=headers) + headers = { + 'authorization': 'Bearer ' + str(GStackAppTestCase.access_token)} + response = self.get( + '/compute/v1/projects/exampleproject/regions/invalidregionname', headers=headers) self.assert_not_found(response) assert 'The resource \'/compute/v1/projects/exampleproject/regions/invalidregionname\' was not found' \ - in response.data - + in response.data http://git-wip-us.apache.org/repos/asf/cloudstack-gcestack/blob/c6cda06f/tests/settings.py ---------------------------------------------------------------------- diff --git a/tests/settings.py b/tests/settings.py index e6f93ed..513eb4b 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -1,3 +1,24 @@ +#!/usr/bin/env python +# encoding: utf-8 +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# + GSTACK_BIND_ADDRESS = 'localhost' GSTACK_PORT = '5000' CLOUDSTACK_HOST = 'api.exoscale.ch' @@ -5,7 +26,7 @@ CLOUDSTACK_PORT = '443' CLOUDSTACK_PROTOCOL = 'https' CLOUDSTACK_PATH = '/compute' -DEBUG=False +DEBUG = False TESTING = True SQLALCHEMY_DATABASE_URI = 'sqlite:///:memory:' http://git-wip-us.apache.org/repos/asf/cloudstack-gcestack/blob/c6cda06f/tests/utils.py ---------------------------------------------------------------------- diff --git a/tests/utils.py b/tests/utils.py index c442322..3f2491e 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -1,11 +1,23 @@ #!/usr/bin/env python # encoding: utf-8 -""" - tests.utils - ~~~~~~~~~~~ - - test utilities -""" +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# class FlaskTestCaseMixin(object): @@ -57,4 +69,3 @@ class FlaskTestCaseMixin(object): def assert_unauthorized(self, response): return self.assert_status_code(response, 401) - http://git-wip-us.apache.org/repos/asf/cloudstack-gcestack/blob/c6cda06f/tests/zones_tests.py ---------------------------------------------------------------------- diff --git a/tests/zones_tests.py b/tests/zones_tests.py index fa89ad8..240b7db 100644 --- a/tests/zones_tests.py +++ b/tests/zones_tests.py @@ -1,47 +1,75 @@ #!/usr/bin/env python # encoding: utf-8 +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# import mock from gstack.helpers import read_file from . import GStackAppTestCase + class ZonesTestCase(GStackAppTestCase): def test_list_zones(self): get = mock.Mock() - get.return_value.text = read_file('tests/data/valid_describe_zone.json') + get.return_value.text = read_file( + 'tests/data/valid_describe_zone.json') get.return_value.status_code = 200 with mock.patch('requests.get', get): - headers = {'authorization': 'Bearer ' + str(GStackAppTestCase.access_token)} - response = self.get('/compute/v1/projects/exampleproject/zones', headers=headers) + headers = { + 'authorization': 'Bearer ' + str(GStackAppTestCase.access_token)} + response = self.get( + '/compute/v1/projects/exampleproject/zones', headers=headers) self.assert_ok(response) def test_get_zone(self): get = mock.Mock() - get.return_value.text = read_file('tests/data/valid_describe_zone.json') + get.return_value.text = read_file( + 'tests/data/valid_describe_zone.json') get.return_value.status_code = 200 with mock.patch('requests.get', get): - headers = {'authorization': 'Bearer ' + str(GStackAppTestCase.access_token)} - response = self.get('/compute/v1/projects/exampleproject/zones/zonename', headers=headers) + headers = { + 'authorization': 'Bearer ' + str(GStackAppTestCase.access_token)} + response = self.get( + '/compute/v1/projects/exampleproject/zones/zonename', headers=headers) self.assert_ok(response) def test_get_zone_zone_not_found(self): get = mock.Mock() - get.return_value.text = read_file('tests/data/empty_describe_zone.json') + get.return_value.text = read_file( + 'tests/data/empty_describe_zone.json') get.return_value.status_code = 200 with mock.patch('requests.get', get): - headers = {'authorization': 'Bearer ' + str(GStackAppTestCase.access_token)} - response = self.get('/compute/v1/projects/exampleproject/zones/zonename', headers=headers) + headers = { + 'authorization': 'Bearer ' + str(GStackAppTestCase.access_token)} + response = self.get( + '/compute/v1/projects/exampleproject/zones/zonename', headers=headers) self.assert_not_found(response) assert 'The resource \'/compute/v1/projects/exampleproject/zones/zonename\' was not found' \ - in response.data + in response.data