Merge "Testing bad microversions on v1/allocations"
diff --git a/ironic_tempest_plugin/tests/api/admin/test_microversion_enforcement.py b/ironic_tempest_plugin/tests/api/admin/test_microversion_enforcement.py
index 4fd8c99..caf520f 100644
--- a/ironic_tempest_plugin/tests/api/admin/test_microversion_enforcement.py
+++ b/ironic_tempest_plugin/tests/api/admin/test_microversion_enforcement.py
@@ -1,16 +1,16 @@
-#    Licensed under the Apache License, Version 2.0 (the "License"); you may
-#    not use this file except in compliance with the License. You may obtain
-#    a copy of the License at
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
 #
-#         http://www.apache.org/licenses/LICENSE-2.0
+#      http://www.apache.org/licenses/LICENSE-2.0
 #
-#    Unless required by applicable law or agreed to in writing, software
-#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-#    License for the specific language governing permissions and limitations
-#    under the License.
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
 
-
+from oslo_utils import uuidutils
 from tempest.lib import decorators
 from tempest.lib import exceptions as lib_exc
 
@@ -20,11 +20,8 @@
 from ironic_tempest_plugin.tests.api import base
 
 
-class TestMicroversionEnforcement(base.BaseBaremetalTest):
-    """Tests for API microversion enforcement."""
-
-    def setUp(self):
-        super(TestMicroversionEnforcement, self).setUp()
+class MicroversionTestMixin:
+    """Mixin class containing shared microversion test functionality."""
 
     def _microversion_test(
             self, method_name, min_version, expected_error, required_args):
@@ -42,8 +39,6 @@
         ]
 
         # Get method name from method object
-        # This way, users can pass the method object,
-        # and we can still get the instantiated method
         method_name = method_name.__name__
 
         for microversion in invalid_versions:
@@ -68,6 +63,22 @@
                         **{arg_name: arg_value},
                     )
 
+
+class BaseTestMicroversionEnforcement(base.BaseBaremetalTest):
+    """Base class for microversion enforcement tests."""
+
+    def setUp(self):
+        super(BaseTestMicroversionEnforcement, self).setUp()
+        self.resource_class = uuidutils.generate_uuid()
+
+
+class TestShardMicroversions(
+        BaseTestMicroversionEnforcement,
+        MicroversionTestMixin):
+    """Tests for shard-related API microversion enforcement."""
+
+    min_microversion = "1.82"
+
     @decorators.idempotent_id("e5403a31-e12b-4f97-a776-dcb819e5e9a0")
     def test_shard(self):
         self._microversion_test(
@@ -80,3 +91,49 @@
             BaremetalClient.list_nodes, "1.82",
             lib_exc.NotAcceptable, {"shard": "testshard"}
         )
+
+
+class TestAllocationMicroversions(
+        BaseTestMicroversionEnforcement,
+        MicroversionTestMixin):
+    """Tests for allocation-related API microversion enforcement."""
+
+    min_microversion = "1.52"
+
+    @decorators.idempotent_id('8f527b3d-d5f1-4859-920f-8022b5d13621')
+    def test_create_allocations(self):
+        self._microversion_test(
+            BaremetalClient.create_allocation, "1.52",
+            lib_exc.UnexpectedResponseCode, {
+                "resource_class": self.resource_class
+            }
+        )
+
+    @decorators.idempotent_id('511e0c4b-1320-4ac5-9c4a-fb0394d3ff67')
+    def test_list_allocations(self):
+        self._microversion_test(
+            BaremetalClient.list_allocations, "1.52",
+            lib_exc.NotFound, {}
+        )
+
+    @decorators.idempotent_id('a0d17f90-baa0-4518-95f7-a7eab73ff6d1')
+    def test_show_allocations(self):
+        _, allocation = self.create_allocation(self.resource_class)
+
+        self._microversion_test(
+            BaremetalClient.show_allocation, "1.52",
+            lib_exc.NotFound, {
+                "allocation_ident": allocation['uuid']
+            }
+        )
+
+    @decorators.idempotent_id('b05a9b1a-4a12-4b55-93c7-530c3f35c7d9')
+    def test_delete_allocations(self):
+        _, allocation = self.create_allocation(self.resource_class)
+
+        self._microversion_test(
+            BaremetalClient.delete_allocation, "1.52",
+            lib_exc.UnexpectedResponseCode, {
+                "allocation_ident": allocation['uuid']
+            }
+        )