Skip to content

Commit 6460f1e

Browse files
author
Dean Troyer
committed
Complete basic test infrastructure
This finally gets all of the API tests into a common framework regarding test classes and so forth. Change-Id: If675347129c50dcba0bfc5b6c58f5a2ca57ff46c
1 parent c946192 commit 6460f1e

29 files changed

+652
-438
lines changed

openstackclient/image/v1/image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def take_action(self, parsed_args):
213213
image_client.images,
214214
parsed_args.image,
215215
)
216-
image_client.images.delete(image)
216+
image_client.images.delete(image.id)
217217

218218

219219
class ListImage(lister.Lister):

openstackclient/tests/compute/test_compute.py

Lines changed: 0 additions & 50 deletions
This file was deleted.
Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2013 Nebula Inc.
1+
# Copyright 2013 OpenStack Foundation
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License"); you may
44
# not use this file except in compliance with the License. You may obtain
@@ -12,20 +12,3 @@
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
1414
#
15-
16-
from openstackclient.tests.identity.v3 import fakes
17-
from openstackclient.tests import utils
18-
19-
20-
AUTH_TOKEN = "foobar"
21-
AUTH_URL = "http://0.0.0.0"
22-
23-
24-
class TestIdentityv3(utils.TestCommand):
25-
def setUp(self):
26-
super(TestIdentityv3, self).setUp()
27-
28-
self.app.client_manager.identity = fakes.FakeIdentityv3Client(
29-
endpoint=AUTH_URL,
30-
token=AUTH_TOKEN,
31-
)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright 2013 Nebula Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
# not use this file except in compliance with the License. You may obtain
5+
# a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations
13+
# under the License.
14+
#
15+
16+
import mock
17+
18+
from openstackclient.tests import fakes
19+
from openstackclient.tests import utils
20+
21+
22+
image_id = 'im1'
23+
24+
IMAGE = {
25+
'id': image_id,
26+
}
27+
28+
29+
server_id = 'serv1'
30+
server_name = 'waiter'
31+
32+
SERVER = {
33+
'id': server_id,
34+
'name': server_name,
35+
}
36+
37+
38+
class FakeComputev2Client(object):
39+
def __init__(self, **kwargs):
40+
self.images = mock.Mock()
41+
self.images.resource_class = fakes.FakeResource(None, {})
42+
self.servers = mock.Mock()
43+
self.servers.resource_class = fakes.FakeResource(None, {})
44+
self.auth_token = kwargs['token']
45+
self.management_url = kwargs['endpoint']
46+
47+
48+
class TestComputev2(utils.TestCommand):
49+
def setUp(self):
50+
super(TestComputev2, self).setUp()
51+
52+
self.app.client_manager.compute = FakeComputev2Client(
53+
endpoint=fakes.AUTH_URL,
54+
token=fakes.AUTH_TOKEN,
55+
)
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Copyright 2013 Nebula Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
# not use this file except in compliance with the License. You may obtain
5+
# a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations
13+
# under the License.
14+
#
15+
16+
import copy
17+
18+
from openstackclient.compute.v2 import server
19+
from openstackclient.tests.compute.v2 import fakes as compute_fakes
20+
from openstackclient.tests import fakes
21+
22+
23+
class TestServer(compute_fakes.TestComputev2):
24+
25+
def setUp(self):
26+
super(TestServer, self).setUp()
27+
28+
# Get a shortcut to the ServerManager Mock
29+
self.servers_mock = self.app.client_manager.compute.servers
30+
self.servers_mock.reset_mock()
31+
32+
33+
class TestServerDelete(TestServer):
34+
35+
def setUp(self):
36+
super(TestServerDelete, self).setUp()
37+
38+
# This is the return value for utils.find_resource()
39+
self.servers_mock.get.return_value = fakes.FakeResource(
40+
None,
41+
copy.deepcopy(compute_fakes.SERVER),
42+
loaded=True,
43+
)
44+
self.servers_mock.delete.return_value = None
45+
46+
# Get the command object to test
47+
self.cmd = server.DeleteServer(self.app, None)
48+
49+
def test_server_delete_no_options(self):
50+
arglist = [
51+
compute_fakes.server_id,
52+
]
53+
verifylist = [
54+
('server', compute_fakes.server_id),
55+
]
56+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
57+
58+
# DisplayCommandBase.take_action() returns two tuples
59+
self.cmd.take_action(parsed_args)
60+
61+
self.servers_mock.delete.assert_called_with(
62+
compute_fakes.server_id,
63+
)

openstackclient/tests/fakes.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
import sys
1717

1818

19+
AUTH_TOKEN = "foobar"
20+
AUTH_URL = "http://0.0.0.0"
21+
22+
1923
class FakeStdout:
2024
def __init__(self):
2125
self.content = []

openstackclient/tests/identity/v2_0/fakes.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import mock
1717

1818
from openstackclient.tests import fakes
19+
from openstackclient.tests import utils
20+
1921

2022
project_id = '8-9-64'
2123
project_name = 'beatles'
@@ -83,3 +85,13 @@ def __init__(self, **kwargs):
8385
self.ec2.resource_class = fakes.FakeResource(None, {})
8486
self.auth_token = kwargs['token']
8587
self.management_url = kwargs['endpoint']
88+
89+
90+
class TestIdentityv2(utils.TestCommand):
91+
def setUp(self):
92+
super(TestIdentityv2, self).setUp()
93+
94+
self.app.client_manager.identity = FakeIdentityv2Client(
95+
endpoint=fakes.AUTH_URL,
96+
token=fakes.AUTH_TOKEN,
97+
)

openstackclient/tests/identity/v2_0/test_project.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@
1818
from openstackclient.identity.v2_0 import project
1919
from openstackclient.tests import fakes
2020
from openstackclient.tests.identity.v2_0 import fakes as identity_fakes
21-
from openstackclient.tests.identity.v2_0 import test_identity
2221

2322

24-
class TestProject(test_identity.TestIdentityv2):
23+
class TestProject(identity_fakes.TestIdentityv2):
2524

2625
def setUp(self):
2726
super(TestProject, self).setUp()

openstackclient/tests/identity/v2_0/test_role.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@
2020
from openstackclient.identity.v2_0 import role
2121
from openstackclient.tests import fakes
2222
from openstackclient.tests.identity.v2_0 import fakes as identity_fakes
23-
from openstackclient.tests.identity.v2_0 import test_identity
2423

2524

26-
class TestRole(test_identity.TestIdentityv2):
25+
class TestRole(identity_fakes.TestIdentityv2):
2726

2827
def setUp(self):
2928
super(TestRole, self).setUp()

openstackclient/tests/identity/v2_0/test_service.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@
1818
from openstackclient.identity.v2_0 import service
1919
from openstackclient.tests import fakes
2020
from openstackclient.tests.identity.v2_0 import fakes as identity_fakes
21-
from openstackclient.tests.identity.v2_0 import test_identity
2221

2322

24-
class TestService(test_identity.TestIdentityv2):
23+
class TestService(identity_fakes.TestIdentityv2):
2524

2625
def setUp(self):
2726
super(TestService, self).setUp()

0 commit comments

Comments
 (0)