
from cinder import test
from cinder.tests import utils as test_utils


class TestUtilsTestCase(test.TestCase):
    def test_get_test_admin_context(self):
        """get_test_admin_context's return value behaves like admin context."""
        ctxt = test_utils.get_test_admin_context()

        # TODO(soren): This should verify the full interface context
        # objects expose.
        self.assertTrue(ctxt.is_admin)


from cinder import test
from cinder.tests import utils as test_utils


class TestUtilsTestCase(test.TestCase):
    def test_get_test_admin_context(self):
        """get_test_admin_context's return value behaves like admin context."""
        ctxt = test_utils.get_test_admin_context()

        self.assertIsNone(ctxt.project_id)
        self.assertIsNone(ctxt.user_id)
        self.assertIsNone(ctxt.domain)
        self.assertIsNone(ctxt.project_domain)
        self.assertIsNone(ctxt.user_domain)
        self.assertIsNone(ctxt.project_name)
        self.assertIsNone(ctxt.remote_address)
        self.assertIsNone(ctxt.auth_token)
        self.assertIsNone(ctxt.quota_class)

        self.assertIsNotNone(ctxt.request_id)
        self.assertIsNotNone(ctxt.timestamp)

        self.assertEqual(['admin'], ctxt.roles)
        self.assertEqual([], ctxt.service_catalog)
        self.assertEqual('no', ctxt.read_deleted)

        self.assertTrue(ctxt.read_deleted)
        self.assertTrue(ctxt.is_admin)

Verify the full interface of the context object
Verify the full interface of the context object

Improved testcase for get_test_admin_context method
Change-Id: I8c99401150ed41cbf66b32cd00c7f8353ec4e267

  
  from cinder import test
  from cinder.tests import utils as test_utils
  
  
  class TestUtilsTestCase(test.TestCase):
      def test_get_test_admin_context(self):
          """get_test_admin_context's return value behaves like admin context."""
          ctxt = test_utils.get_test_admin_context()
  
-         # TODO(soren): This should verify the full interface context
-         # objects expose.
+         self.assertIsNone(ctxt.project_id)
+         self.assertIsNone(ctxt.user_id)
+         self.assertIsNone(ctxt.domain)
+         self.assertIsNone(ctxt.project_domain)
+         self.assertIsNone(ctxt.user_domain)
+         self.assertIsNone(ctxt.project_name)
+         self.assertIsNone(ctxt.remote_address)
+         self.assertIsNone(ctxt.auth_token)
+         self.assertIsNone(ctxt.quota_class)
+ 
+         self.assertIsNotNone(ctxt.request_id)
+         self.assertIsNotNone(ctxt.timestamp)
+ 
+         self.assertEqual(['admin'], ctxt.roles)
+         self.assertEqual([], ctxt.service_catalog)
+         self.assertEqual('no', ctxt.read_deleted)
+ 
+         self.assertTrue(ctxt.read_deleted)
          self.assertTrue(ctxt.is_admin)
  
Verify the full interface of the context object
## Code Before:

from cinder import test
from cinder.tests import utils as test_utils


class TestUtilsTestCase(test.TestCase):
    def test_get_test_admin_context(self):
        """get_test_admin_context's return value behaves like admin context."""
        ctxt = test_utils.get_test_admin_context()

        # TODO(soren): This should verify the full interface context
        # objects expose.
        self.assertTrue(ctxt.is_admin)

## Instruction:
Verify the full interface of the context object
## Code After:

from cinder import test
from cinder.tests import utils as test_utils


class TestUtilsTestCase(test.TestCase):
    def test_get_test_admin_context(self):
        """get_test_admin_context's return value behaves like admin context."""
        ctxt = test_utils.get_test_admin_context()

        self.assertIsNone(ctxt.project_id)
        self.assertIsNone(ctxt.user_id)
        self.assertIsNone(ctxt.domain)
        self.assertIsNone(ctxt.project_domain)
        self.assertIsNone(ctxt.user_domain)
        self.assertIsNone(ctxt.project_name)
        self.assertIsNone(ctxt.remote_address)
        self.assertIsNone(ctxt.auth_token)
        self.assertIsNone(ctxt.quota_class)

        self.assertIsNotNone(ctxt.request_id)
        self.assertIsNotNone(ctxt.timestamp)

        self.assertEqual(['admin'], ctxt.roles)
        self.assertEqual([], ctxt.service_catalog)
        self.assertEqual('no', ctxt.read_deleted)

        self.assertTrue(ctxt.read_deleted)
        self.assertTrue(ctxt.is_admin)
