<commit_before>#    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
#
#    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 tempest.api.image import base
from tempest import test


class ImagesMemberTest(base.BaseV2MemberImageTest):

    @test.idempotent_id('5934c6ea-27dc-4d6e-9421-eeb5e045494a')
    def test_image_share_accept(self):
        image_id = self._create_image()
        member = self.image_member_client.create_image_member(
            image_id, member=self.alt_tenant_id)
        self.assertEqual(member['member_id'], self.alt_tenant_id)
        self.assertEqual(member['image_id'], image_id)
        self.assertEqual(member['status'], 'pending')
        self.assertNotIn(image_id, self._list_image_ids_as_alt())
        self.alt_image_member_client.update_image_member(image_id,
                                                         self.alt_tenant_id,
                                                         status='accepted')
        self.assertIn(image_id, self._list_image_ids_as_alt())
        body = self.image_member_client.list_image_members(image_id)
        members = body['members']
        member = members[0]
        self.assertEqual(len(members), 1, str(members))
        self.assertEqual(member['member_id'], self.alt_tenant_id)
        self.assertEqual(member['image_id'], image_id)
        self.assertEqual(member['status'], 'accepted')

    @test.idempotent_id('d9e83e5f-3524-4b38-a900-22abcb26e90e')
    def test_image_share_reject(self):
        image_id = self._create_image()
        member = self.image_member_client.create_image_member(
            image_id, member=self.alt_tenant_id)
        self.assertEqual(member['member_id'], self.alt_tenant_id)
        self.assertEqual(member['image_id'], image_id)
        self.assertEqual(member['status'], 'pending')
        self.assertNotIn(image_id, self._list_image_ids_as_alt())
        self.alt_image_member_client.update_image_member(image_id,
                                                         self.alt_tenant_id,
                                                         status='rejected')
        self.assertNotIn(image_id, self._list_image_ids_as_alt())

    @test.idempotent_id('a6ee18b9-4378-465e-9ad9-9a6de58a3287')
    def test_get_image_member(self):
        image_id = self._create_image()
        self.image_member_client.create_image_member(
            image_id, member=self.alt_tenant_id)
        self.alt_image_member_client.update_image_member(image_id,
                                                         self.alt_tenant_id,
                                                         status='accepted')

        self.assertIn(image_id, self._list_image_ids_as_alt())
        member = self.image_member_client.show_image_member(
            image_id, self.alt_tenant_id)
        self.assertEqual(self.alt_tenant_id, member['member_id'])
        self.assertEqual(image_id, member['image_id'])
        self.assertEqual('accepted', member['status'])

    @test.idempotent_id('72989bc7-2268-48ed-af22-8821e835c914')<commit_msg>Add resource clean for tests<commit_after>#    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
#
#    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 tempest.api.image import base
from tempest import test


class ImagesMemberTest(base.BaseV2MemberImageTest):

    @test.idempotent_id('5934c6ea-27dc-4d6e-9421-eeb5e045494a')
    def test_image_share_accept(self):
        image_id = self._create_image()
        member = self.image_member_client.create_image_member(
            image_id, member=self.alt_tenant_id)
        self.addCleanup(self.image_member_client.delete_image_member,
                        image_id, self.alt_tenant_id)
        self.assertEqual(member['member_id'], self.alt_tenant_id)
        self.assertEqual(member['image_id'], image_id)
        self.assertEqual(member['status'], 'pending')
        self.assertNotIn(image_id, self._list_image_ids_as_alt())
        self.alt_image_member_client.update_image_member(image_id,
                                                         self.alt_tenant_id,
                                                         status='accepted')
        self.assertIn(image_id, self._list_image_ids_as_alt())
        body = self.image_member_client.list_image_members(image_id)
        members = body['members']
        member = members[0]
        self.assertEqual(len(members), 1, str(members))
        self.assertEqual(member['member_id'], self.alt_tenant_id)
        self.assertEqual(member['image_id'], image_id)
        self.assertEqual(member['status'], 'accepted')

    @test.idempotent_id('d9e83e5f-3524-4b38-a900-22abcb26e90e')
    def test_image_share_reject(self):
        image_id = self._create_image()
        member = self.image_member_client.create_image_member(
            image_id, member=self.alt_tenant_id)
        self.addCleanup(self.image_member_client.delete_image_member,
                        image_id, self.alt_tenant_id)
        self.assertEqual(member['member_id'], self.alt_tenant_id)
        self.assertEqual(member['image_id'], image_id)
        self.assertEqual(member['status'], 'pending')
        self.assertNotIn(image_id, self._list_image_ids_as_alt())
        self.alt_image_member_client.update_image_member(image_id,
                                                         self.alt_tenant_id,
                                                         status='rejected')
        self.assertNotIn(image_id, self._list_image_ids_as_alt())

    @test.idempotent_id('a6ee18b9-4378-465e-9ad9-9a6de58a3287')
    def test_get_image_member(self):
        image_id = self._create_image()
        self.image_member_client.create_image_member(
            image_id, member=self.alt_tenant_id)
        self.addCleanup(self.image_member_client.delete_image_member,
                        image_id, self.alt_tenant_id)
        self.alt_image_member_client.update_image_member(image_id,
                                                         self.alt_tenant_id,
                                                         status='accepted')

        self.assertIn(image_id, self._list_image_ids_as_alt())
        member = self.image_member_client.show_image_member(
            image_id, self.alt_tenant_id)
        self.assertEqual(self.alt_tenant_id, member['member_id'])
        self.assertEqual(image_id, member['image_id'])
        self.assertEqual('accepted', member['status'])

    @test.idempotent_id('72989bc7-2268-48ed-af22-8821e835c914')
{'fraction_non_alphanumeric': 0.09229523681014708, 'fraction_numerical': 0.024827958440156523, 'mean_word_length': 2.5464114832535887, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1875861', 'n_tokens_mistral': 2230, 'n_tokens_neox': 2151, 'n_words': 356}