Merge "Transfer Request - refactoring and new test cases"
diff --git a/designate_tempest_plugin/tests/api/v2/test_transfer_request.py b/designate_tempest_plugin/tests/api/v2/test_transfer_request.py
index f548f47..caf1876 100644
--- a/designate_tempest_plugin/tests/api/v2/test_transfer_request.py
+++ b/designate_tempest_plugin/tests/api/v2/test_transfer_request.py
@@ -297,12 +297,12 @@
         self.addCleanup(self.wait_zone_delete, self.zone_client, zone['id'])
 
         LOG.info('Create a zone transfer_request')
-        _, transfer_request = self.client.create_transfer_request(zone['id'])
+        transfer_request = self.client.create_transfer_request(zone['id'])[1]
         self.addCleanup(self.client.delete_transfer_request,
                         transfer_request['id'])
 
         LOG.info('List transfer_requests')
-        _, body = self.client.list_transfer_requests()
+        body = self.client.list_transfer_requests()[1]
 
         self.assertGreater(len(body['transfer_requests']), 0)
 
@@ -445,16 +445,16 @@
         self.addCleanup(self.wait_zone_delete, self.zone_client, zone['id'])
 
         LOG.info('Create a zone transfer_request')
-        _, transfer_request = self.client.create_transfer_request(zone['id'])
+        transfer_request = self.client.create_transfer_request(zone['id'])[1]
         self.addCleanup(self.client.delete_transfer_request,
                         transfer_request['id'])
 
         LOG.info('Update the transfer_request')
         data = {
-                 "description": "demo descripion"
+                 "description": "demo description"
                }
-        _, transfer_request_patch = self.client.update_transfer_request(
-            transfer_request['id'], transfer_request_data=data)
+        transfer_request_patch = self.client.update_transfer_request(
+            transfer_request['id'], transfer_request_data=data)[1]
 
         self.assertEqual(data['description'],
                          transfer_request_patch['description'])
@@ -507,6 +507,15 @@
         super(TestTransferRequestNotFound, cls).setup_clients()
         cls.client = cls.os_primary.dns_v2.TransferRequestClient()
 
+    @decorators.idempotent_id('39131f7c-e9bb-4f92-a325-444a675e1b3d')
+    def test_create_transfer_request_404(self):
+        e = self.assertRaises(lib_exc.NotFound,
+                              self.client.create_transfer_request,
+                              data_utils.rand_uuid())
+        self.assertEqual(404, e.resp.status)
+        self.assertEqual(404, e.resp_body['code'])
+        self.assertEqual("zone_not_found", e.resp_body['type'])
+
     @decorators.idempotent_id('d255f72f-ba24-43df-9dba-011ed7f4625d')
     def test_show_transfer_request_404(self):
         e = self.assertRaises(lib_exc.NotFound,
@@ -532,8 +541,6 @@
         self.assertEqual(404, resp.status)
         self.assertEqual(404, resp_body['code'])
         self.assertEqual("zone_transfer_request_not_found", resp_body['type'])
-        self.assertEqual("Could not find ZoneTransferRequest",
-                         resp_body['message'])
 
 
 class TestTransferRequestInvalidId(BaseTransferRequestTest):
diff --git a/designate_tempest_plugin/tests/scenario/v2/test_zones_transfer.py b/designate_tempest_plugin/tests/scenario/v2/test_zones_transfer.py
index b29262a..78aaabc 100644
--- a/designate_tempest_plugin/tests/scenario/v2/test_zones_transfer.py
+++ b/designate_tempest_plugin/tests/scenario/v2/test_zones_transfer.py
@@ -15,6 +15,7 @@
 from tempest import config
 from tempest.lib import decorators
 from tempest.lib import exceptions as lib_exc
+from designate_tempest_plugin.common import constants as const
 
 from designate_tempest_plugin.tests import base
 from designate_tempest_plugin import data_utils as dns_data_utils
@@ -74,7 +75,8 @@
             self.request_client.create_transfer_request_empty_body(
                 zone['id'])[1])
         self.addCleanup(self.request_client.delete_transfer_request,
-                        transfer_request['id'])
+                        transfer_request['id'],
+                        ignore_errors=lib_exc.NotFound)
 
         accept_data = {
                  "key": transfer_request['key'],
@@ -82,7 +84,13 @@
         }
 
         LOG.info('Accept the request as alt tenant')
-        self.alt_accept_client.create_transfer_accept(accept_data)
+        transfer_accept = self.alt_accept_client.create_transfer_accept(
+            accept_data)[1]
+
+        LOG.info('Ensure we respond with COMPLETE status')
+        show_request = self.request_client.show_transfer_request(
+            transfer_request['id'])[1]
+        self.assertEqual(const.COMPLETE, show_request['status'])
 
         LOG.info('Fetch the zone as alt tenant')
         alt_zone = self.alt_zones_client.show_zone(zone['id'])[1]
@@ -100,6 +108,15 @@
                 lib_exc.BadRequest, 'invalid_zone_transfer_request', 400):
             self.admin_accept_client.create_transfer_accept(accept_data)
 
+        LOG.info('Delete the transfer_request')
+        self.request_client.delete_transfer_request(transfer_request['id'])[1]
+
+        LOG.info('Validation that transfer_accept deleted'
+                 ' after the transfer_request delete')
+        self.assertRaises(lib_exc.NotFound,
+                          self.accept_client.show_transfer_accept,
+                          transfer_accept['id'])
+
     @decorators.idempotent_id('5855b772-a036-11eb-9973-74e5f9e2a801')
     def test_zone_transfer_target_project(self):
         LOG.info('Create a zone as "primary" tenant')
@@ -116,7 +133,7 @@
         self.addCleanup(self.request_client.delete_transfer_request,
                         transfer_request['id'])
         LOG.info('Ensure we respond with ACTIVE status')
-        self.assertEqual('ACTIVE', transfer_request['status'])
+        self.assertEqual(const.ACTIVE, transfer_request['status'])
 
         LOG.info('Accept the request as "alt" tenant, Expected: should fail '
                  'as "admin" was set as a target project.')