{"body":"# -*- coding: utf-8 -*-\n\n# Licensed under the Apache License, Version 2.0 (the \"License\"); you may\n# not use this file except in compliance with the License. You may obtain\n# a copy of the License at\n#\n#      http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n# License for the specific language governing permissions and limitations\n# under the License.\n\nfrom __future__ import absolute_import\nimport uuid\n\nimport fixtures\n\n\nclass ScopedAuth(fixtures.Fixture):\n\n    def __init__(self, test_instance, project_name=None, reuse_project=False):\n        self.project_name = project_name or uuid.uuid4().hex\n        self.reuse_project = False\n        self.test_instance = test_instance\n        self.project = None\n\n    def setUp(self):\n        params = {\n            'name': self.project_name,\n            'description': 'Scoped Project Via Fixture'\n        }\n        if self.test_instance.identity_version == '3':\n            params['domain_id'] = \\\n                self.test_instance.operator_cloud.get_domain('default')['id']\n        self.project = self.test_instance.operator_cloud.create_project(\n            **params)\n        self.test_instance.assertIsNotNone(self.project)\n        # TODO(morgan): Override scope for demo AND operator cloud auth\n        self.addCleanup(self._cleanup_project())\n\n    def _cleanup_project(self):\n        if not self.reuse_project:\n            # Cleanup the Project only if we aren't re-using the project\n            params = {'name': self.project_name}\n            if self.test_instance.identity_version == '3':\n                params['domain_id'] = \\\n                    self.test_instance.operator_cloud.get_domain(\n                        'default')['id']\n            self.test_instance.assertTrue(\n                self.test_instance.operator_cloud.delete_project(\n                    self.project['id']))\n","name":"","extension":"txt","url":"https://www.irccloud.com/pastebin/6OEyeLlH","modified":1481670337,"id":"6OEyeLlH","size":2058,"lines":53,"own_paste":false,"theme":"","date":1481670337}