Merge lp://qastaging/~yolanda.robla/charms/precise/keystone/unit_testing into lp://qastaging/~openstack-charmers/charms/precise/keystone/icehouse

Proposed by Yolanda Robla
Status: Merged
Merged at revision: 79
Proposed branch: lp://qastaging/~yolanda.robla/charms/precise/keystone/unit_testing
Merge into: lp://qastaging/~openstack-charmers/charms/precise/keystone/icehouse
Diff against target: 653 lines (+579/-5)
3 files modified
unit_tests/test_keystone_contexts.py (+70/-0)
unit_tests/test_keystone_hooks.py (+251/-5)
unit_tests/test_keystone_utils.py (+258/-0)
To merge this branch: bzr merge lp://qastaging/~yolanda.robla/charms/precise/keystone/unit_testing
Reviewer Review Type Date Requested Status
James Page Needs Fixing
Review via email: mp+214009@code.qastaging.launchpad.net

Description of the change

Added unit testing

To post a comment you must log in.
Revision history for this message
James Page (james-page) wrote :
Download full text (6.9 KiB)

You need to mock out get_local_endpoint:

======================================================================
ERROR: test_add_service_to_keystone_clustered_https_none_values (unit_tests.test_keystone_utils.TestKeystoneUtils)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/mock.py", line 1210, in patched
    return func(*args, **keywargs)
  File "/home/jamespage/src/charms/icehouse/keystone/unit_tests/test_keystone_utils.py", line 158, in test_add_service_to_keystone_clustered_https_none_values
    utils.add_service_to_keystone(relation_id=relation_id, remote_unit=remote_unit)
  File "hooks/keystone_utils.py", line 608, in add_service_to_keystone
    manager = manager.KeystoneManager(endpoint=get_local_endpoint(),
  File "hooks/keystone_utils.py", line 272, in get_local_endpoint
    determine_api_port(api_port('keystone-admin'))
  File "hooks/charmhelpers/contrib/hahelpers/cluster.py", line 122, in determine_api_port
    if len(peer_units()) > 0 or is_clustered():
  File "hooks/charmhelpers/contrib/hahelpers/cluster.py", line 59, in peer_units
    for r_id in (relation_ids('cluster') or []):
  File "hooks/charmhelpers/core/hookenv.py", line 44, in wrapper
    res = func(*args, **kwargs)
  File "hooks/charmhelpers/core/hookenv.py", line 213, in relation_ids
    return json.loads(subprocess.check_output(relid_cmd_line)) or []
  File "/usr/lib/python2.7/subprocess.py", line 566, in check_output
    process = Popen(stdout=PIPE, *popenargs, **kwargs)
  File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

======================================================================
ERROR: test_add_service_to_keystone_no_clustered_no_https_complete_values (unit_tests.test_keystone_utils.TestKeystoneUtils)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/mock.py", line 1210, in patched
    return func(*args, **keywargs)
  File "/home/jamespage/src/charms/icehouse/keystone/unit_tests/test_keystone_utils.py", line 196, in test_add_service_to_keystone_no_clustered_no_https_complete_values
    utils.add_service_to_keystone(relation_id=relation_id, remote_unit=remote_unit)
  File "hooks/keystone_utils.py", line 608, in add_service_to_keystone
    manager = manager.KeystoneManager(endpoint=get_local_endpoint(),
  File "hooks/keystone_utils.py", line 272, in get_local_endpoint
    determine_api_port(api_port('keystone-admin'))
  File "hooks/charmhelpers/contrib/hahelpers/cluster.py", line 122, in determine_api_port
    if len(peer_units()) > 0 or is_clustered():
  File "hooks/charmhelpers/contrib/hahelpers/cluster.py", line 59, in peer_units
    for r_id in (relation_ids('cluster') or []):
  File "hooks/charmhelpers/core/hookenv.py", line 44, in wrapper
    res = func(*args, **kwargs)
  File "hooks/charmhelpers/core/hookenv.py", line 213, in relation_ids
    return json.loads(subprocess.check_ou...

Read more...

review: Needs Fixing
79. By Yolanda Robla

mocking extra calls

80. By Yolanda Robla

mocking keystone manager

81. By Yolanda Robla

fixing tests for latest changes

Revision history for this message
James Page (james-page) wrote :

Looking better; one further comment - Mocks don't have an "assert_called()" method; this works because its a mock but actually fails to check anything - use :

   self.assertTrue(self.<function>.called).

I see a few instances of this throughout the tests.

review: Needs Fixing
82. By Yolanda Robla

changing assert_called

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.

Subscribers

People subscribed via source and target branches