def test_cleaner_resources(self, mock_del_neutron, mock_del_cinder, mock_del_glance, mock_del_nova, mock_clients): context = { "task": mock.MagicMock(), "users": [{ "endpoint": mock.MagicMock() }, { "endpoint": mock.MagicMock() }], "config": { "cleanup": ["cinder", "nova", "glance", "neutron"] }, "tenants": [mock.MagicMock()] } user_cleaner = user_cleanup.UserCleanup(context) with user_cleaner: user_cleaner.setup() expected = [ mock.call(context["users"][0]["endpoint"]), mock.call(context["users"][1]["endpoint"]) ] mock_clients.assert_has_calls(expected, any_order=True) self.assertEqual(mock_del_nova.call_count, 2) self.assertEqual(mock_del_glance.call_count, 2) self.assertEqual(mock_del_cinder.call_count, 2) self.assertEqual(mock_del_neutron.call_count, 2)
def test_with_statement_no_user(self): context = { "task": mock.MagicMock(), "admin": mock.MagicMock(), "users": [], "tenants": [], } user_cleaner = user_cleanup.UserCleanup(context) with user_cleaner: user_cleaner.setup()
def test_cleaner_default_behavior(self, mock_cleanup): context = { "task": mock.MagicMock(), "users": [{"endpoint": mock.MagicMock()}, {"endpoint": mock.MagicMock()}], } user_cleaner = user_cleanup.UserCleanup(context) with user_cleaner: user_cleaner.setup() self.assertEqual(mock_cleanup.call_count, 0)
def test_with_statement(self): fake_user_ctx = fakes.FakeUserContext({}).context fake_user_ctx["config"] = {"cleanup": ["nova"]} user_cleaner = user_cleanup.UserCleanup(fake_user_ctx) user_cleaner.setup() user_cleaner._cleanup_resources = mock.MagicMock() with user_cleaner as cleaner: self.assertEqual(user_cleaner, cleaner) user_cleaner._cleanup_resources.assert_called_once_with()