2013-10-22 17:46:41 +00:00
|
|
|
# Copyright 2011 OpenStack Foundation
|
|
|
|
# Copyright 2013 Rackspace Hosting
|
|
|
|
# Copyright 2013 Hewlett-Packard Development Company, L.P.
|
|
|
|
# All Rights Reserved.
|
|
|
|
#
|
|
|
|
# Licensed 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.
|
|
|
|
|
2014-01-13 17:04:50 +00:00
|
|
|
import testtools
|
2020-04-18 11:59:46 -05:00
|
|
|
from unittest import mock
|
2013-01-25 09:20:30 -08:00
|
|
|
|
2013-06-17 23:34:27 -07:00
|
|
|
from troveclient import base
|
2014-01-13 17:04:50 +00:00
|
|
|
from troveclient.v1 import accounts
|
2013-01-25 09:20:30 -08:00
|
|
|
|
|
|
|
"""
|
|
|
|
Unit tests for accounts.py
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
Ignore fewer PEP8/flake8 rules
Reasons:
- code should be pythonicaly clean,
that is why number of ignored rules should reduced
Changes:
- E125, F811, H102, H103, F201, H23,
H302, F841, H301, H702, H703 rules are now enabled
Change-Id: Ibf4025162244d3c2f1278b49a76ec1527a729042
2013-12-10 18:49:20 +02:00
|
|
|
class AccountTest(testtools.TestCase):
|
2013-01-25 09:20:30 -08:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(AccountTest, self).setUp()
|
|
|
|
self.orig__init = accounts.Account.__init__
|
Ignore fewer PEP8/flake8 rules
Reasons:
- code should be pythonicaly clean,
that is why number of ignored rules should reduced
Changes:
- E125, F811, H102, H103, F201, H23,
H302, F841, H301, H702, H703 rules are now enabled
Change-Id: Ibf4025162244d3c2f1278b49a76ec1527a729042
2013-12-10 18:49:20 +02:00
|
|
|
accounts.Account.__init__ = mock.Mock(return_value=None)
|
2013-01-25 09:20:30 -08:00
|
|
|
self.account = accounts.Account()
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
super(AccountTest, self).tearDown()
|
|
|
|
accounts.Account.__init__ = self.orig__init
|
|
|
|
|
|
|
|
def test___repr__(self):
|
|
|
|
self.account.name = "account-1"
|
|
|
|
self.assertEqual('<Account: account-1>', self.account.__repr__())
|
|
|
|
|
|
|
|
|
Ignore fewer PEP8/flake8 rules
Reasons:
- code should be pythonicaly clean,
that is why number of ignored rules should reduced
Changes:
- E125, F811, H102, H103, F201, H23,
H302, F841, H301, H702, H703 rules are now enabled
Change-Id: Ibf4025162244d3c2f1278b49a76ec1527a729042
2013-12-10 18:49:20 +02:00
|
|
|
class AccountsTest(testtools.TestCase):
|
2013-01-25 09:20:30 -08:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(AccountsTest, self).setUp()
|
|
|
|
self.orig__init = accounts.Accounts.__init__
|
Ignore fewer PEP8/flake8 rules
Reasons:
- code should be pythonicaly clean,
that is why number of ignored rules should reduced
Changes:
- E125, F811, H102, H103, F201, H23,
H302, F841, H301, H702, H703 rules are now enabled
Change-Id: Ibf4025162244d3c2f1278b49a76ec1527a729042
2013-12-10 18:49:20 +02:00
|
|
|
accounts.Accounts.__init__ = mock.Mock(return_value=None)
|
2013-01-25 09:20:30 -08:00
|
|
|
self.accounts = accounts.Accounts()
|
Ignore fewer PEP8/flake8 rules
Reasons:
- code should be pythonicaly clean,
that is why number of ignored rules should reduced
Changes:
- E125, F811, H102, H103, F201, H23,
H302, F841, H301, H702, H703 rules are now enabled
Change-Id: Ibf4025162244d3c2f1278b49a76ec1527a729042
2013-12-10 18:49:20 +02:00
|
|
|
self.accounts.api = mock.Mock()
|
|
|
|
self.accounts.api.client = mock.Mock()
|
2013-01-25 09:20:30 -08:00
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
super(AccountsTest, self).tearDown()
|
|
|
|
accounts.Accounts.__init__ = self.orig__init
|
|
|
|
|
|
|
|
def test__list(self):
|
|
|
|
def side_effect_func(self, val):
|
|
|
|
return val
|
|
|
|
|
Ignore fewer PEP8/flake8 rules
Reasons:
- code should be pythonicaly clean,
that is why number of ignored rules should reduced
Changes:
- E125, F811, H102, H103, F201, H23,
H302, F841, H301, H702, H703 rules are now enabled
Change-Id: Ibf4025162244d3c2f1278b49a76ec1527a729042
2013-12-10 18:49:20 +02:00
|
|
|
self.accounts.resource_class = mock.Mock(side_effect=side_effect_func)
|
2013-01-25 09:20:30 -08:00
|
|
|
key_ = 'key'
|
|
|
|
body_ = {key_: "test-value"}
|
Ignore fewer PEP8/flake8 rules
Reasons:
- code should be pythonicaly clean,
that is why number of ignored rules should reduced
Changes:
- E125, F811, H102, H103, F201, H23,
H302, F841, H301, H702, H703 rules are now enabled
Change-Id: Ibf4025162244d3c2f1278b49a76ec1527a729042
2013-12-10 18:49:20 +02:00
|
|
|
self.accounts.api.client.get = mock.Mock(return_value=('resp', body_))
|
2013-01-25 09:20:30 -08:00
|
|
|
self.assertEqual("test-value", self.accounts._list('url', key_))
|
|
|
|
|
Ignore fewer PEP8/flake8 rules
Reasons:
- code should be pythonicaly clean,
that is why number of ignored rules should reduced
Changes:
- E125, F811, H102, H103, F201, H23,
H302, F841, H301, H702, H703 rules are now enabled
Change-Id: Ibf4025162244d3c2f1278b49a76ec1527a729042
2013-12-10 18:49:20 +02:00
|
|
|
self.accounts.api.client.get = mock.Mock(return_value=('resp', None))
|
2013-01-25 09:20:30 -08:00
|
|
|
self.assertRaises(Exception, self.accounts._list, 'url', None)
|
|
|
|
|
|
|
|
def test_index(self):
|
Ignore fewer PEP8/flake8 rules
Reasons:
- code should be pythonicaly clean,
that is why number of ignored rules should reduced
Changes:
- E125, F811, H102, H103, F201, H23,
H302, F841, H301, H702, H703 rules are now enabled
Change-Id: Ibf4025162244d3c2f1278b49a76ec1527a729042
2013-12-10 18:49:20 +02:00
|
|
|
resp = mock.Mock()
|
2013-09-26 22:26:02 -07:00
|
|
|
resp.status_code = 400
|
2013-01-25 09:20:30 -08:00
|
|
|
body = {"Accounts": {}}
|
Ignore fewer PEP8/flake8 rules
Reasons:
- code should be pythonicaly clean,
that is why number of ignored rules should reduced
Changes:
- E125, F811, H102, H103, F201, H23,
H302, F841, H301, H702, H703 rules are now enabled
Change-Id: Ibf4025162244d3c2f1278b49a76ec1527a729042
2013-12-10 18:49:20 +02:00
|
|
|
self.accounts.api.client.get = mock.Mock(return_value=(resp, body))
|
2013-01-25 09:20:30 -08:00
|
|
|
self.assertRaises(Exception, self.accounts.index)
|
2013-09-26 22:26:02 -07:00
|
|
|
resp.status_code = 200
|
2016-01-04 17:31:58 -05:00
|
|
|
self.assertIsInstance(self.accounts.index(), base.Resource)
|
Ignore fewer PEP8/flake8 rules
Reasons:
- code should be pythonicaly clean,
that is why number of ignored rules should reduced
Changes:
- E125, F811, H102, H103, F201, H23,
H302, F841, H301, H702, H703 rules are now enabled
Change-Id: Ibf4025162244d3c2f1278b49a76ec1527a729042
2013-12-10 18:49:20 +02:00
|
|
|
self.accounts.api.client.get = mock.Mock(return_value=(resp, None))
|
2013-01-25 09:20:30 -08:00
|
|
|
self.assertRaises(Exception, self.accounts.index)
|
|
|
|
|
|
|
|
def test_show(self):
|
|
|
|
def side_effect_func(acct_name, acct):
|
|
|
|
return acct_name, acct
|
|
|
|
|
Ignore fewer PEP8/flake8 rules
Reasons:
- code should be pythonicaly clean,
that is why number of ignored rules should reduced
Changes:
- E125, F811, H102, H103, F201, H23,
H302, F841, H301, H702, H703 rules are now enabled
Change-Id: Ibf4025162244d3c2f1278b49a76ec1527a729042
2013-12-10 18:49:20 +02:00
|
|
|
account_ = mock.Mock()
|
2013-01-25 09:20:30 -08:00
|
|
|
account_.name = "test-account"
|
Ignore fewer PEP8/flake8 rules
Reasons:
- code should be pythonicaly clean,
that is why number of ignored rules should reduced
Changes:
- E125, F811, H102, H103, F201, H23,
H302, F841, H301, H702, H703 rules are now enabled
Change-Id: Ibf4025162244d3c2f1278b49a76ec1527a729042
2013-12-10 18:49:20 +02:00
|
|
|
self.accounts._list = mock.Mock(side_effect=side_effect_func)
|
2013-01-25 09:20:30 -08:00
|
|
|
self.assertEqual(('/mgmt/accounts/test-account', 'account'),
|
|
|
|
self.accounts.show(account_))
|
|
|
|
|
|
|
|
def test__get_account_name(self):
|
|
|
|
account_ = 'account with no name'
|
|
|
|
self.assertEqual(account_,
|
|
|
|
accounts.Accounts._get_account_name(account_))
|
Ignore fewer PEP8/flake8 rules
Reasons:
- code should be pythonicaly clean,
that is why number of ignored rules should reduced
Changes:
- E125, F811, H102, H103, F201, H23,
H302, F841, H301, H702, H703 rules are now enabled
Change-Id: Ibf4025162244d3c2f1278b49a76ec1527a729042
2013-12-10 18:49:20 +02:00
|
|
|
account_ = mock.Mock()
|
2013-01-25 09:20:30 -08:00
|
|
|
account_.name = "account-name"
|
|
|
|
self.assertEqual("account-name",
|
|
|
|
accounts.Accounts._get_account_name(account_))
|