nova/nova/tests
Matt Riedemann c75a15a489 Rename NotAuthorized exception to Forbidden
The NotAuthorized NovaException has an internal code of 403 which is
actually Forbidden, so rename it appropriately.

This patch doesn't change the external behavior, the status code in
responses will still be 403 but the exception is just named properly.

This is also necessary to create an actual Unauthorized NovaException
with code 401 for use in some Neutron API bug fixes for more granular
error handling from python-neutronclient.

Related-Bug: #1298075

Change-Id: I691fac2e2c797f47c04da7965d7b1c8685c74edb
2014-04-25 12:37:07 -07:00
..
api Rename NotAuthorized exception to Forbidden 2014-04-25 12:37:07 -07:00
bundle
CA
cells Rename instance_actions v3 to server_actions 2014-04-01 14:59:31 +02:00
cert Remove vi modelines 2014-02-03 14:19:44 +00:00
compute Rename NotAuthorized exception to Forbidden 2014-04-25 12:37:07 -07:00
conductor Deprecate instance_get_active_by_window_joined() from conductor 2014-04-24 08:52:59 -07:00
console Remove vi modelines 2014-02-03 14:19:44 +00:00
consoleauth Remove vi modelines 2014-02-03 14:19:44 +00:00
db Rename NotAuthorized exception to Forbidden 2014-04-25 12:37:07 -07:00
fake_loadables
glance Add deleted_at attribute in glance stub on delete() 2014-03-19 02:18:24 +00:00
image Rename NotAuthorized exception to Forbidden 2014-04-25 12:37:07 -07:00
integrated Fixed many typos. 2014-04-25 21:47:41 -07:00
keymgr Rename NotAuthorized exception to Forbidden 2014-04-25 12:37:07 -07:00
monkey_patch_example Remove vi modelines 2014-02-03 14:19:44 +00:00
network Rename NotAuthorized exception to Forbidden 2014-04-25 12:37:07 -07:00
objects Fix migrate_instance_*() using DB for floating addresses 2014-04-22 07:42:50 -07:00
pci Remove PciDeviceList usage in pci manager 2014-03-20 14:14:58 -07:00
scheduler Merge "Rename instance_actions v3 to server_actions" 2014-04-24 07:18:42 +00:00
servicegroup Make sure report_interval is less than service_down_time 2013-11-27 13:06:15 +08:00
ssl_cert
virt Fixed many typos. 2014-04-25 21:47:41 -07:00
volume Remove vi modelines 2014-02-03 14:19:44 +00:00
__init__.py Remove vi modelines 2014-02-03 14:19:44 +00:00
cast_as_call.py Remove vi modelines 2014-02-03 14:19:44 +00:00
conf_fixture.py Set default auth_strategy to keystone 2014-04-23 17:36:13 -07:00
fake_block_device.py Add block device mapping objects implementation 2014-01-30 15:28:05 +01:00
fake_crypto.py Remove vi modelines 2014-02-03 14:19:44 +00:00
fake_hosts.py
fake_instance.py Clean up _make_*_list in object models to use base.obj_make_list 2014-02-26 08:13:43 +08:00
fake_ldap.py Remove vi modelines 2014-02-03 14:19:44 +00:00
fake_network_cache_model.py Correct network_model tests and __eq__ operator 2014-03-06 16:52:40 -08:00
fake_network.py Remove unused method from fake_network.py 2014-03-18 16:17:21 -07:00
fake_notifier.py Serialize the notification payload in json 2014-02-20 11:42:40 +01:00
fake_policy.py Rename instance_actions v3 to server_actions 2014-04-01 14:59:31 +02:00
fake_processutils.py Remove vi modelines 2014-02-03 14:19:44 +00:00
fake_server_actions.py Rename instance_actions v3 to server_actions 2014-04-01 14:59:31 +02:00
fake_utils.py
fake_volume.py ec2: use BlockDeviceMappingList object 2014-04-14 15:13:02 +00:00
fakeguestfs.py Check image exists before calling inject_data 2014-04-08 20:23:49 +03:00
matchers.py Enable flake8 H404 checking 2014-02-27 11:15:55 +04:00
policy_fixture.py Adds unit test for etc/nova/policy.json data 2014-02-28 07:24:32 +01:00
README.rst Fixed many typos. 2014-04-25 21:47:41 -07:00
test_api_validation.py Define common "name" parameter for Nova v3 API 2014-02-05 19:43:07 +09:00
test_availability_zones.py Change assertTrue(isinstance()) by optimal assert 2014-02-12 16:19:08 +01:00
test_baserpc.py
test_bdm.py Remove vi modelines 2014-02-03 14:19:44 +00:00
test_block_device.py Fix BDM legacy usage with objects 2014-03-06 13:17:27 -08:00
test_cinder.py Use six.moves.urllib.parse instead of urlparse 2014-02-12 18:32:05 +08:00
test_configdrive2.py Remove vi modelines 2014-02-03 14:19:44 +00:00
test_context.py Remove vi modelines 2014-02-03 14:19:44 +00:00
test_crypto.py
test_exception.py Merge "Sync latest gettextutils from oslo-incubator" 2014-02-10 11:56:23 +00:00
test_flavors.py Sync the latest DB code from oslo-incubator 2014-03-03 16:45:22 -05:00
test_hacking.py Don't translate debug level scheduler logs 2014-04-18 10:53:49 -07:00
test_hooks.py Remove vi modelines 2014-02-03 14:19:44 +00:00
test_instance_types_extra_specs.py Remove vi modelines 2014-02-03 14:19:44 +00:00
test_iptables_network.py Remove vi modelines 2014-02-03 14:19:44 +00:00
test_ipv6.py Remove vi modelines 2014-02-03 14:19:44 +00:00
test_linuxscsi.py Remove vi modelines 2014-02-03 14:19:44 +00:00
test_loadables.py
test_matchers.py Remove vi modelines 2014-02-03 14:19:44 +00:00
test_metadata.py Remove metadata's network-api dependence on the database 2014-04-21 06:32:57 -07:00
test_notifications.py Fixed many typos. 2014-04-25 21:47:41 -07:00
test_nova_manage.py Remove utils.reset_is_neutron() to avoid races 2014-04-17 23:09:32 +00:00
test_objectstore.py Add HEAD api response for test s3 server BucketHandler 2014-02-09 01:16:33 +08:00
test_pipelib.py
test_policy.py Adds unit test for etc/nova/policy.json data 2014-02-28 07:24:32 +01:00
test_quota.py Use one query instead of two for quota_usages 2014-04-16 15:18:20 -07:00
test_safeutils.py Remove vi modelines 2014-02-03 14:19:44 +00:00
test_service.py Wait till message handling is done on service stop 2014-03-21 12:18:10 +01:00
test_test_utils.py Merge "Fix potential fd leak" 2014-02-10 09:18:32 +00:00
test_test.py Use debug level logging in unit tests, but don't save them. 2014-04-09 17:10:10 -07:00
test_utils.py Remove utils.reset_is_neutron() to avoid races 2014-04-17 23:09:32 +00:00
test_versions.py Remove vi modelines 2014-02-03 14:19:44 +00:00
test_weights.py Normalize the weights instead of using raw values 2013-12-11 20:24:16 +01:00
test_wsgi.py Allow operators to customize max header size 2014-02-10 09:18:11 +00:00
utils.py Add get_hosts to InstanceGroup object 2014-03-06 20:57:14 +00:00

OpenStack Nova Testing Infrastructure

This README file attempts to provide current and prospective contributors with everything they need to know in order to start creating unit tests for nova.

Note: the content for the rest of this file will be added as the work items in the following blueprint are completed: https://blueprints.launchpad.net/nova/+spec/consolidate-testing-infrastructure

Test Types: Unit vs. Functional vs. Integration

TBD

Writing Unit Tests

TBD

Using Fakes

TBD

test.TestCase

The TestCase class from nova.test (generally imported as test) will automatically manage self.stubs using the stubout module and self.mox using the mox module during the setUp step. They will automatically verify and clean up during the tearDown step.

If using test.TestCase, calling the super class setUp is required and calling the super class tearDown is required to be last if tearDown is overridden.

Writing Functional Tests

TBD

Writing Integration Tests

TBD

Tests and Exceptions

A properly written test asserts that particular behavior occurs. This can be a success condition or a failure condition, including an exception. When asserting that a particular exception is raised, the most specific exception possible should be used.

In particular, testing for Exception being raised is almost always a mistake since it will match (almost) every exception, even those unrelated to the exception intended to be tested.

This applies to catching exceptions manually with a try/except block, or using assertRaises().

Example:

self.assertRaises(exception.InstanceNotFound, db.instance_get_by_uuid,
                  elevated, instance_uuid)

If a stubbed function/method needs a generic exception for testing purposes, test.TestingException is available.

Example:

def stubbed_method(self):
    raise test.TestingException()
self.stubs.Set(cls, 'inner_method', stubbed_method)

obj = cls()
self.assertRaises(test.TestingException, obj.outer_method)

Stubbing and Mocking

Whenever possible, tests SHOULD NOT stub and mock out the same function.

If it's unavoidable, tests SHOULD define stubs before mocks since the TestCase cleanup routine will un-mock before un-stubbing. Doing otherwise results in a test that leaks stubbed functions, causing hard-to-debug interference between tests1.

If a mock must take place before a stub, any stubs after the mock call MUST be manually unset using self.cleanUp calls within the test.


  1. https://bugs.launchpad.net/nova/+bug/1180671↩︎