import mock
from rightscale import util


def test_read_rc():
    """
    get_rc_creds() should return (endpoint, token).
    """
    exp_endpoint = 'the endpoint yo'
    exp_token = 'the ref token'

    def fake_config_parser_get(_, key):
        return {
                util.CFG_OPTION_ENDPOINT: exp_endpoint,
                util.CFG_OPTION_REF_TOKEN: exp_token,
                }.get(key)

    _get_config = mock.MagicMock()
    _get_config.return_value.get.side_effect = fake_config_parser_get

    util.get_config = _get_config

    assert (exp_endpoint, exp_token) == util.get_rc_creds()


def test_failed_rc():
    """
    get_rc_creds() should return empty strings on errors.
    """
    _get_config = mock.MagicMock()
    _get_config.return_value.get.side_effect = ['first', ValueError]
    util.get_config = _get_config
    assert ('', '') == util.get_rc_creds()

    _get_config.return_value.get.side_effect = [NameError, 'last']
    assert ('', '') == util.get_rc_creds()

    _get_config.return_value = ValueError
    assert ('', '') == util.get_rc_creds()

@@ -1,15 +1,26 @@
+from mock 
 import 
-mock
+patch
 %0Afro
@@ -407,39 +407,69 @@
     
-_get_config = mock.MagicMock()%0A
+with patch('rightscale.util.get_config') as _get_config:%0A    
     
@@ -538,44 +538,12 @@
 get%0A
-%0A
     
-util.get_config = _get_config%0A%0A
     
@@ -704,43 +704,73 @@
     
-_get_config = mock.MagicMock()%0A
+with patch('rightscale.util.get_config') as _get_config:%0A 
     
+   
 _get
@@ -838,38 +838,8 @@
     
-util.get_config = _get_config%0A
     
@@ -870,32 +870,36 @@
 get_rc_creds()%0A%0A
+    
     _get_config.
@@ -949,16 +949,20 @@
 'last'%5D%0A
+    
     asse
@@ -997,24 +997,28 @@
 reds()%0A%0A    
+  
+  
 _get_config.
@@ -1043,16 +1043,20 @@
 ueError%0A
+    
     asse

Switch to patching in test_rc.py.