def test_safe_region(self): # Pass direct reg = utils.random_unicode() ret = pyrax._safe_region(reg) self.assertEqual(reg, ret) # From config setting orig_reg = pyrax.get_setting("region") reg = utils.random_unicode() pyrax.set_setting("region", reg) ret = pyrax._safe_region() self.assertEqual(reg, ret) # Identity default pyrax.set_setting("region", None) orig_defreg = pyrax.identity.get_default_region reg = utils.random_unicode() pyrax.identity.get_default_region = Mock(return_value=reg) ret = pyrax._safe_region() self.assertEqual(reg, ret) pyrax.identity.get_default_region = orig_defreg pyrax.set_setting("region", orig_reg)
def test_safe_region_no_context(self): reg = None sav_ident = pyrax.identity sav_create = pyrax._create_identity def set_ident(): pyrax.identity = sav_ident pyrax._create_identity = Mock(side_effect=set_ident) sav_get = pyrax.settings.get pyrax.settings.get = Mock(return_value=None) pyrax.identity = None ret = pyrax._safe_region(reg) self.assertIsNotNone(ret) pyrax._create_identity = sav_create pyrax.identity = sav_ident pyrax.settings.get = sav_get